DateTime::Format::ISO8601->parse_time

5 views
Skip to first unread message

hymie!

unread,
Jan 3, 2021, 8:41:20 PMJan 3
to
Greetings.

I'm a big fan of the DateTime modules, but I'm having some trouble with
the DateTime::Format::ISO8601 parse_time() function.

The problem I'm having is that I'm in UTC-0500 (US Eastern Time Zone) but
the parse_time function assumes I'm working in UTC. So if the current
date/time is 2021-01-03 20:00 in my local time zone, then parse_time is
working off of a base of 2021-01-04 01:00 . Since parse_time does not
take a date, only a time, then the resulting object is off by a day.

I am aware that DateTime::Format::ISO8601->new() takes an optional
"base_datetime" , but when I try to set this:

$base = DateTime->now()->set_time_zone("America/New_York");

$date = DateTime::Format::ISO8601 -> new ( base_datetime => $base )
->parse_time( "1955" );

I end up in an infinite loop.

brk(0x2808000) = 0x2808000
brk(0x2829000) = 0x2829000
brk(0x284a000) = 0x284a000
brk(0x286b000) = 0x286b000
brk(0x288c000) = 0x288c000
brk(0x288b000) = 0x288b000
brk(0x28ac000) = 0x28ac000
brk(0x28cd000) = 0x28cd000
brk(0x28ee000) = 0x28ee000
brk(0x28ed000) = 0x28ed000
[...]

Is there something that I can do to force DateTime::Format::ISO8601's
parse_time() function to do what I want -- use the local time zone as
its base for the unspecified date?

(Reminder, for those of you willing to test and help -- the problem only
exists when the **current time** is between midnight-UTC and midnight-local,
**not** the time provided to the parse_time function.)

Thanks.

--hymie! http://nasalinux.net/~hymie hy...@nasalinux.net

George Bouras

unread,
Jan 4, 2021, 3:49:10 PMJan 4
to
Στις 4/1/2021 3:41 π.μ., ο/η hymie! έγραψε:
> Greetings.
>
> I'm a big fan of the DateTime modules, but I'm having some trouble with
> the DateTime::Format::ISO8601 parse_time() function.


maybe not what you want but it looks fine to me
my ($YYYY,$MM,$DD,$HH,$MM,$SS) = ...
=~/^(\d+4)(\d\d)(\d\d)(\d\d)(\d\d)(\d\d)$/ or die "shit happens\n";


hymie!

unread,
Jan 5, 2021, 8:25:18 AMJan 5
to
In our last episode, the evil Dr. Lacto had captured our hero,
I'm sorry, but I honestly have no idea what you're trying to say here.

--hymie! http://nasalinux.net/~hymie hy...@nasalinux.net

Rainer Weikusat

unread,
Jan 5, 2021, 11:13:15 AMJan 5
to
hymie! <hy...@nasalinux.net> writes:
>
> I'm a big fan of the DateTime modules, but I'm having some trouble with
> the DateTime::Format::ISO8601 parse_time() function.
>
> The problem I'm having is that I'm in UTC-0500 (US Eastern Time Zone) but
> the parse_time function assumes I'm working in UTC.

Juding from the documentation and a (somewhat cursory) look at the code,
it should be possible to pass the local time zone as numeric offset
appended to the time string, eg,

20:00:00-05:00

at least for parse_datetime.
Reply all
Reply to author
Forward
0 new messages