Module:Sandbox/DixonD/DateTemplates/testcases

-- Unit tests. Click talk page to run tests.

local p = require('Module:UnitTests');

function p:testJulianDay()

self:preprocess_equals_preprocess_many('{{#invoke:Sandbox/DixonD/DateTemplates|julianDay|', '}}',

'{{JULIANDAY|', '}}', {

{''},

{'aaa'},

-- Errors are expected in most results below (dates not supported by the template due to its use of the PHP "round0" operator on negative dividends).

{'-4800|2|29|23|59|59'},

{'-4800|3|1|0|0|0'},

{'-4800|3|1'},

{'-4800|3|2'},

{'-4799|2|28|23|59|59'},

-- This is the first correct date (epoch: 1 March 4800 BC 12:00:00 UTC) with the JULIANDAY template.

{'-4799|3|1|0|0|0'},

{'-4799|3|1'},

{'-4799|12|31'},

{'-4713|3|1'},

{'-4713|11|24'},

{'-4713|11|25'},

{'-4700|3|1'},

{'0'},

{'0|1|1'},

{'0|12|25'},

{'0|12|30'},

{'0|12|31'},

{'1|1|1'},

{'200|2|28'},

{'200|3|1'},

{'300|2|28'},

{'300|3|1'},

{'325|3|21'},

{'1782|10|14'},

{'1782|10|15'},

{'1858|11|16|12|00|00'},

{'1858|11|17|00|00|00'},

{'1968|05|24|00|00|00'},

{'1995|10|10|00|00|00'},

{'1999|12|31'},

{'2000|1|1'},

{'2000|1|2'},

{'2000|2|1'},

{'2000|3|1'},

{'2000|12|31'},

{'2001|1|1'},

{'2001|12|31'},

{'2002|12|31'},

{'2003|12|31'},

{'2006|2|1'},

{'2006|3|1'},

{'2006|3|31'},

{'2006|4|30|0|0|0'},

{'2006|4|30|01|35|48'},

{'2006|4|30|11|59|60'},

{'2006|4|30|12.0'},

{'2006|4|30'},

{'2006|4|30|23|59|59'},

{'2006|5|1|00|00|00'},

{'2006|5|1|12|00|00'},

{'2006|5|1'},

-- some tests with expressions

{'2000+6|6-1|1'},

});

end

function p:testYearOfJulianDay()

self:preprocess_equals_preprocess_many('{{#invoke:Sandbox/DixonD/DateTemplates|yearOfJulianDay|', '}}',

'{{JULIANDAY.YEAR|', '}}', {

{''},

{'aaa'},

-- Errors are expected in most results below (dates not supported by the template due to its use of the PHP "round0" operator on negative dividends).

{'-32410'}, -- ?

{'-32409'}, -- ?

{'-32044.500011574'}, -- -4800|2|29|23|59|59

{'-32044.5'}, -- -4800|3|1|0|0|0

{'-32044'}, -- -4800|3|1

{'-32043'}, -- -4800|3|2

{'-31680.500011574'}, -- -4799|2|28|23|59|59

{'-31679.5'}, -- -4799|3|1|0|0|0

-- This is the first correct date (epoch: 1 March 4800 BC 12:00:00 UTC) with the JULIANDAY.DAY template.

{'-31679'}, -- -4799|3|1

{'-31374'}, -- -4799|12|31

{'-268'}, -- -4713|3|1

{'0'}, -- -4713|11|24

{'1'}, -- -4713|11|25

{'4480'}, -- -4700|3|1

{'1721060'}, -- 0, 0|1|1

{'1721419'}, -- 0|12|25

{'1721424'}, -- 0|12|30

{'1721425'}, -- 0|12|31

{'1721426'}, -- 1|1|1

{'1794167'}, -- 200|2|28

{'1794168'}, -- 200|3|1

{'1830691'}, -- 300|2|28

{'1830692'}, -- 300|3|1

{'1839843'}, -- 325|3|21

{'2372209'}, -- 1782|10|14

{'2372210'}, -- 1782|10|15

{'2400000'}, -- 1858|11|16|12|00|00

{'2400000.5'}, -- 1858|11|17|00|00|00

{'2440000.5'}, -- 1968|05|24|00|00|00

{'2450000.5'}, -- 1995|10|10|00|00|00

{'2451544'}, -- 1999|12|31

{'2451545'}, -- 2000|1|1

{'2451546'}, -- 2000|1|2

{'2451576'}, -- 2000|2|1

{'2451605'}, -- 2000|3|1

{'2451910'}, -- 2000|12|31

{'2451911'}, -- 2001|1|1

{'2452275'}, -- 2001|12|31

{'2452640'}, -- 2002|12|31

{'2453005'}, -- 2003|12|31

{'2453768'}, -- 2006|2|1

{'2453796'}, -- 2006|3|1

{'2453826'}, -- 2006|3|31

{'2453855.5'}, -- 2006|4|30|0|0|0

{'2453855.5665278'}, -- 2006|4|30|01|35|48

{'2453856'}, -- 2006|4|30|11|59|60, 2006|4|30|12.0, 2006|4|30

{'2453856.4999884'}, -- 2006|4|30|23|59|59

{'2453856.5'}, -- 2006|5|1|00|00|00

{'2453857'}, -- 2006|5|1|12|00|00, 2006|5|1, 2000+6|6-1|1

{'2+2453857-1-1'}, -- same date with expressions

});

