EAI-Wrap
view release on metacpan or search on metacpan
t/1_DateUtil.t view on Meta::CPAN
is(last_week(27,5,2019,1,5),1,'last_week 1=last monday in may');
is(last_week(10,5,2019,1,5),0,'last_week false');
like(get_curdate,qr/\d{8}/,'get_curdate');
like(get_curdatetime,qr/\d{8}_\d{6}/,'get_curdatetime');
like(get_curdate_dot,qr/\d{2}\.\d{2}\.20\d{2}/,'get_curdate_dot');
is(formatDate(2019,1,1,"D.M.Y"),"01.01.2019",'formatDate D.M.Y');
is(formatDate(2019,3,1,"D.MMM.Y"),"01.Mar.2019",'formatDate D.MMM.Y');
is(formatDate(2019,3,1,"D.mmm.Y"),"01.Mär.2019",'formatDate D.mmm.Y');
is(formatDateFromYYYYMMDD("20190101","D.M.Y"),"01.01.2019",'formatDateFromYYYYMMDD D.M.Y');
is(get_curdate_dash_plus_X_years(100,"20190101"),"01-01-2119",'get_curdate_dash_plus_X_years with date');
is(get_curdate_dash_plus_X_years(30,"20240229"),"28-02-2054",'get_curdate_dash_plus_X_years with date regarding leap year1');
is(get_curdate_dash_plus_X_years(30,"20240228"),"28-02-2054",'get_curdate_dash_plus_X_years with date regarding leap year2');
print get_curdate_dash_plus_X_years(30)."\n";
is(get_curdate_dash_plus_X_years(100,"20190105",4),"01-01-2119",'get_curdate_dash_plus_X_years with date and subtract days');
# only "like" on the format, as these functions pass back volatile values
like(get_curdate_dash(),qr/\d{2}\-\d{2}\-20\d{2}/,'get_curdate_dash');
like(get_curdate_dash_plus_X_years(100),qr/\d{2}\-\d{2}\-21\d{2}/,'get_curdate_dash_plus_X_years without date');
like(get_curtime(),qr/\d{2}:\d{2}:\d{2}/,'get_curtime');
like(get_curtime("%02d_%02d_%02d"),qr/\d{2}_\d{2}_\d{2}/,'get_curtime with format %02d_%02d_%02d');
like(get_curtime("%02d%02d%02d"),qr/\d{2}\d{2}\d{2}/,'get_curtime with format %02d%02d%02d');
print "get_curtime HHMMSS:".get_curtime("%02d%02d%02d")."\n";
print "get_curtime HHMMSS + 30 seconds:".get_curtime("%02d%02d%02d",30)."\n";
print "get_curtime HHMMSS + 1 day (next day):".get_curtime("%02d%02d%02d",24*60*60)."\n";
#like(get_curtime("%02d%02d"),qr/\d{2}\d{2}/,'get_curtime with format %02d%02d'); this throws a warning Redundant argument in sprintf at C:\dev\EAI\lib/EAI/DateUtil.pm
like(get_curtime("%02d%02d%02d"),qr/\d{2}\d{2}\d{2}/,'get_curtime with format %02d%02d%02d');
like(get_curtime_HHMM(),qr/\d{4}/,'get_curtime_HHMM');
like(get_curdate_gen("D.M.Y"),qr/\d{2}\.\d{2}\.20\d{2}/,'get_curdate_gen D.M.Y');
like(get_curdate_gen("D/M/Y"),qr/\d{2}\/\d{2}\/20\d{2}/,'get_curdate_gen D/M/Y');
like(get_curdate_gen("YMD"),qr/20\d{6}/,'get_curdate_gen YMD');
like(get_curdate_gen(),qr/20\d{6}/,'get_curdate_gen default = YMD');
like(get_curdate_gen("D-MMM-Y"),qr/\d{2}-\w{3}-20\d{2}/,'get_curdate_gen D-MMM-Y');
is(convertToThousendDecimal(123456789.12),"123.456.789,12",'convertToThousendDecimal comma digit');
is(convertToThousendDecimal(123456789),"123.456.789,0",'convertToThousendDecimal integer');
is(convertToThousendDecimal(0),"0,0",'convertToThousendDecimal 0 with decimal places');
is(convertToThousendDecimal(0,1),"0",'convertToThousendDecimal 0 without decimal places');
is(convertToThousendDecimal(12345.20,1),"12.345",'convertToThousendDecimal decimal without decimal places');
is(convertToThousendDecimal(-12345.20,1),"-12.345",'convertToThousendDecimal negative decimal without decimal places');
is(convertToThousendDecimal(-123456789),"-123.456.789,0",'convertToThousendDecimal negative integer');
is(parseFromDDMMYYYY("01.01.1970"),0,'parseFromDDMMYYYY 01.01.1970');
is(parseFromDDMMYYYY("02.01.1970"),24*60*60,'parseFromDDMMYYYY 02.01.1970');
is(parseFromYYYYMMDD("19700102"),24*60*60,'parseFromYYYYMMDD 19700102');
is((parseFromYYYYMMDD("19700103")-parseFromYYYYMMDD("19700101"))/(24*60*60),2,'diff between 19700103 - 19700101 in days');
is((parseFromYYYYMMDD("20191104")-parseFromDDMMYYYY("01.11.2019"))/(24*60*60),3,'diff between 20191104 - 01.11.2019 in days');
is(parseFromYYYYMMDD("19000100"),undef,'expect error with invalid argument (year >= 1900, 1<=month<=12, 1<=day<=31): returns undef');
is(parseFromDDMMYYYY("01.13.2001"),undef,'expect error with invalid argument (year >= 1900, 1<=month<=12, 1<=day<=31): returns undef');
is(parseFromYYYYMMDD(""),undef,'expect error with invalid argument (year >= 1900, 1<=month<=12, 1<=day<=31): returns undef');
is(parseFromDDMMYYYY("01.01.1801"),undef,'expect error with invalid argument (year >= 1900, 1<=month<=12, 1<=day<=31): returns undef');
is(parseFromYYYYMMDD("20010132"),undef,'expect error with invalid argument (year >= 1900, 1<=month<=12, 1<=day<=31): returns undef');
is(parseFromDDMMYYYY("00.01.1901"),undef,'expect error with invalid argument (year >= 1900, 1<=month<=12, 1<=day<=31): returns undef');
is(convertEpochToYYYYMMDD(parseFromYYYYMMDD("20010131")),"20010131",'convertEpochToYYYYMMDD 20010131');
is(convertEpochToYYYYMMDD(Time::Piece->strptime("20010131","%Y%m%d")),"20010131",'convertEpochToYYYYMMDD Time::Piece 20010131');
is(get_last_day_of_month("20011215"),"20011231",'get_last_day_of_month 20011231');
is(get_last_day_of_month("20010115"),"20010131",'get_last_day_of_month 20010131');
is(get_last_day_of_month("20010215"),"20010228",'get_last_day_of_month 20010228');
is(get_last_day_of_month("20040215"),"20040229",'get_last_day_of_month 20040229');
sub testCalSpecial {
my ($y,$m,$d) = $_[0] =~ /(.{4})(..)(..)/;
return 1 if $y eq "2002" and $m eq "09" and $d eq "08";
return 0;
}
is(addCalendar("TC",{"0101"=>1,"0105"=>1,"2512"=>1,"2612"=>1},{"EM"=>1,"GF"=>1},\&testCalSpecial),1,'added test calendar');
is(is_holiday("TC","20020908"),1,'special holiday testcalendar');
is(is_holiday("TC","20120406"),1,'good friday testcalendar');
is(is_holiday("TC","20120501"),1,'may day testcalendar');
is(addLocaleMonths("FR",["jan","fév","mars","avr","mai","juin","juil","août","sept","oct","nov","déc"]),1,'added french short months');
is(monthsToInt("jan","FR"),"01",'1 from french january');
is(monthsToInt("jan","EN"),"01",'1 from english january');
is(monthsToInt("fév","FR"),"02",'2 from french february');
is(intToMonths(8,"FR"),"août",'french august from 8');
is(monthsToInt("mär","GE"),"03",'3 from german march');
is(intToMonths(3,"GE"),"Mär",'german march from 3');
is(formatDate(2019,3,1,"D.mmm.Y[fr]"),"01.mars.2019",'formatDate D.mmm.Y french');
is(formatDate(2019,3,1,"D.mmm.Y"),"01.Mär.2019",'formatDate D.mmm.Y german');
is(formatTime(make_time("122003")),"12:20:03",'formatTime from make_time("122003")');
is(formatTime(make_time("122003",60)),"12:21:03",'formatTime from make_time("122003",60)');
is(formatTime(make_time("122003",3)),"12:20:06",'formatTime from make_time("122003",3)');
is(formatTime(make_time("122003"),"%02d%02d"),"1220",'formatTime with format %02d%02d from make_time("122003","%02d%02d")');
is(formatTime(make_time("122003"),"%02d%02d%02d%02d"),"00122003",'formatTime from make_time("122003","%02d%02d%02d%02d")');
is(formatTime(make_time("122003"),"%02d%02d%02d%02d%02d"),undef,'formatTime with unsupported format');
is(formatTime(make_time("122003",60),"%02d%02d"),"1221",'formatTime with format %02d%02d from make_time("122003",60)');
like(formatTime(get_curtime_epochs(),"%02d%02d"),qr/\d{2}\d{2}/,'formatTime(get_curtime_epochs(),"%02d%02d")');
is(convertJulianToYYYYMMDD(45582),"20241017",'convertJulianToYYYYMMDD');
is(skipOnDate("B","20120101"),"skipping as \$onlyPassIf eq B and is_weekend(20120101)=1 || is_holiday(AT,20120101)=1",'skipOnDate 1a');
is(skipOnDate("B","20120101","UK"),"skipping as \$onlyPassIf eq B and is_weekend(20120101)=1 || is_holiday(UK,20120101)=1",'skipOnDate 1b');
is(skipOnDate("M1","20120102"),"skipping as \$onlyPassIf eq M1 and curDate (20120102) !~ /\\d{4}\\d{2}01/",'skipOnDate 2');
is(skipOnDate("Q","20120103"),"skipping as \$onlyPassIf eq Q and curDate (20120103) !~ /\\d{4}0102/ and curDate !~ /\\d{4}0401/ and curDate !~ /\\d{4}0701/ and curDate !~ /\\d{4}1001/",'skipOnDate 3');
is(skipOnDate("ML","20120103"),"skipping as \$onlyPassIf eq MLAT and (!is_last_day_of_month(20120103,AT)= or (\$checkCal(=AT) and (is_weekend(20120103)= or is_holiday(AT,20120103)=))))",'skipOnDate 4a');
is(skipOnDate("MLAT","20120103"),"skipping as \$onlyPassIf eq MLAT and (!is_last_day_of_month(20120103,AT)= or (\$checkCal(=AT) and (is_weekend(20120103)= or is_holiday(AT,20120103)=))))",'skipOnDate 4b');
is(skipOnDate("W2","20120103"),"skipping as substr(W2,0,1) eq W and !(weekday(20120103) (3) eq substr(W2,1,1))",'skipOnDate 5');
is(skipOnDate("MW1","20120103"),"skipping as substr(MW1,0,2) eq MW and !(first_weekYYYYMMDD(20120103,substr(MW1,2,1)))",'skipOnDate 6');
done_testing();
( run in 0.517 second using v1.01-cache-2.11-cpan-85f18b9d64f )