Last active
June 14, 2017 06:02
-
-
Save aereal/96017b666a27ecd6c7e8ee5b2db54fa9 to your computer and use it in GitHub Desktop.
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/bin/env perl | |
use strict; | |
use warnings; | |
use DateTime::Format::W3CDTF; | |
use DateTime; | |
use Test::More; | |
{ | |
my $days = get_days( | |
DateTime::Format::W3CDTF->parse_datetime('2017-01-01'), | |
DateTime::Format::W3CDTF->parse_datetime('2017-01-01') | |
); | |
is $days, 0; | |
}; | |
{ | |
my $days = get_days( | |
DateTime::Format::W3CDTF->parse_datetime('2017-01-01'), | |
DateTime::Format::W3CDTF->parse_datetime('2017-01-02') | |
); | |
is $days, 1; | |
}; | |
{ | |
my $days = get_days( | |
DateTime::Format::W3CDTF->parse_datetime('2017-01-01'), | |
DateTime::Format::W3CDTF->parse_datetime('2017-02-01') | |
); | |
is $days, 31; | |
}; | |
{ | |
my $days = get_days( | |
DateTime::Format::W3CDTF->parse_datetime('2017-01-01'), | |
DateTime::Format::W3CDTF->parse_datetime('2017-01-31') | |
); | |
is $days, 30; | |
}; | |
sub get_days { | |
my ($date1, $date2) = @_; | |
return $date2->delta_days($date1)->delta_days; | |
} | |
done_testing; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment