2014-01-14 05:52:21 -08:00
|
|
|
#!/usr/bin/env perl
|
|
|
|
|
|
|
|
use strict;
|
|
|
|
use warnings;
|
|
|
|
use Test::More;
|
|
|
|
use DDG::Test::Goodie;
|
2014-01-16 18:58:24 -08:00
|
|
|
use Time::Piece;
|
2014-01-14 05:52:21 -08:00
|
|
|
|
|
|
|
zci answer_type => 'workdays_between';
|
|
|
|
|
2014-01-16 18:58:24 -08:00
|
|
|
# In the output, the abbreviated month will return different results based on
|
|
|
|
# the user's language settings. This means we need to test against those
|
|
|
|
# specific values instead of hardcoding in the month abbreviations.
|
|
|
|
# Abbreviation for January (Jan in english)
|
|
|
|
my $JAN_ABBREV = Time::Piece->strptime("01", "%m")->strftime("%b");
|
|
|
|
# Abbreviation for June (Jun in english)
|
|
|
|
my $JUN_ABBREV = Time::Piece->strptime("06", "%m")->strftime("%b");
|
|
|
|
|
2014-01-14 05:52:21 -08:00
|
|
|
ddg_goodie_test(
|
|
|
|
[
|
|
|
|
'DDG::Goodie::WorkdaysBetween'
|
|
|
|
],
|
|
|
|
|
|
|
|
# Standard work week
|
|
|
|
'workdays between 01/06/2014 01/10/2014' =>
|
2014-01-16 18:58:24 -08:00
|
|
|
test_zci("There are 4 workdays between $JAN_ABBREV 06, 2014 and $JAN_ABBREV 10, 2014."),
|
2014-01-14 05:52:21 -08:00
|
|
|
'workdays between 01/06/2014 01/10/2014 inclusive' =>
|
2014-01-16 18:58:24 -08:00
|
|
|
test_zci("There are 5 workdays between $JAN_ABBREV 06, 2014 and $JAN_ABBREV 10, 2014, inclusive."),
|
2014-01-14 05:52:21 -08:00
|
|
|
|
2014-01-14 14:59:16 -08:00
|
|
|
# Ending date first
|
|
|
|
'workdays between 01/10/2014 01/06/2014' =>
|
2014-01-16 18:58:24 -08:00
|
|
|
test_zci("There are 4 workdays between $JAN_ABBREV 06, 2014 and $JAN_ABBREV 10, 2014."),
|
2014-01-14 14:59:16 -08:00
|
|
|
'workdays between 01/10/2014 01/06/2014 inclusive' =>
|
2014-01-16 18:58:24 -08:00
|
|
|
test_zci("There are 5 workdays between $JAN_ABBREV 06, 2014 and $JAN_ABBREV 10, 2014, inclusive."),
|
2014-01-14 14:59:16 -08:00
|
|
|
|
2014-01-14 05:52:21 -08:00
|
|
|
# Ending date on a weekend
|
|
|
|
'workdays between 01/06/2014 01/12/2014' =>
|
2014-01-16 18:58:24 -08:00
|
|
|
test_zci("There are 4 workdays between $JAN_ABBREV 06, 2014 and $JAN_ABBREV 12, 2014."),
|
2014-01-14 05:52:21 -08:00
|
|
|
'workdays between 01/06/2014 01/12/2014 inclusive' =>
|
2014-01-16 18:58:24 -08:00
|
|
|
test_zci("There are 5 workdays between $JAN_ABBREV 06, 2014 and $JAN_ABBREV 12, 2014, inclusive."),
|
2014-01-14 05:52:21 -08:00
|
|
|
|
|
|
|
# Including the weekend
|
|
|
|
'workdays between 01/06/2014 01/13/2014' =>
|
2014-01-16 18:58:24 -08:00
|
|
|
test_zci("There are 5 workdays between $JAN_ABBREV 06, 2014 and $JAN_ABBREV 13, 2014."),
|
2014-01-14 05:52:21 -08:00
|
|
|
'workdays between 01/06/2014 01/13/2014 inclusive' =>
|
2014-01-16 18:58:24 -08:00
|
|
|
test_zci("There are 6 workdays between $JAN_ABBREV 06, 2014 and $JAN_ABBREV 13, 2014, inclusive."),
|
2014-01-14 05:52:21 -08:00
|
|
|
|
2014-01-14 14:59:16 -08:00
|
|
|
# Including the weekend -- Backwards
|
|
|
|
'workdays between 01/13/2014 01/06/2014' =>
|
2014-01-16 18:58:24 -08:00
|
|
|
test_zci("There are 5 workdays between $JAN_ABBREV 06, 2014 and $JAN_ABBREV 13, 2014."),
|
2014-01-14 14:59:16 -08:00
|
|
|
'workdays between 01/13/2014 01/06/2014 inclusive' =>
|
2014-01-16 18:58:24 -08:00
|
|
|
test_zci("There are 6 workdays between $JAN_ABBREV 06, 2014 and $JAN_ABBREV 13, 2014, inclusive."),
|
2014-01-14 14:59:16 -08:00
|
|
|
|
2014-01-14 05:52:21 -08:00
|
|
|
# Starting on a Saturday
|
|
|
|
'workdays between 01/11/2014 01/14/2014' =>
|
2014-01-24 12:26:11 -08:00
|
|
|
test_zci("There are 1 workdays between $JAN_ABBREV 11, 2014 and $JAN_ABBREV 14, 2014."),
|
2014-01-14 05:52:21 -08:00
|
|
|
'workdays between 01/11/2014 01/14/2014 inclusive' =>
|
2014-01-24 12:26:11 -08:00
|
|
|
test_zci("There are 2 workdays between $JAN_ABBREV 11, 2014 and $JAN_ABBREV 14, 2014, inclusive."),
|
2014-01-14 05:52:21 -08:00
|
|
|
|
|
|
|
# Starting on a Sunday
|
|
|
|
'workdays between 01/12/2014 01/14/2014' =>
|
2014-01-24 12:26:11 -08:00
|
|
|
test_zci("There are 1 workdays between $JAN_ABBREV 12, 2014 and $JAN_ABBREV 14, 2014."),
|
2014-01-14 05:52:21 -08:00
|
|
|
'workdays between 01/12/2014 01/14/2014 inclusive' =>
|
2014-01-24 12:26:11 -08:00
|
|
|
test_zci("There are 2 workdays between $JAN_ABBREV 12, 2014 and $JAN_ABBREV 14, 2014, inclusive."),
|
2014-01-14 05:52:21 -08:00
|
|
|
|
|
|
|
# Workdays in a year
|
|
|
|
'workdays between 01/01/2014 01/01/2015' =>
|
2014-01-16 18:58:24 -08:00
|
|
|
test_zci("There are 261 workdays between $JAN_ABBREV 01, 2014 and $JAN_ABBREV 01, 2015."),
|
2014-01-14 05:52:21 -08:00
|
|
|
'workdays between 01/01/2014 01/01/2015 inclusive' =>
|
2014-01-16 18:58:24 -08:00
|
|
|
test_zci("There are 262 workdays between $JAN_ABBREV 01, 2014 and $JAN_ABBREV 01, 2015, inclusive."),
|
2014-01-14 05:52:21 -08:00
|
|
|
|
2014-01-15 12:58:05 -08:00
|
|
|
# Business Days
|
|
|
|
'business days between 01/06/2014 01/10/2014' =>
|
2014-01-16 18:58:24 -08:00
|
|
|
test_zci("There are 4 workdays between $JAN_ABBREV 06, 2014 and $JAN_ABBREV 10, 2014."),
|
2014-01-15 12:58:05 -08:00
|
|
|
'business days between 01/06/2014 01/10/2014 inclusive' =>
|
2014-01-16 18:58:24 -08:00
|
|
|
test_zci("There are 5 workdays between $JAN_ABBREV 06, 2014 and $JAN_ABBREV 10, 2014, inclusive."),
|
2014-01-15 12:58:05 -08:00
|
|
|
|
2014-01-15 14:15:44 -08:00
|
|
|
# Month and Date are backwards
|
|
|
|
'workdays between 16/06/2014 20/06/2014' =>
|
2014-01-16 18:58:24 -08:00
|
|
|
test_zci("There are 4 workdays between $JUN_ABBREV 16, 2014 and $JUN_ABBREV 20, 2014."),
|
2014-01-16 20:26:52 -08:00
|
|
|
'workdays between 5/06/2014 20/06/2014' =>
|
|
|
|
test_zci("There are 11 workdays between $JUN_ABBREV 05, 2014 and $JUN_ABBREV 20, 2014."),
|
|
|
|
'workdays between 20/06/2014 5/06/2014' =>
|
|
|
|
test_zci("There are 11 workdays between $JUN_ABBREV 05, 2014 and $JUN_ABBREV 20, 2014."),
|
2014-01-15 14:15:44 -08:00
|
|
|
|
2014-01-15 14:40:42 -08:00
|
|
|
# Single digit days and months
|
2014-01-16 18:14:43 -08:00
|
|
|
'workdays between 1/6/2014 1/10/2014' =>
|
2014-01-16 18:58:24 -08:00
|
|
|
test_zci("There are 4 workdays between $JAN_ABBREV 06, 2014 and $JAN_ABBREV 10, 2014."),
|
2014-01-15 14:40:42 -08:00
|
|
|
'workdays between 1/6/2014 1/10/2014 inclusive' =>
|
2014-01-16 18:58:24 -08:00
|
|
|
test_zci("There are 5 workdays between $JAN_ABBREV 06, 2014 and $JAN_ABBREV 10, 2014, inclusive."),
|
2014-01-15 14:40:42 -08:00
|
|
|
|
2014-01-15 14:36:01 -08:00
|
|
|
# Unambiguous date format
|
|
|
|
'workdays between jan 6 2014 jan 10 2014' =>
|
2014-01-16 18:58:24 -08:00
|
|
|
test_zci("There are 4 workdays between $JAN_ABBREV 06, 2014 and $JAN_ABBREV 10, 2014."),
|
2014-01-15 14:36:01 -08:00
|
|
|
'workdays between jan 6 2014 jan 10 2014 inclusive' =>
|
2014-01-16 18:58:24 -08:00
|
|
|
test_zci("There are 5 workdays between $JAN_ABBREV 06, 2014 and $JAN_ABBREV 10, 2014, inclusive."),
|
2014-01-15 14:36:01 -08:00
|
|
|
|
2014-01-15 14:38:36 -08:00
|
|
|
# Unambiguous date format with comma separator
|
|
|
|
'workdays between jan 6, 2014 jan 10, 2014' =>
|
2014-01-16 18:58:24 -08:00
|
|
|
test_zci("There are 4 workdays between $JAN_ABBREV 06, 2014 and $JAN_ABBREV 10, 2014."),
|
2014-01-15 14:38:36 -08:00
|
|
|
'workdays between jan 6, 2014 jan 10, 2014 inclusive' =>
|
2014-01-16 18:58:24 -08:00
|
|
|
test_zci("There are 5 workdays between $JAN_ABBREV 06, 2014 and $JAN_ABBREV 10, 2014, inclusive."),
|
2014-01-15 14:38:36 -08:00
|
|
|
|
2014-01-14 05:52:21 -08:00
|
|
|
# Invalid input
|
|
|
|
'workdays between 01/2014 01/2015' => undef,
|
|
|
|
'workdays between 01/2014/01' => undef,
|
|
|
|
'workdays between 01/01/2014 inclusive' => undef,
|
2014-01-15 14:15:44 -08:00
|
|
|
'workdays between 01/01/2014' => undef,
|
|
|
|
'workdays between 20/01/2014 inclusive' => undef,
|
2014-01-15 14:17:24 -08:00
|
|
|
'workdays between 19/19/2014 20/24/2015' => undef,
|
|
|
|
'workdays between 19/19/2014 20/24/2015 inclusive' => undef,
|
2014-01-14 05:52:21 -08:00
|
|
|
);
|
|
|
|
|
|
|
|
done_testing;
|