end

function p:testMonthOfJulianDay()

self:preprocess_equals_preprocess_many('{{#invoke:Sandbox/DixonD/DateTemplates|monthOfJulianDay|', '}}',

'{{JULIANDAY.MONTH|', '}}', {

{''},

{'aaa'},

-- Errors are expected in most results below (dates not supported by the template due to its use of the PHP "round0" operator on negative dividends).

{'-32410'}, -- ?

{'-32409'}, -- ?

{'-32044.500011574'}, -- -4800|2|29|23|59|59

{'-32044.5'}, -- -4800|3|1|0|0|0

{'-32044'}, -- -4800|3|1

{'-32043'}, -- -4800|3|2

{'-31680.500011574'}, -- -4799|2|28|23|59|59

{'-31679.5'}, -- -4799|3|1|0|0|0

-- This is the first correct date (epoch: 1 March 4800 BC 12:00:00 UTC) with the JULIANDAY.DAY template.

{'-31679'}, -- -4799|3|1

{'-31374'}, -- -4799|12|31

{'-268'}, -- -4713|3|1

{'0'}, -- -4713|11|24

{'1'}, -- -4713|11|25

{'4480'}, -- -4700|3|1

{'1721060'}, -- 0, 0|1|1

{'1721419'}, -- 0|12|25

{'1721424'}, -- 0|12|30

{'1721425'}, -- 0|12|31

{'1721426'}, -- 1|1|1

{'1794167'}, -- 200|2|28

{'1794168'}, -- 200|3|1

{'1830691'}, -- 300|2|28

{'1830692'}, -- 300|3|1

{'1839843'}, -- 325|3|21

{'2372209'}, -- 1782|10|14

{'2372210'}, -- 1782|10|15

{'2400000'}, -- 1858|11|16|12|00|00

{'2400000.5'}, -- 1858|11|17|00|00|00

{'2440000.5'}, -- 1968|05|24|00|00|00

{'2450000.5'}, -- 1995|10|10|00|00|00

{'2451544'}, -- 1999|12|31

{'2451545'}, -- 2000|1|1

{'2451546'}, -- 2000|1|2

{'2451576'}, -- 2000|2|1

{'2451605'}, -- 2000|3|1

{'2451910'}, -- 2000|12|31

{'2451911'}, -- 2001|1|1

{'2452275'}, -- 2001|12|31

{'2452640'}, -- 2002|12|31

{'2453005'}, -- 2003|12|31

{'2453768'}, -- 2006|2|1

{'2453796'}, -- 2006|3|1

{'2453826'}, -- 2006|3|31

{'2453855.5'}, -- 2006|4|30|0|0|0

{'2453855.5665278'}, -- 2006|4|30|01|35|48

{'2453856'}, -- 2006|4|30|11|59|60, 2006|4|30|12.0, 2006|4|30

{'2453856.4999884'}, -- 2006|4|30|23|59|59

{'2453856.5'}, -- 2006|5|1|00|00|00

{'2453857'}, -- 2006|5|1|12|00|00, 2006|5|1, 2000+6|6-1|1

{'2+2453857-1-1'}, -- same date with expressions

});

end

function p:testDayOfJulianDay()

self:preprocess_equals_preprocess_many('{{#invoke:Sandbox/DixonD/DateTemplates|dayOfJulianDay|', '}}',

'{{JULIANDAY.DAY|', '}}', {

{''},

{'aaa'},

-- Errors are expected in most results below (dates not supported by the template due to its use of the PHP "round0" operator on negative dividends).

{'-32410'}, -- ?

{'-32409'}, -- ?

{'-32044.500011574'}, -- -4800|2|29|23|59|59

{'-32044.5'}, -- -4800|3|1|0|0|0

{'-32044'}, -- -4800|3|1

{'-32043'}, -- -4800|3|2

{'-31680.500011574'}, -- -4799|2|28|23|59|59

{'-31679.5'}, -- -4799|3|1|0|0|0

-- This is the first correct date (epoch: 1 March 4800 BC 12:00:00 UTC) with the JULIANDAY.DAY template.

{'-31679'}, -- -4799|3|1

{'-31374'}, -- -4799|12|31

{'-268'}, -- -4713|3|1

{'0'}, -- -4713|11|24

{'1'}, -- -4713|11|25

{'4480'}, -- -4700|3|1

{'1721060'}, -- 0, 0|1|1

{'1721419'}, -- 0|12|25

{'1721424'}, -- 0|12|30

{'1721425'}, -- 0|12|31

{'1721426'}, -- 1|1|1

{'1794167'}, -- 200|2|28

{'1794168'}, -- 200|3|1

{'1830691'}, -- 300|2|28

{'1830692'}, -- 300|3|1

{'1839843'}, -- 325|3|21

{'2372209'}, -- 1782|10|14

{'2372210'}, -- 1782|10|15

{'2400000'}, -- 1858|11|16|12|00|00

{'2400000.5'}, -- 1858|11|17|00|00|00

{'2440000.5'}, -- 1968|05|24|00|00|00

{'2450000.5'}, -- 1995|10|10|00|00|00

{'2451544'}, -- 1999|12|31

{'2451545'}, -- 2000|1|1

{'2451546'}, -- 2000|1|2

{'2451576'}, -- 2000|2|1

{'2451605'}, -- 2000|3|1

{'2451910'}, -- 2000|12|31

{'2451911'}, -- 2001|1|1

{'2452275'}, -- 2001|12|31

{'2452640'}, -- 2002|12|31

{'2453005'}, -- 2003|12|31

{'2453768'}, -- 2006|2|1

{'2453796'}, -- 2006|3|1

{'2453826'}, -- 2006|3|31

{'2453855.5'}, -- 2006|4|30|0|0|0

{'2453855.5665278'}, -- 2006|4|30|01|35|48

{'2453856'}, -- 2006|4|30|11|59|60, 2006|4|30|12.0, 2006|4|30

{'2453856.4999884'}, -- 2006|4|30|23|59|59

{'2453856.5'}, -- 2006|5|1|00|00|00

{'2453857'}, -- 2006|5|1|12|00|00, 2006|5|1, 2000+6|6-1|1

{'2+2453857-1-1'}, -- same date with expressions

});

end

function p:testJulianDayJulian()

