I am storing timestamp of a file as “datetime” object in a DB, now when
i parse through a file i check if there is an existing entry in the DB
with same name and get the timestamp out of it. I compare both the
timestamps.
i have used GetFileInfo #{file} | grep modified.split(": ").last to
get something of this kind
Tue Jun 05 14:16:28 UTC 2012
When i retrive the datatime field from the DB i see this 2012-06-05
14:16:28 UTC. Since these two point to the same time , how do i compare
them?
so the UTC and -0800 characters dont match and as a result the strcmp
fails.
No, the Time object does not compare the strings (this wouldn’t make any
sense) but the actual points of time.
cyber c. wrote in post #1063777:
Im sorry , reposting it again to avoid confusion
Those are still two different points of time: “2011-12-22 16:26:43
-0800” is “2011-12-22 23:26:43 UTC”, so it’s definitely not equal to the
database time “2011-12-22 16:26:43 UTC”.
You’ll probably have to fix the database timestamps (subtract 8 hours
according to your local timezone).
time_1 = File.mtime ‘myfile.foo’ # mtime of file
this returns “Thu Dec 22 16:26:43 -0800 2011”
time_2 = Time.parse ‘2011-12-22 16:26:43 UTC’ # from database //
Modified the param to Time.parse
returns “Thu Dec 22 16:26:43 UTC 2011”