I'm trying to compare how new a file is with the header obtained
from Net::HTTP.head(). I use
STRFTIME_FORMAT = "%a, %d %b %Y %H:%M:%S GMT"
timestamp = DateTime.strptime(lastmod, STRFTIME_FORMAT)
But I can't compare this with the results of File.mtime, because one
is a DateTime, and one is a Time. Time::strptime or Time::strftime
don't exist. Time#strftime does, but I can't pass a string to be
turned into a time into it. Parsedate deosn't seem to handle this
case, either in so far as it has no str[fp]time.
Is there a cunning way to do this I have missed? Do I need another
library and if so, what?
Thank you,
Hugh
this might help...
harp:~ > cat a.rb
require 'alib'
now = Time::now
p now
now_s = ALib::Util::timestamp now
p now_s
p ALib::Util::stamptime(now_s, 'local' => true)
harp:~ > ruby a.rb
Thu Sep 08 12:31:26 MDT 2005
"2005-09-08 18:31:26.812671"
Thu Sep 08 18:31:26 MDT 2005
dunno though... without the 'local' it assumes utc.
cheers.
-a
···
On Fri, 9 Sep 2005, Hugh Sasse wrote:
I'm trying to compare how new a file is with the header obtained
from Net::HTTP.head(). I use
STRFTIME_FORMAT = "%a, %d %b %Y %H:%M:%S GMT"
timestamp = DateTime.strptime(lastmod, STRFTIME_FORMAT)
But I can't compare this with the results of File.mtime, because one
is a DateTime, and one is a Time. Time::strptime or Time::strftime
don't exist. Time#strftime does, but I can't pass a string to be
turned into a time into it. Parsedate deosn't seem to handle this
case, either in so far as it has no str[fp]time.
Is there a cunning way to do this I have missed? Do I need another
library and if so, what?
Thank you,
Hugh
--
email :: ara [dot] t [dot] howard [at] noaa [dot] gov
phone :: 303.497.6469
Your life dwells amoung the causes of death
Like a lamp standing in a strong breeze. --Nagarjuna
===============================================================================
I'm trying to compare how new a file is with the header obtained
from Net::HTTP.head(). I use
STRFTIME_FORMAT = "%a, %d %b %Y %H:%M:%S GMT"
timestamp = DateTime.strptime(lastmod, STRFTIME_FORMAT)
require 'time'
timestamp = Time.parse lastmod
But I can't compare this with the results of File.mtime, because one
is a DateTime, and one is a Time. Time::strptime or Time::strftime
don't exist. Time#strftime does, but I can't pass a string to be
turned into a time into it. Parsedate deosn't seem to handle this
case, either in so far as it has no str[fp]time.
Time.parse Just Works.
Is there a cunning way to do this I have missed? Do I need another
library and if so, what?
I tend to avoid Date and DateTime unless I need them.
···
On 08 Sep 2005, at 11:11, Hugh Sasse wrote:
--
Eric Hodel - drbrain@segment7.net - http://segment7.net
FEC2 57F1 D465 EB15 5D6E 7C11 332A 551C 796C 9F04
I'm trying to compare how new a file is with the header obtained
from Net::HTTP.head(). I use
[...]
But I can't compare this with the results of File.mtime, because one
is a DateTime, and one is a Time. Time::strptime or Time::strftime
this might help...
harp:~ > cat a.rb
require 'alib'
What is alib?
dunno though... without the 'local' it assumes utc.
I think it depends on whenther I can get both times into the same
form.
cheers.
-a
Thank you
Hugh
···
On Fri, 9 Sep 2005, Ara.T.Howard wrote:
On Fri, 9 Sep 2005, Hugh Sasse wrote:
turned into a time into it. Parsedate deosn't seem to handle this
case, either in so far as it has no str[fp]time.
Time.parse Just Works.
except when it doesn't
i ran into a case this a few months ago, trying to parse a log. i was
getting weird results until i saw that time.parse wasn't parsing
properly...using strptime helped a little...
···
--
http://home.cogeco.ca/~tsummerfelt1
telnet://ventedspleen.dyndns.org
I'm trying to compare how new a file is with the header obtained
from Net::HTTP.head(). I use
[...]
But I can't compare this with the results of File.mtime, because one
is a DateTime, and one is a Time. Time::strptime or Time::strftime
this might help...
harp:~ > cat a.rb
require 'alib'
What is alib?
ara's lib it's a holding place for all the utility methods i don't end up
putting anywhere else. i also have inlined some small, but very useful code
developed by other people like satoru takabayashi's bsearch code for built-in
arrays. it's a mix of useful stuff like
- Util : lot's of time/string/process/filesystem/tmpdir-file/hash
manipulation routines
- Main : utilities for whipping out simple and configurable (via yaml file)
main programs that support usage, logging, command line and option parsing
in seconds
- Bsearch : bsearch support for arrays
- OrderedHash : name says it all
basically it's my personal stash of stuff i can't live without. get it here
http://codeforpeople.com/lib/ruby/alib/
I think it depends on whenther I can get both times into the same form.
to form those methods use is iso-8601 - should be a peice of cake.
cheers.
-a
···
On Fri, 9 Sep 2005, Hugh Sasse wrote:
On Fri, 9 Sep 2005, Ara.T.Howard wrote:
On Fri, 9 Sep 2005, Hugh Sasse wrote:
--
email :: ara [dot] t [dot] howard [at] noaa [dot] gov
phone :: 303.497.6469
Your life dwells amoung the causes of death
Like a lamp standing in a strong breeze. --Nagarjuna
===============================================================================
What is alib?
ara's lib it's a holding place for all the utility methods i don't end
[...]
arrays. it's a mix of useful stuff like
- Util : lot's of time/string/process/filesystem/tmpdir-file/hash
manipulation routines
- Main : utilities for whipping out simple and configurable (via yaml file)
main programs that support usage, logging, command line and option parsing
in seconds
- Bsearch : bsearch support for arrays
- OrderedHash : name says it all
These sound useful, thank you.
basically it's my personal stash of stuff i can't live without. get it here
http://codeforpeople.com/lib/ruby/alib/
Thank you for this.
I think it depends on whenther I can get both times into the same form.
s/nth/th/
to form those methods use is iso-8601 - should be a peice of cake.
And Google waves in the direction of
Which it turns out I have linked to before!
cheers.
-a
Thank you,
Hugh
···
On Fri, 9 Sep 2005, Ara.T.Howard wrote:
On Fri, 9 Sep 2005, Hugh Sasse wrote: