Created
March 7, 2014 09:19
-
-
Save neilb/9408257 to your computer and use it in GitHub Desktop.
Show dates where Date::WeekOfYear gets the week number wrong
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/local/bin/perl | |
# | |
# Compares the week numbers from DateTime and Date::WeekOfYear | |
# This shows the places where WeekOfYear gets it wrong. | |
# | |
use strict; | |
use warnings; | |
use DateTime; | |
use Date::WeekOfYear; | |
my $DAY_IN_SECONDS = 24 * 60 * 60; | |
my $time = time(); | |
for (my $i = 0; $i < 1500; $i++) { | |
my @tm = gmtime($time); | |
my ($year, $month, $day) = @tm[5,4,3]; | |
$year += 1900; | |
$month++; | |
my $dt = DateTime->from_epoch(epoch => $time); | |
my ($week_year, $week_number) = $dt->week; | |
my $dt_week = sprintf("%.4d-W%.2d", $week_year, $week_number); | |
my ($woy_week, $woy_year) = WeekOfYear($time); | |
my $date = $dt->strftime('%Y-%m-%d'); | |
my $woy = sprintf("%.4d-W%.2d", $woy_year, $woy_week); | |
if ($woy ne $dt_week) { | |
print "for $date, epoch=$time, dt_week=$dt_week, WeekOfYear=$woy\n"; | |
} | |
$time -= $DAY_IN_SECONDS; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment