Module:Date/testcases

local date = require("Dev:Date") local ScribuntoUnit = require("Module:ScribuntoUnit") local suite = ScribuntoUnit:new

function suite:date_parsing self:assertTrue( date("Jul 27 2006 03:56:28 +2:00") == date(2006,07,27,1,56,28)) self:assertTrue(date("Jul 27 2006 -75 ") == date(2006,07,27,1,15,0)) self:assertTrue(date("Jul 27 2006 -115") == date(2006,07,27,1,15,0)) self:assertTrue(date("Jul 27 2006 +10 ") == date(2006,07,26,14,0,0)) self:assertTrue(date("Jul 27 2006 +2 ") == date(2006,07,26,22,0,0))

-- Standard timezone GMT, UTC, EST, EDT, CST, CDT, MST, MDT, PST, PDT are supported. self:assertTrue(date("Jul 27 2006 GMT") == date(2006,07,27,0,0,0)) self:assertTrue(date("Jul 27 2006 UTC") == date(2006,07,27,0,0,0)) self:assertTrue(date("Jul 27 2006 EST") == date(2006,07,27,5,0,0)) self:assertTrue(date("Jul 27 2006 EDT") == date(2006,07,27,4,0,0)) self:assertTrue(date("Jul 27 2006 CST") == date(2006,07,27,6,0,0)) self:assertTrue(date("Jul 27 2006 CDT") == date(2006,07,27,5,0,0)) self:assertTrue(date("Jul 27 2006 MST") == date(2006,07,27,7,0,0)) self:assertTrue(date("Jul 27 2006 MDT") == date(2006,07,27,6,0,0)) self:assertTrue(date("Jul 27 2006 PST") == date(2006,07,27,8,0,0)) self:assertTrue(date("Jul 27 2006 PDT") == date(2006,07,27,7,0,0)) -- Date Format. Short dates can use either a "/" or "-" date separator, -- but must follow the month/day/year format self:assertTrue(date("02-03-04")==date(1904,02,03)) self:assertTrue(date("12/25/98")==date(1998,12,25)) -- Long dates of the form "July 10 1995" can be given with the year, month, -- and day in any order, and the year in 2-digit or 4-digit form. If you use -- the 2-digit form, the year must be greater than or equal to 70. self:assertTrue(date("Feb-03-04")==date(1904,02,03)) self:assertTrue(date("December 25 1998")==date(1998,12,25)) -- Follow the year with BC or BCE to indicate that the year is before common era. self:assertTrue(date("Feb 3 0003 BC")==date(-2,02,03)) self:assertTrue(date("December 25 0001 BC")==date(0,12,25))

-- Supported ISO 8601 Formats. -- YYYY-MM-DDwhere YYYY is the year, MM is the month of the year, and DD is the -- day of the month. self:assertTrue(date("2000-12-31")==date(2000,12,31)) self:assertTrue(date(" 20001231 ")==date(2000,12,31)) -- Compact version -- YYYY-DDDwhere YYYY is the year, DDD is the day of the year. self:assertTrue(date("1995-035")==date(1995,02,04)) self:assertTrue(date("1995035 ")==date(1995,02,04)) -- Compact version -- YYYY-WDD-Dwhere YYYY is the year, DD is the week of the year, D is the day of    -- the week. self:assertTrue(date("1997-W01-1")==date(1996,12,30)) self:assertTrue(date(" 1997W017")==date(1997,01,05)) -- Compact version -- DATE HH:MM:SS.SSSWhere DATE is the date format discuss above, HH is the hour, -- MM is the miute, SS.SSS is the seconds (fraction is optional). self:assertTrue(date("1995-02-04 24:00:51.536")==date(1995,2,5,0,0,51.536)) self:assertTrue(date("1976-W01-1 12:12:12.123")==date(1975,12,29,12,12,12.123)) self:assertTrue(date("1995-035 23:59:59.99999")==date(1995,02,04,23,59,59.99999)) -- Compact version separated by latin capital letter T   self:assertTrue(date("  19950205T000051.536  ")==date(1995,2,5,0,0,51.536)) self:assertTrue(date(" 1976W011T121212.123  ")==date(1975,12,29,12,12,12.123)) self:assertTrue(date(" 1995035T235959.99999 ")==date(1995,02,04,23,59,59.99999)) -- DATE TIME +HH:MM, DATE TIME -HHMM, DATE TIME Z,Where DATE and TIME is the date -- and time format discuss above. First character is a sign "+" (east of UTC) or "-" -- (west of UTC). HH and MM is Hours and minutes offset. The Z stands for the zero offset. self:assertTrue(date("1976-W01-1 12:00Z    ")==date(1975,12,29,12)) self:assertTrue(date("1976-W01-1 13:00+01:00")==date(1975,12,29,12)) self:assertTrue(date("1976-W01-1 0700-0500 ")==date(1975,12,29,12))

local a = date(2006, 8, 13)  self:assertTrue(a == date("Sun Aug 13 2006")) local b = date("Jun 13 1999") self:assertTrue(b == date(1999, 6, 13)) local c = date(1234483200)   self:assertTrue(c == date("Feb 13 2009")) local d = date({year=2009, month=11, day=13, min=6}) self:assertTrue(d == date("Nov 13 2009 00:06:00")) local e = date             self:assertTrue(e) end

return suite