taylorfinnell / awscr-s3

A Crystal shard for S3.
https://taylorfinnell.github.io/awscr-s3/
MIT License
81 stars 48 forks source link

adds LastModifed to object as last_modifed #47

Closed samueleaton closed 5 years ago

samueleaton commented 5 years ago

exposes the LastModifed time string to the user

example:

client.list_objects(bucket: BUCKET, max_keys: 10).each do |response|
  keys = response.contents.sort_by do |o|
    Time.parse!(o.last_modified, "%FT%T")
  end.map(&.key)

  p keys
end
samueleaton commented 5 years ago

S3 and DigitalOcean spaces both seem to use ISO string where the date and time are separated by a T.

I could parse the times so @last_modifed is a Time instead of a String. I'm just not aware of any edge cases, like if times are ever stored without milliseconds, or if they are always in UTC time.

taylorfinnell commented 5 years ago

Thanks! I think parsing it as a Time would be solid. Doing that in other places like https://github.com/taylorfinnell/awscr-s3/blob/master/src/awscr-s3/responses/list_all_my_buckets.cr#L23 albeit it needs to be fixed there :)

samueleaton commented 5 years ago

I tried to use the existing Time Format string you showed me above but the time returned by DigitalOcean uses a decimal precision (e.g. 2019-03-06T01:52:47.037Z) so it breaks when it sees the period. Should we do it without decimal precision or a timezone and just parse it as UTC?

Example:

# "%Y-%M-%dT%H:%M:%S" is the same as "%FT%T"
last_modified = Time.parse(object.string("LastModified"), "%FT%T", Time::Location::UTC)

(When you don't specify a timezone in the time format string it required a location)

taylorfinnell commented 5 years ago

It looks like if a timestamp format is not specified the Ruby gem parses UTC and iso 8601. So I guess let's do that

https://github.com/aws/aws-sdk-ruby/blob/master/gems/aws-sdk-core/lib/aws-sdk-core/xml/builder.rb#L108