Unit tests for modified Date functions

This commit is contained in:
MarkBaker 2016-08-14 15:35:43 +01:00
parent 91306d0c31
commit f0e167c182
3 changed files with 62 additions and 60 deletions

View File

@ -158,9 +158,10 @@ class Date
/** /**
* Convert a MS serialized datetime value from Excel to a PHP Date/Time object * Convert a MS serialized datetime value from Excel to a PHP Date/Time object
* *
* @param integer|float $dateValue Excel date/time value * @param integer|float $dateValue MS Excel serialized date/time value
* @param \DateTimeZone|string|null $timezone The timezone to assume for the Excel timestamp, * @param \DateTimeZone|string|null $timezone The timezone to assume for the Excel timestamp,
* if you don't want to treat it as a UTC value * if you don't want to treat it as a UTC value
* Use the default (UST) unless you absolutely need a conversion
* @return \DateTime PHP date/time object * @return \DateTime PHP date/time object
* @throws \Exception * @throws \Exception
*/ */
@ -195,9 +196,10 @@ class Date
/** /**
* Convert a MS serialized datetime value from Excel to a unix timestamp * Convert a MS serialized datetime value from Excel to a unix timestamp
* *
* @param integer|float $dateValue Excel date/time value * @param integer|float $dateValue MS Excel serialized date/time value
* @param \DateTimeZone|string|null $timezone The timezone to assume for the Excel timestamp, * @param \DateTimeZone|string|null $timezone The timezone to assume for the Excel timestamp,
* if you don't want to treat it as a UTC value * if you don't want to treat it as a UTC value
* Use the default (UST) unless you absolutely need a conversion
* @return integer Unix timetamp for this date/time * @return integer Unix timetamp for this date/time
* @throws \Exception * @throws \Exception
*/ */

View File

@ -2,26 +2,26 @@
// Excel DateTimeStamp Timezone Result Comments // Excel DateTimeStamp Timezone Result Comments
return [ return [
[ 22269, 'America/New_York', -285102000 ], // 19-Dec-1960 00:00:00 UST [ 22269, 'America/New_York', -285102000 ], // 19-Dec-1960 00:00:00 EST => 19-Dec-1960 05:00:00 UTC
[ 25569, 'America/New_York', 18000 ], // PHP Base Date 01-Jan-1970 00:00:00 UST [ 25569, 'America/New_York', 18000 ], // 01-Jan-1970 00:00:00 EST => 01-Jan-1970 05:00:00 UTC PHP Base Date
[ 30292, 'America/New_York', 408085200 ], // 07-Dec-1982 00:00:00 UST [ 30292, 'America/New_York', 408085200 ], // 07-Dec-1982 00:00:00 EST => 07-Dec-1982 05:00:00 UTC
[ 39611, 'America/New_York', 1213243200 ], // 12-Jun-2008 00:00:00 UST [ 39611, 'America/New_York', 1213243200 ], // 12-Jun-2008 00:00:00 EDT => 12-Jun-2008 04:00:00 UTC
[ 50424, 'America/New_York', 2147490000 ], // PHP 32-bit Latest Date 19-Jan-2038 00:00:00 UST [ 50424, 'America/New_York', 2147490000 ], // 19-Jan-2038 00:00:00 EST => 19-Jan-2038 05:00:00 UTC PHP 32-bit Latest Date
[ 22345.56789, 'America/New_York', -278522534 ], // 18-May-1903 13:37:46 UST [ 22345.56789, 'America/New_York', -278486534 ], // 05-Mar-1961 13:37:46 EST => 05-Mar-1961 18:37:46 UTC
[ 22345.6789, 'America/New_York', -278512943 ], // 18-Oct-1933 16:17:37 UST [ 22345.6789, 'America/New_York', -278476943 ], // 05-Mar-1961 16:17:37 EST => 05-Mar-1961 21:17:37 UTC
[ 0.5, 'America/New_York', 25200 ], // 12:00:00 UST [ 0.5, 'America/New_York', 61200 ], // 12:00:00 EST => 17:00:00 UTC
[ 0.75, 'America/New_York', 46800 ], // 18:00.00 UST [ 0.75, 'America/New_York', 82800 ], // 18:00.00 EST => 23:00:00 UTC
[ 0.12345, 'America/New_York', -7334 ], // 02:57:46 UST [ 0.12345, 'America/New_York', 28666 ], // 02:57:46 EST => 07:57:46 UTC
[ 41215, 'America/New_York', 1351800000 ], // 02-Nov-2012 00:00:00 UST [ 41215, 'America/New_York', 1351828800 ], // 02-Nov-2012 00:00:00 EDT => 02-Nov-2012 04:00:00 UTC
[ 22269, 'Pacific/Auckland', -285076800 ], // 19-Dec-1960 00:00:00 UST [ 22269, 'Pacific/Auckland', -285163200 ], // 19-Dec-1960 00:00:00 NZST => 18-Dec-1960 12:00:00 UTC
[ 25569, 'Pacific/Auckland', 43200 ], // PHP Base Date 01-Jan-1970 00:00:00 UST [ 25569, 'Pacific/Auckland', -43200 ], // 01-Jan-1970 00:00:00 NZST => 31-Dec-1969 12:00:00 UTC PHP Base Date
[ 30292, 'Pacific/Auckland', 408114000 ], // 07-Dec-1982 00:00:00 UST [ 30292, 'Pacific/Auckland', 408020400 ], // 07-Dec-1982 00:00:00 NZDT => 06-Dec-1982 11:00:00 UTC
[ 39611, 'Pacific/Auckland', 1213272000 ], // 12-Jun-2008 00:00:00 UST [ 39611, 'Pacific/Auckland', 1213185600 ], // 12-Jun-2008 00:00:00 NZST => 11-Jun-2008 12:00:00 UTC
[ 50423.5, 'Pacific/Auckland', 2147475600 ], // PHP 32-bit Latest Date 19-Jan-2038 00:00:00 UST [ 50423.5, 'Pacific/Auckland', 2147382000 ], // 18-Jan-2038 12:00:00 NZDT => 17-Jan-2038 23:00:00 UTC PHP 32-bit Latest Date
[ 22345.56789, 'Pacific/Auckland', -278461334 ], // 18-May-1903 13:37:46 UST [ 22345.56789, 'Pacific/Auckland', -278547734 ], // 05-Mar-1961 13:37:46 NZST => 05-Mar-1961 01:37:46 UTC
[ 22345.6789, 'Pacific/Auckland', -278451743 ], // 18-Oct-1933 16:17:37 UST [ 22345.6789, 'Pacific/Auckland', -278538143 ], // 05-Mar-1961 16:17:37 NZST => 05-Mar-1961 04:17:37 UTC
[ 0.5, 'Pacific/Auckland', 90000 ], // 12:00:00 UST [ 0.5, 'Pacific/Auckland', 0 ], // 12:00:00 NZST => 00:00:00 UTC
[ 0.75, 'Pacific/Auckland', 111600 ], // 18:00.00 UST [ 0.75, 'Pacific/Auckland', 21600 ], // 18:00.00 NZST => 06:00:00 UTC
[ 0.12345, 'Pacific/Auckland', 57466 ], // 02:57:46 UST [ 0.12345, 'Pacific/Auckland', -32534 ], // 02:57:46 NZST => 14:57:46 UTC
[ 41215, 'Pacific/Auckland', 1351861200 ], // 02-Nov-2012 00:00:00 UST [ 41215, 'Pacific/Auckland', 1351767600 ], // 02-Nov-2012 00:00:00 NZDT => 01-Nov-2012 11:00:00 UTC
]; ];

