Skip Menu |
 

This queue is for tickets about the TimeDate CPAN distribution.

Report information
The Basics
Id: 1352
Status: resolved
Priority: 0/
Queue: TimeDate

People
Owner: GBARR [...] CPAN.ORG
Requestors: yan [...] seiner.com
Cc:
AdminCc:

Bug Information
Severity: Normal
Broken in: (no value)
Fixed in: (no value)



Subject: TimeDate parsing lpd log files
Download (untitled) / with headers
text/plain 1.1k
I am using timedate to parse lpd-generated log files. lpd uses a '-' to separate its time and date values. Also, I had a problem with parsing the new millenium two digit years. This patch takes care of both: *** TimeDate-1.1301/lib/Date/Parse.pm Thu Jun 6 14:12:58 2002 --- TimeDate-1.1301-ys/lib/Date/Parse.pm Sun Jun 16 12:22:43 2002 *************** *** 88,94 **** $dtstr =~ s#($daypat)\s*(den\s)?# #o; # Time: 12:00 or 12:00:00 with optional am/pm ! if ($dtstr =~ s/(?:^|\s)(\d{4})([-:]?)(\d\d?)\2(\d\d?)(?:[Tt ](\d\d?)(?:([-:]?)(\d\d?)(?:\6(\d\d?)(?:[.,]\d+)?)?)?)?\b/ /) { ($year,$month,$day,$hh,$mm,$ss) = ($1,$3-1,$4,$5,$7,$8); } else { --- 88,94 ---- $dtstr =~ s#($daypat)\s*(den\s)?# #o; # Time: 12:00 or 12:00:00 with optional am/pm ! if ($dtstr =~ s/(?:^|\s)(\d{4})([-:]?)(\d\d?)\2(\d\d?)(?:[Tt -](\d\d?)(?:([-:]?)(\d\d?)(?:\6(\d\d?)(?:[.,]\d+)?)?)?)?\b/ /) { ($year,$month,$day,$hh,$mm,$ss) = ($1,$3-1,$4,$5,$7,$8); } else { *************** *** 184,189 **** --- 184,190 ---- } $year -= 1900 if defined $year && $year > 1900; + $year += 100 if defined $year && $year < 50; $zone += 3600 if defined $zone && $dst; Thanks, --Yan
Download (untitled) / with headers
text/plain 276b
Can you provide some sample dates for testing. I dont like the $year += 100 if < 50. That has potential to break any script that is currently using TimeDate to parse dates from before 1950. Although this is not going to be common, it is a possability that someone is doing it
From: Yan Seiner
Download (untitled) / with headers
text/plain 2.6k
[Sorry if you got my earlier note and this is a repost. CPAN's RT is set up differently from mine; it does not appear to automatically post emailed responses.] Yup. The problem is that if you have a year with 02, it will be parsed as 1902 and not 2002, which is a much more likely scenario. Basically, the parser must make an assumption about the century when it's only given the last two digits of the year. I've changed the assumption, is all. I've since resolved the problem by using RE parsing on input to standardize my dates before they go to the parser. The other possibility is to pass to the parser an optional format string when handling off-the-wall formats. Hylafax, for example, uses a weird date format: 06/08/02 19:31 SEND 00000114 ttyI6 50 "" yan@cardinalengineering.com "3226021" "LOWCOUNTRYLANDCENTER" 2314 1 0:31 0:13 "" 06/08/02 19:35 SEND 00000116 ttyI7 51 "" yan@cardinalengineering.com "322.6021" "LOWCOUNTRYLANDCENTER" 2314 6 2:00 1:46 "" 06/08/02 19:44 SEND 00000118 ttyI6 52 "" yan@cardinalengineering.com "322.6021" "LOWCOUNTRYLANDCENTER" 2314 1 0:41 0:27 "" 02/08/02 20:25 SEND 00000120 ttyI7 53 "" yan@cardinalengineering.com "322.6021" "LOWCOUNTRYLANDCENTER" 2315 1 0:33 0:19 "" 02/09/02 05:52 SEND 00000122 ttyI6 54 "" yan@cardinalengineering.com "322.6021" "LOWCOUNTRYLANDCENTER" 2315 2 1:12 0:54 "" "" You really have to look at a series of dates to figure out which is yy, mm, and dd. No way a parser can make that call. Knowing that this is US software, I'd guess it's mm/dd/yy, but you really have to look to be sure. For the other item, here's the output of lpd log files: cardinal jim 1149 3 2002-02-26-10:37:21.141 2002-02-26-10:37:40.000 smbprn.000798.9evHfX aphrodite.cardinal.lan cardinal jim 1150 1 2002-02-26-10:37:35.042 2002-02-26-10:38:02.000 smbprn.000799.5FEI4I aphrodite.cardinal.lan cardinal jim 1219 1 2002-02-26-15:16:50.244 2002-02-26-15:16:52.000 smbprn.000810.J5wnVi aphrodite.cardinal.lan cardinal jim 1220 1 2002-02-26-15:32:53.831 2002-02-26-15:32:56.000 smbprn.000814.MFfzsB aphrodite.cardinal.lan cardinal jim 1221 1 2002-02-26-15:35:59.887 2002-02-26-15:36:02.000 smbprn.000817.EmxbXB aphrodite.cardinal.lan The dates are as lpd feeds them to the various filters - af, if, and of And here's my version of lpd (AFAIK, the date format has not changed in a long time): [root@aphrodite /root]# lpd -V LPRng-3.7.4, Copyright 1988-2000 Patrick Powell, <papowell@lprng.com> --Yan
From: Yan Seiner
Download (untitled) / with headers
text/plain 2.6k
[Sorry if you got my earlier note and this is a repost. CPAN's RT is set up differently from mine; it does not appear to automatically post emailed responses.] Yup. The problem is that if you have a year with 02, it will be parsed as 1902 and not 2002, which is a much more likely scenario. Basically, the parser must make an assumption about the century when it's only given the last two digits of the year. I've changed the assumption, is all. I've since resolved the problem by using RE parsing on input to standardize my dates before they go to the parser. The other possibility is to pass to the parser an optional format string when handling off-the-wall formats. Hylafax, for example, uses a weird date format: 06/08/02 19:31 SEND 00000114 ttyI6 50 "" yan@cardinalengineering.com "3226021" "LOWCOUNTRYLANDCENTER" 2314 1 0:31 0:13 "" 06/08/02 19:35 SEND 00000116 ttyI7 51 "" yan@cardinalengineering.com "322.6021" "LOWCOUNTRYLANDCENTER" 2314 6 2:00 1:46 "" 06/08/02 19:44 SEND 00000118 ttyI6 52 "" yan@cardinalengineering.com "322.6021" "LOWCOUNTRYLANDCENTER" 2314 1 0:41 0:27 "" 02/08/02 20:25 SEND 00000120 ttyI7 53 "" yan@cardinalengineering.com "322.6021" "LOWCOUNTRYLANDCENTER" 2315 1 0:33 0:19 "" 02/09/02 05:52 SEND 00000122 ttyI6 54 "" yan@cardinalengineering.com "322.6021" "LOWCOUNTRYLANDCENTER" 2315 2 1:12 0:54 "" "" You really have to look at a series of dates to figure out which is yy, mm, and dd. No way a parser can make that call. Knowing that this is US software, I'd guess it's mm/dd/yy, but you really have to look to be sure. For the other item, here's the output of lpd log files: cardinal jim 1149 3 2002-02-26-10:37:21.141 2002-02-26-10:37:40.000 smbprn.000798.9evHfX aphrodite.cardinal.lan cardinal jim 1150 1 2002-02-26-10:37:35.042 2002-02-26-10:38:02.000 smbprn.000799.5FEI4I aphrodite.cardinal.lan cardinal jim 1219 1 2002-02-26-15:16:50.244 2002-02-26-15:16:52.000 smbprn.000810.J5wnVi aphrodite.cardinal.lan cardinal jim 1220 1 2002-02-26-15:32:53.831 2002-02-26-15:32:56.000 smbprn.000814.MFfzsB aphrodite.cardinal.lan cardinal jim 1221 1 2002-02-26-15:35:59.887 2002-02-26-15:36:02.000 smbprn.000817.EmxbXB aphrodite.cardinal.lan The dates are as lpd feeds them to the various filters - af, if, and of And here's my version of lpd (AFAIK, the date format has not changed in a long time): [root@aphrodite /root]# lpd -V LPRng-3.7.4, Copyright 1988-2000 Patrick Powell, <papowell@lprng.com> --Yan


This service is sponsored and maintained by Best Practical Solutions and runs on Perl.org infrastructure.

Please report any issues with rt.cpan.org to rt-cpan-admin@bestpractical.com.