Perl-Date-Business / perl-date-business

Other
0 stars 1 forks source link

timegm should be called with 4-digit year #2

Open bpschuck opened 1 month ago

bpschuck commented 1 month ago

See original at https://rt.cpan.org/Ticket/Display.html?id=124549


man Time::Local says

Whenever possible, use an absolute four digit year instead.

With a detailed explanation about ambiguity of 2-digit years above that.

Please review/test/merge the attached patch


Index: Date-Business-1.2/Business.pm

--- Date-Business-1.2.orig/Business.pm
+++ Date-Business-1.2/Business.pm
@@ -93,7 +93,7 @@ sub image2value($;$) {
   my($image) = @_;

   $image =~ m/(....)(..)(..)/;
-  return timegm(0, 0, 0, $3, ($2-1), $1 - 1900);
+  return timegm(0, 0, 0, $3, ($2-1), $1);
 }  

sub value($) {

If a change is to be made, it looks like replacing timegm() with timegm_modern() is also a good idea.

bpschuck commented 1 week ago

Time::Local also says:

Strictly speaking, the year should be specified in a form consistent with "localtime()", i.e. the offset from 1900. In order to make the interpretation of the year easier for humans, however, who are more accustomed to seeing years as two-digit or four-digit values, the following conventions are followed: