Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   Ruby (http://www.velocityreviews.com/forums/f66-ruby.html)
-   -   Time.gm(1969) chokes on Windows (http://www.velocityreviews.com/forums/t847100-time-gm-1969-chokes-on-windows.html)

Tim Ferrell 01-03-2008 06:12 PM

Time.gm(1969) chokes on Windows
 

I was trying to sort out a YAML parsing issue on Windows XP SP 2 and
traced it to Time.gm failing on pre-1970 dates ... this works fine on
both Ubuntu Linux and my Mac... Any ideas or workarounds?

Thanks!
Tim
--
Posted via http://www.ruby-forum.com/.


James Tucker 01-03-2008 06:20 PM

Re: Time.gm(1969) chokes on Windows
 
It may or may not be related, but check in:

Control Panel -> Regional and Language Options -> Regional Options ->
Customize... -> Date -> "Calendar"

You'll find the default time ranges for date assumptions.

It's quite likely that ruby doesn't use these though.

On 3 Jan 2008, at 14:12, Tim Ferrell wrote:

>
> I was trying to sort out a YAML parsing issue on Windows XP SP 2 and
> traced it to Time.gm failing on pre-1970 dates ... this works fine on
> both Ubuntu Linux and my Mac... Any ideas or workarounds?
>
> Thanks!
> Tim
> --
> Posted via http://www.ruby-forum.com/.
>




Rob Biedenharn 01-03-2008 06:27 PM

Re: Time.gm(1969) chokes on Windows
 
If you want a date, use Date. (require 'date')

It handled any date you'd care to throw at it and 1969/1970 is not an
issue.

-Rob

On Jan 3, 2008, at 1:20 PM, James Tucker wrote:

> It may or may not be related, but check in:
>
> Control Panel -> Regional and Language Options -> Regional Options -
> > Customize... -> Date -> "Calendar"

>
> You'll find the default time ranges for date assumptions.
>
> It's quite likely that ruby doesn't use these though.
>
> On 3 Jan 2008, at 14:12, Tim Ferrell wrote:
>
>>
>> I was trying to sort out a YAML parsing issue on Windows XP SP 2 and
>> traced it to Time.gm failing on pre-1970 dates ... this works fine on
>> both Ubuntu Linux and my Mac... Any ideas or workarounds?
>>
>> Thanks!
>> Tim



Rob Biedenharn http://agileconsultingllc.com
Rob@AgileConsultingLLC.com




David Morton 01-03-2008 06:42 PM

Re: Time.gm(1969) chokes on Windows
 
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

I'd expect it to be the other way around, when using Time as opposed
to Date:

http://en.wikipedia.org/wiki/Unix_time


On Jan 3, 2008, at 12:12 PM, Tim Ferrell wrote:

>
> I was trying to sort out a YAML parsing issue on Windows XP SP 2 and
> traced it to Time.gm failing on pre-1970 dates ... this works fine on
> both Ubuntu Linux and my Mac... Any ideas or workarounds?
>
> Thanks!
> Tim
> --
> Posted via http://www.ruby-forum.com/.
>


David Morton
Maia Mailguard http://www.maiamailguard.com
mortonda@dgrmm.net



-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.7 (Darwin)

iD8DBQFHfSypUy30ODPkzl0RAibiAKCxj51ItJR2UZlURyubdZ Y0cUpT7ACgx7FQ
djOCSDn7tHIUIVIjGhOc4oU=
=a1gl
-----END PGP SIGNATURE-----


Tim Ferrell 01-03-2008 07:29 PM

Re: Time.gm(1969) chokes on Windows
 

Thanks Rob, but unfortunately I am not the one doing the parsing - YAML
is... and it uses Time.gm/Time.utc, which are apparently "built-in"
functions in Ruby (i.e. implemented in C) ... I can't help but think
this is just a setting somewhere...

I checked my regional settings (as James Tucker suggested) but that
setting only appears to affect how Windows interprets 2-digit years.
Ruby must be doing some kind of system api call for this and it is just
limited on Windows...

Any other thoughts?


Rob Biedenharn wrote:
> If you want a date, use Date. (require 'date')
>
> It handled any date you'd care to throw at it and 1969/1970 is not an
> issue.

--
Posted via http://www.ruby-forum.com/.


Rob Biedenharn 01-03-2008 07:45 PM

Re: Time.gm(1969) chokes on Windows
 
On Jan 3, 2008, at 2:29 PM, Tim Ferrell wrote:
> Thanks Rob, but unfortunately I am not the one doing the parsing -
> YAML
> is... and it uses Time.gm/Time.utc, which are apparently "built-in"
> functions in Ruby (i.e. implemented in C) ... I can't help but think
> this is just a setting somewhere...
>
> I checked my regional settings (as James Tucker suggested) but that
> setting only appears to affect how Windows interprets 2-digit years.
> Ruby must be doing some kind of system api call for this and it is
> just
> limited on Windows...
>
> Any other thoughts?


irb> YAML.load("--- 2008-01-03 14:42:18.998097 -05:00\n").class
=> Time
irb> YAML.load("--- 2008-01-03\n").class
=> Date

What does your YAML look like? What exactly is being parsed (and
where does it come from if that might matter)?

-Rob

> Rob Biedenharn wrote:
>> If you want a date, use Date. (require 'date')
>>
>> It handled any date you'd care to throw at it and 1969/1970 is not an
>> issue.

> --
> Posted via http://www.ruby-forum.com/.
>


Rob Biedenharn http://agileconsultingllc.com
Rob@AgileConsultingLLC.com




Jamey Cribbs 01-03-2008 07:55 PM

Re: Time.gm(1969) chokes on Windows
 
[Note: parts of this message were removed to make it a legal post.]

Nope. It's not going to work on windows. You can always force the value in
the YAML file to be a string by prepending it with !str, and then you can
convert it however you want in your script.



On Jan 3, 2008 2:29 PM, Tim Ferrell < s0nspark@gmail.com> wrote:

>
> Thanks Rob, but unfortunately I am not the one doing the parsing - YAML
> is... and it uses Time.gm/Time.utc, which are apparently "built-in"
> functions in Ruby (i.e. implemented in C) ... I can't help but think
> this is just a setting somewhere...
>
> I checked my regional settings (as James Tucker suggested) but that
> setting only appears to affect how Windows interprets 2-digit years.
> Ruby must be doing some kind of system api call for this and it is just
> limited on Windows...
>
> Any other thoughts?
>
>
> Rob Biedenharn wrote:
> > If you want a date, use Date. (require 'date')
> >
> > It handled any date you'd care to throw at it and 1969/1970 is not an
> > issue.

> --
> Posted via http://www.ruby-forum.com/.
>
>
>



Tim Ferrell 01-04-2008 01:03 PM

Re: Time.gm(1969) chokes on Windows
 
Jamey Cribbs wrote:
> Nope. It's not going to work on windows. You can always force the
> value in
> the YAML file to be a string by prepending it with !str, and then you
> can
> convert it however you want in your script.


Well, in this case I have no control over how the yaml file gets
created...

This just seems to me to be a bad design decision somewhere. Why would
YAML use Time.gm to deserialize rather than DateTime given the fact that
Time.gm behavior is so system-dependent?!

What I ended up doing to work around this temporarily was get a hold of
the pure ruby yaml library, RbYAML, and hacked the timestamp code to use
DateTime.parse instead of Time.gm - I haven't finished fully testing it
yet and I may be missing some kind of big issue as well, but it seems to
work at the moment.

This, in concert with the Rails ActiveSupport Date/Time/DateTime core
extensions gives me some ability to work with timestamps in a fairly
interchangeable fashion but... honestly, this kind of thing sucks!
Having two seemingly similar timestamp classes just leads to confusion,
especially with those new to the language! The fact that their APIs
aren't similar doesn't help matters, as that must end up dictating which
to use in some cases... IMO, DateTime and Time objects should be fully
interchangeable!
--
Posted via http://www.ruby-forum.com/.


Rob Biedenharn 01-04-2008 01:44 PM

Re: Time.gm(1969) chokes on Windows
 
On Jan 4, 2008, at 8:03 AM, Tim Ferrell wrote:
> Jamey Cribbs wrote:
>> Nope. It's not going to work on windows. You can always force the
>> value in
>> the YAML file to be a string by prepending it with !str, and then you
>> can
>> convert it however you want in your script.

>
> Well, in this case I have no control over how the yaml file gets
> created...



You still haven't shown the exact format of the string that YAML
doesn't parse the way you want. I showed you that the format of the
string influences whether YAML creates a Date or a Time object. If
you have a string that appears to be in the format of a time, but is
outside the range of a Time object (on your platform), there may not
be any way to get YAML to do what you want. You can either get a
better platform or preprocess the YAML to add the type specifier !str
as Jamey suggests. (Or perhaps some other hackery to change how YAML
treats timestamps on your platform.)

-Rob

Rob Biedenharn http://agileconsultingllc.com
Rob@AgileConsultingLLC.com




Tim Ferrell 01-04-2008 03:24 PM

Re: Time.gm(1969) chokes on Windows
 
Rob Biedenharn wrote:
>
> You still haven't shown the exact format of the string that YAML
> doesn't parse the way you want. I showed you that the format of the
> string influences whether YAML creates a Date or a Time object. If
> you have a string that appears to be in the format of a time, but is
> outside the range of a Time object (on your platform), there may not
> be any way to get YAML to do what you want. You can either get a
> better platform or preprocess the YAML to add the type specifier !str
> as Jamey suggests.


Obviously the string in question is a timestamp - YAML/Syck handles
plain pre-1970 dates just fine. So, assuming I have valid pre-1970
timestamps to deal with, I am left with no choice BUT to work around
Syck's (IMO shortsighted) choice of using Time.gm rather than DateTime,
which I'm fairly certain was done for performance reasons... Still, it
seems a rather bad choice given that it is not always portable.

My workaround was to drop Syck for this app and use a customized version
of RbYAML, as mentioned in my previous post.

As for the "better platform" comment - believe me, it is not my choice
to use Windows for this particular case but, given some constraints I am
in no position to address right now, there is no other option.
--
Posted via http://www.ruby-forum.com/.



All times are GMT. The time now is 12:28 AM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.