View File

@ -2,40 +2,40 @@
// Excel Format Code Result // Excel Format Code Result
return [ return [
[ "General", FALSE ], [ 'General', FALSE ],
[ "@", FALSE ], [ '@', FALSE ],
[ "0", FALSE ], [ '0', FALSE ],
[ "0.00", FALSE ], [ '0.00', FALSE ],
[ "#,##0.00", FALSE ], [ '#,##0.00', FALSE ],
[ "#,##0.00_-", FALSE ], [ '#,##0.00_-', FALSE ],
[ "0%", FALSE ], [ '0%', FALSE ],
[ "0.00%", FALSE ], [ '0.00%', FALSE ],
[ "yyyy-mm-dd", TRUE ], [ 'yyyy-mm-dd', TRUE ],
[ "yy-mm-dd", TRUE ], [ 'yy-mm-dd', TRUE ],
[ "dd/mm/yy", TRUE ], [ 'dd/mm/yy', TRUE ],
[ "d/m/y", TRUE ], [ 'd/m/y', TRUE ],
[ "d-m-y", TRUE ], [ 'd-m-y', TRUE ],
[ "d-m", TRUE ], [ 'd-m', TRUE ],
[ "m-y", TRUE ], [ 'm-y', TRUE ],
[ "mm-dd-yy", TRUE ], [ 'mm-dd-yy', TRUE ],
[ "d-mmm-yy", TRUE ], [ 'd-mmm-yy', TRUE ],
[ "d-mmm", TRUE ], [ 'd-mmm', TRUE ],
[ "mmm-yy", TRUE ], [ 'mmm-yy', TRUE ],
[ "m/d/yy h:mm", TRUE ], [ 'm/d/yy h:mm', TRUE ],
[ "d/m/y h:mm", TRUE ], [ 'd/m/y h:mm', TRUE ],
[ "h:mm AM/PM", TRUE ], [ 'h:mm AM/PM', TRUE ],
[ "h:mm:ss AM/PM", TRUE ], [ 'h:mm:ss AM/PM', TRUE ],
[ "h:mm", TRUE ], [ 'h:mm', TRUE ],
[ "h:mm:ss", TRUE ], [ 'h:mm:ss', TRUE ],
[ "mm:ss", TRUE ], [ 'mm:ss', TRUE ],
[ "h:mm:ss", TRUE ], [ 'h:mm:ss', TRUE ],
[ "i:s.S", TRUE ], [ 'i:s.S', TRUE ],
[ "h:mm:ss;@", TRUE ], [ 'h:mm:ss;@', TRUE ],
[ "yy/mm/dd;@", TRUE ], [ 'yy/mm/dd;@', TRUE ],
[ "\"$\"#,##0.00_-", FALSE ], [ '"$" #,##0.00_-', FALSE ],
[ "$#,##0_-", FALSE ], [ '$#,##0_-', FALSE ],
[ "[$EUR ]#,##0.00_-", FALSE ], [ '[$EUR ]#,##0.00_-', FALSE ],
[ "_[$EUR ]#,##0.00_-", FALSE ], [ '_[$EUR ]#,##0.00_-', FALSE ],
[ "[Green]#,##0.00;[Red]#,##0.00_-", FALSE ], [ '[Green]#,##0.00;[Red]#,##0.00_-', FALSE ],
[ "#,##0.00 \"dollars\"", FALSE ], [ '#,##0.00 "dollars"', FALSE ],
]; ];