self:preprocess_equals_preprocess_many('{{#invoke:Sandbox/DixonD/DateTemplates|julianDayJulian|', '}}',

'{{JULIANDAY.JULIAN|', '}}', {

{''},

{'aaa'},

-- Errors are expected in most results below (dates not supported by the template due to its use of the PHP "round0" operator on negative dividends).

{'-4800|2|29|23|59|59'},

{'-4800|3|1|0|0|0'},

{'-4800|3|1'},

{'-4800|3|2'},

{'-4799|2|28|23|59|59'},

-- This is the first correct date (epoch: 1 March 4800 BC 12:00:00 UTC) with the JULIANDAY template.

{'-4799|3|1|0|0|0'},

{'-4799|3|1'},

{'-4799|12|31'},

{'-4713|3|1'},

{'-4713|11|24'},

{'-4713|11|25'},

{'-4700|3|1'},

{'0'},

{'0|1|1'},

{'0|12|25'},

{'0|12|30'},

{'0|12|31'},

{'1|1|1'},

{'200|2|28'},

{'200|3|1'},

{'300|2|28'},

{'300|3|1'},

{'325|3|21'},

{'1782|10|14'},

{'1782|10|15'},

{'1858|11|16|12|00|00'},

{'1858|11|17|00|00|00'},

{'1968|05|24|00|00|00'},

{'1995|10|10|00|00|00'},

{'1999|12|31'},

{'2000|1|1'},

{'2000|1|2'},

{'2000|2|1'},

{'2000|3|1'},

{'2000|12|31'},

{'2001|1|1'},

{'2001|12|31'},

{'2002|12|31'},

{'2003|12|31'},

{'2006|2|1'},

{'2006|3|1'},

{'2006|3|31'},

{'2006|4|30|0|0|0'},

{'2006|4|30|01|35|48'},

{'2006|4|30|11|59|60'},

{'2006|4|30|12.0'},

{'2006|4|30'},

{'2006|4|30|23|59|59'},

{'2006|5|1|00|00|00'},

{'2006|5|1|12|00|00'},

{'2006|5|1'},

-- some tests with expressions

{'2000+6|6-1|1'},

});

end

function p:testGregorianSerialDate()

self:preprocess_equals_preprocess_many('{{#invoke:Sandbox/DixonD/DateTemplates|gregorianSerialDate|', '}}',

'{{Gregorian serial date|', '}}', {

{''},

{'year=aaa'},

{'year=2006|month=bbb'},

{'year=2006|month=2|day=ccc'},

-- Errors are expected in most results below (dates not supported by the template due to its use of the PHP "round0" operator on negative dividends).

{'year=-4800|month=2|day=29'},

{'year=-470|month=3|day=1'},

{'year=0'},

{'year=0|month=1|day=1'},

{'year=0|month=12|day=25'},

{'year=0|month=12|day=30'},

{'year=0|month=12|day=31'},

-- This is the first correct date (epoch: 1 March 4800 BC 12:00:00 UTC) with the JULIANDAY template.

{'year=1|month=1|day=1'},

{'year=200|month=2|day=28'},

{'year=200|month=3|day=1'},

{'year=300|month=2|day=28'},

{'year=300|month=3|day=1'},

{'year=325|month=3|day=21'},

{'year=1782|month=10|day=14'},

{'year=1782|month=10|day=15'},

{'year=1858|month=11|day=16'},

{'year=1858|month=11|day=17'},

{'year=1968|month=05|day=24'},

{'year=1995|month=10|day=10'},

{'year=1999|month=12|day=31'},

{'year=2000|month=1|day=1'},

{'year=2000|month=1|day=2'},

{'year=2000|month=2|day=1'},

{'year=2000|month=3|day=1'},

{'year=2000|month=12|day=31'},

{'year=2001|month=1|day=1'},

{'year=2001|month=12|day=31'},

{'year=2002|month=12|day=31'},

{'year=2003|month=12|day=31'},

{'year=2006'},

{'year=2006|month=2|day=1'},

{'year=2006|month=3|day=1'},

{'year=2006|month=3|day=31'},

{'year=2006|month=4|day=30'},

{'year=2006|month=5|day=1'},

{'year=2006|month=5'},

-- some tests with expressions

{'year=2000+6|month=6-1|day=1'},

});

end

return p;