in reply to DateTime conversion
Hard to know where to start here. Firstly, you seem to have completely misunderstood the DateTime::Format::Builder tutorial. Please read it again. More carefully this time.
Secondly, even when I rewrote your example to use the module correctly, it still didn't work as your regex didn't come close to matching your date string. Having corrected that as well, the code I ended up with was:
#!/usr/bin/perl use strict; use warnings; package DateTime::Format::MyParser; use DateTime::Format::Builder ( parsers => { parse_datetime => { regex => qr/^(\d?\d)\s(\d\d)\s(\d\d\d\d) (\d\d):(\d\d):(\d\d)$/ +, params => [ qw( day month year hour minute second ) ], }, }, ); package main; my $date = "Thu, 7 Aug 2008 08:35:36 +01:00"; $date =~ s/Thu, //; $date =~ s/\s+\+01:00$//; $date =~ s/Aug/08/; my $parser = DateTime::Format::MyParser->new(); my $dt = $parser->parse_datetime($date); print $dt;
It still bothers me that you do all that munging of the input string before trying to use it. Surely the point of parsing a date string is to parse the string that you are given, not to have to munge your string into some intermediate format first.
Finally, I think that DateTime::Format::Builder might be completely the wrong tool for what you are doing here. DateTime::Format::Builder is for building DateTime::Format modules (there's a clue in the name). If you're just want to parse a date string and turn it into a DateTime object, then you probably want DateTime::Format::Strptime instead.
See the Copyright notice on my home node.
"The first rule of Perl club is you do not talk about Perl club." -- Chip Salzenberg
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: DateTime conversion
by dHarry (Abbot) on Aug 07, 2008 at 11:35 UTC | |
by davorg (Chancellor) on Aug 07, 2008 at 11:53 UTC |