diff --git a/README.md b/README.md
index 2b0bbfd..8c6f09c 100644
--- a/README.md
+++ b/README.md
@@ -23,6 +23,6 @@ Tests are located in the `spec` directory and can be run using [busted](http://o
##Changes:
-- v2.1.1 fix for '>=' operator, added test suite, added Travis CI, license MIT
+- v2.1.1 fix for '>=' operator [#3](https://github.com/Tieske/date/pull/3), added test suite, added Travis CI, license MIT
- v2.1 Lua 5.2 support. Global 'date' will no longer be set.
- v2.0 original by Jas Latrix
\ No newline at end of file
diff --git a/date-2.1.0-2.rockspec b/date-2.1.1-1.rockspec
similarity index 100%
rename from date-2.1.0-2.rockspec
rename to date-2.1.1-1.rockspec
diff --git a/date.lua b/date.lua
index 998947b..f035ab8 100644
--- a/date.lua
+++ b/date.lua
@@ -1,8 +1,9 @@
---------------------------------------------------------------------------------------
-- Module for date and time calculations
--
--- Version 2.1.1, Copyright (C) 2006, by Jas Latrix (jastejada@yahoo.com)
--- Copyright (C) 2013 update to Lua 5.2 by Thijs Schreijer
+-- Version 2.1.1
+-- Copyright (C) 2006, by Jas Latrix (jastejada@yahoo.com)
+-- Copyright (C) 2013-2014, by Thijs Schreijer
-- Licensed under MIT, http://opensource.org/licenses/MIT
--[[ CONSTANTS ]]--
diff --git a/doc/index.html b/doc/index.html
index 967ab6f..fb0f59b 100644
--- a/doc/index.html
+++ b/doc/index.html
@@ -1,22 +1,134 @@
-
LuaDate is a Lua module for date and time calculation and retrieval using the Gregorian Date system.
-
- To Load the module call local date = require"date" in your script.
- Make sure Lua can find the source file date.lua.
- No global table date will be created.
- Use the metamethod __call to construct a dateObject see example below:
-
LuaDate is a Lua module for date and time
+ calculation and retrieval using the Gregorian Date system.
+
+
To Load the module call local date = require"date" in
+ your script. Make sure Lua can find the source file date.lua. No global table date
+ will be created. Use the metamethod __call to construct
+ a dateObject see example below:
+
local date = require "date"
-- prints all FRIDAY the 13TH dates between year 2000 and 2010
for i = 2000, 2010 do
- -- year jan 1
- x = date(i, 1, 1)
- -- from january to december
- for j = 1, 12 do
- -- set date to 13, check if friday
- if x:setmonth(j, 13):getweekday() == 6 then
- print(x:fmt("%A, %B %d %Y"))
- end
- end
+ -- year jan 1
+ x = date(i, 1, 1)
+ -- from january to december
+ for j = 1, 12 do
+ -- set date to 13, check if friday
+ if x:setmonth(j, 13):getweekday() == 6 then
+ print(x:fmt("%A, %B %d %Y"))
+ end
+ end
end
--- OUTPUT ---
@@ -38,89 +150,630 @@ end
--> Friday, March 13 2009
--> Friday, November 13 2009
--> Friday, August 13 2010
-
-
2. Limits
This module does not recognize leap seconds.
It assumes that a day has exactly 24*60*60 seconds.
The Lua number must be a double C data type
This module supports dates that are greater than
- Mon Jan 01 1000000 BCE 00:00:00 and less than
- Mon Jan 01 1000001 00:00:00.
- This module also supports local time. Local Time is;
-
Local = UTC + bias
- The bias is time zone offset plus the daylight savings if in effect.
- The bias is retrieve using the Lua function os.date and os.time.
- It assumes that the Lua function os.time returns the number of seconds since the start time (called "epoch").
- If the time value is outside the allowable range of times, usually
- Jan 01 1970 00:00:00 to
- Jan 19 2038 03:14:07 the bias will be retrieve
- using the equivalent year inside the allowable range. Two years are considered to
- equivalent if they have the same leap year ness and starting weekday.
-
- Parsable date value is a lua value that can be converted to a dateObject.
- This value must be num_time or tbl_date or str_date or bool_now argument
- describe in the date library __call method.
-
5. Parsable month value
- If a function needs a month value it must be a string or a number.
- If the value is a string, it must be the name of the month full or abbreviated.
- If the value is a number, that number must be 1-12 (January-December). see table below
-
Table 1.
Index
Abbreviation
Full Name
1
Jan
January
2
Feb
February
3
Mar
March
4
Apr
April
5
May
May
6
Jun
June
7
Jul
July
8
Aug
August
9
Sep
September
10
Oct
October
11
Nov
November
12
Dec
December
- If the value does not represent month, that is equivalent to passing a nil value.
-
This module also supports local time. Local Time is;
+
+
+
+ Local = UTC + bias
+
+
The bias is time zone offset plus the
+ daylight savings if in effect. The bias is
+ retrieve using the Lua function os.date and os.time. It assumes that the Lua function os.timereturns the number of seconds
+ since the start time (called "epoch"). If the time value is outside
+ the allowable range of times, usually Jan 01 1970
+ 00:00:00 to Jan 19 2038 03:14:07 the bias will
+ be retrieve using the equivalent year inside the allowable range. Two years are
+ considered to equivalent if they have the same leap year ness and starting weekday.
+
+
Parsable date value is a lua value that can be converted to a dateObject. This value must be num_time
+ or tbl_date or str_date or
+ bool_now argument describe in the date library __call method.
+
+
+
+
+
+
+
5. Parsable month value
+
+
+
If a function needs a month value it must be a string or a number. If the
+ value is a string, it must be the name of the month
+ full or abbreviated. If the value is a number, that
+ number must be 1-12 (January-December). see table below
+
+
+
+
+
Table 1.
+
+
+
+
+
+
+
+
+
+
+
+
Index
+
+
Abbreviation
+
+
Full Name
+
+
+
+
+
+
1
+
+
Jan
+
+
January
+
+
+
+
2
+
+
Feb
+
+
February
+
+
+
+
3
+
+
Mar
+
+
March
+
+
+
+
4
+
+
Apr
+
+
April
+
+
+
+
5
+
+
May
+
+
May
+
+
+
+
6
+
+
Jun
+
+
June
+
+
+
+
7
+
+
Jul
+
+
July
+
+
+
+
8
+
+
Aug
+
+
August
+
+
+
+
9
+
+
Sep
+
+
September
+
+
+
+
10
+
+
Oct
+
+
October
+
+
+
+
11
+
+
Nov
+
+
November
+
+
+
+
12
+
+
Dec
+
+
December
+
+
+
+
+
+
+
If the value does not represent month, that is equivalent to passing a nil
+ value.
true if var_year leap year.
- false if var_year not leap year.
-
Remarks
- A leap year in the Gregorian calendar is defined as a year that is evenly
- divisible by four, except if it is divisible by 100; however, years that are
- divisible by 400 are leap years.
-
Example
+
+
+
+
+
+
+
+
+
+
+
6.1.3. isleapyear
+
+
+
Check if a number
+ or dateObject is a leapyear.
+
+
true if var_year leap year. false
+ if var_year not leap year.
+
+
Remarks
+
+
A leap year in the Gregorian calendar is defined as a year that is
+ evenly divisible by four, except if it is divisible by 100; however, years
+ that are divisible by 400 are leap years.
+
+
Example
+
+
+
d = date(1776, 1, 1)
assert(date.isleapyear(d))
assert(date.isleapyear(d:getyear()))
assert(date.isleapyear(1776))
-
day - an integer, the day of month from 1 to 31. Required if year and month is given
hour - a number, hours value, from 0 to 23, indicating the number of hours since midnight. (default = 0)
min - a number, minutes value, from 0 to 59. (default = 0)
sec - a number, seconds value, from 0 to 59. (default = 0)
- Time (hour or min or sec or msec) must be supplied if
- date (year and month and day) is not given, vice versa.
-
str_date
Required string value. It must have number/words representing date and/or time.
- Use commas and spaces as delimiters.
- Strings enclosed by parenthesis is treated as a comment and is ignored, these parentheses may be nested.
- The stated day of the week is ignored whether its correct or not.
- A string containing an invalid date is an error.
- For example, a string containing two years or two months is an error.
- Time must be supplied if date is not given, vice versa.
-
Time Format.
- Hours, minutes, and seconds are separated by colons, although all need not be specified. "10:", "10:11", and "10:11:12" are all valid.
- If the 24-hour clock is used, it is an error to specify "PM" for times later than 12 noon. For example, "23:15 PM" is an error.
-
Time Zone Format.
- First character is a sign "+" (east of UTC) or "-" (west of UTC).
- Hours and minutes offset are separated by colons:
-
day - an integer,
+ the day of month from 1 to 31. Required if year and month is
+ given
+
+
hour - a number,
+ hours value, from 0 to 23, indicating the number of hours since
+ midnight. (default = 0)
+
+
min - a number,
+ minutes value, from 0 to 59. (default = 0)
+
+
sec - a number,
+ seconds value, from 0 to 59. (default = 0)
+
+
Time (hour or min or sec or
+ msec) must be supplied if date (year and month and day) is not
+ given, vice versa.
+
+
+
+
+
+
+
str_date
+
+
+ Required string value. It must have
+ number/words representing date and/or time. Use commas and spaces
+ as delimiters. Strings enclosed by parenthesis is treated as a
+ comment and is ignored, these parentheses may be nested. The stated
+ day of the week is ignored whether its correct or not. A string
+ containing an invalid date is an error. For example, a string
+ containing two years or two months is an error. Time must be
+ supplied if date is not given, vice versa.
+
+
Time Format. Hours, minutes, and seconds are
+ separated by colons, although all need not be specified. "10:",
+ "10:11", and "10:11:12" are all valid. If the 24-hour clock is
+ used, it is an error to specify "PM" for times later than 12 noon.
+ For example, "23:15 PM" is an error.
+
+
Time Zone Format. First character is a sign "+"
+ (east of UTC) or "-" (west of UTC). Hours and minutes offset are
+ separated by colons:
- Another format is [sign][number]
- If [number] is less than 24, it is the offset in hours e.g. "-10" = -10 hours.
- Otherwise it is the offset in houndred hours e.g. "+75" = "+115" = +1.25 hours.
-
+
+
+
Another format is [sign][number]
+ If [number] is less than 24, it is
+ the offset in hours e.g. "-10" = -10 hours. Otherwise it is the
+ offset in houndred hours e.g. "+75" = "+115" = +1.25 hours.
- 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.
-
+
+
+
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.
-Where DATE and TIME is the dateand 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.
-
+
+
+
+
DATETIME +HH:MM, DATE
+ TIME -HHMM,
+ DATETIME Z,
+
+
+ Where DATE and
+ TIME is the dateand
+ 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.
+
Required boolean value.
- if bool_now is false it returns the current local date and time.
- if bool_now is true it returns the current UTC date and time.
-
Required boolean value. if
+ bool_now is false it returns the current local date and time.
+ if bool_now is true it returns the current UTC date and
+ time.
a = date(2006, 8, 13) assert(a == date("Sun Aug 13 2006"))
b = date("Jun 13 1999") assert(b == date(1999, 6, 13))
c = date(1234483200) assert(c == date("Feb 13 2009"))
d = date({year=2009, month=11, day=13, min=6})
- assert(d == date("Nov 13 2009 00:06:00"))
+ assert(d == date("Nov 13 2009 00:06:00"))
e = date() assert(e)
-
7. dateObject
dateObject is a table containing date and time value.
- It has a metatable for manipulation and retrieval of dates and times.
- Use the __call method of date to construct a dateObject.
+
+
+
+
+
+
+
-
7.1. How Date and Time are stored in dateObject
- Time is stored in dateObject as Ticks or Day Fraction.
- Date is stored in dateObject as Day Number.
- Ticks is time unit per seconds.
- For example, if the tick unit is 1000000.
- 0.25 seconds is equivalent to 250000 ticks (0.25*1000000).
- Day number, is the number days since the epoch, which is January 1, 0001 AD.
- Example.
-
+
+
+
+
+
7. dateObject
+
+
+
dateObject is a table containing date and time
+ value. It has a metatable for manipulation and retrieval of dates and times. Use
+ the __call method of date to
+ construct a dateObject.
+
+
+
+
+
+
7.1. How
+ Date and Time are stored in dateObject
+
+
+
Time is stored in dateObject as Ticks or Day
+ Fraction. Date is stored in dateObject as Day
+ Number. Ticks is time unit per seconds. For example, if the tick unit is 1000000.
+ 0.25 seconds is equivalent to 250000 ticks (0.25*1000000). Day number, is the
+ number days since the epoch, which is January 1, 0001 AD. Example.
+
dobj = date("15:49:59.3669")
-
-If the tick unit is 1000000, dobj store this time as 56999366900 ticks and 0 days.
-
+
If the tick unit is 1000000, dobj store this time as
+56999366900 ticks and 0 days.
+
+ string value. The format string
+ follows the same rules as the strftime standard C function.
+
+
+
+
+
Table 3. Format Spec
+
+
+
+
+
+
+
+
+
+
+
Spec
+
+
Description
+
+
+
+
+
+
'%a'
+
+
Abbreviated weekday name (Sun)
+
+
+
+
'%A'
+
+
Full weekday name (Sunday)
+
+
+
+
'%b'
+
+
Abbreviated month name (Dec)
+
+
+
+
'%B'
+
+
Full month name (December)
+
+
+
+
'%C'
+
+
Year/100 (19, 20, 30)
+
+
+
+
'%d'
+
+
The day of the month as a number (range 1 - 31)
+
+
+
+
'%g'
+
+
year for ISO 8601 week, from 00 (79)
+
+
+
+
'%G'
+
+
year for ISO 8601 week, from 0000 (1979)
+
+
+
+
'%h'
+
+
same as %b
+
+
+
+
'%H'
+
+
hour of the 24-hour day, from 00 (06)
+
+
+
+
'%I'
+
+
The hour as a number using a 12-hour clock (01 -
+ 12)
+
+
+
+
'%j'
+
+
The day of the year as a number (001 - 366)
+
+
+
+
'%m'
+
+
Month of the year, from 01 to 12
+
+
+
+
'%M'
+
+
Minutes after the hour 55
+
+
+
+
'%p'
+
+
AM/PM indicator (AM)
+
+
+
+
'%S'
+
+
The second as a number (59, 20 , 01)
+
+
+
+
'%u'
+
+
ISO 8601 day of the week, to 7 for Sunday (7, 1)
+
+
+
+
'%U'
+
+
Sunday week of the year, from 00 (48)
+
+
+
+
'%V'
+
+
ISO 8601 week of the year, from 01 (48)
+
+
+
+
'%w'
+
+
The day of the week as a decimal, Sunday being 0
+
+
+
+
'%W'
+
+
Monday week of the year, from 00 (48)
+
+
+
+
'%y'
+
+
The year as a number without a century (range 00 to
+ 99)
+
+
+
+
'%Y'
+
+
Year with century (2000, 1914, 0325, 0001)
+
+
+
+
'%z'
+
+
Time zone offset, the date object is assumed local
+ time (+1000, -0230)
+
+
+
+
'%Z'
+
+
Time zone name, the date object is assumed local
+ time
+
+
+
+
'%\b'
+
+
Year, if year is in BCE, prints the BCE Year
+ representation, otherwise result is similar to "%Y" (1
+ BCE, 40 BCE) #
+
+
+
+
'%\f'
+
+
Seconds including fraction (59.998, 01.123) #
+
+
+
+
'%%'
+
+
percent character %
+
+
+
+
'%r'
+
+
12-hour time, from 01:00:00 AM (06:55:15 AM); same as
+ "%I:%M:%S %p"
+
+
+
+
'%R'
+
+
hour:minute, from 01:00 (06:55); same as "%I:%M"
+
+
+
+
'%T'
+
+
24-hour time, from 00:00:00 (06:55:15); same as
+ "%H:%M:%S"
+
+
+
+
'%D'
+
+
month/day/year from 01/01/00 (12/02/79); same as
+ "%m/%d/%y"
+
+
+
+
'%F'
+
+
year-month-day (1979-12-02); same as "%Y-%m-%d"
+
+
+
+
'%c'
+
+
The preferred date and time representation; same as
+ "%x %X"
+
+
+
+
'%x'
+
+
The preferred date representation, same as "%a %b %d
+ %\b"
+
+
+
+
'%X'
+
+
The preferred time representation, same as
+ "%H:%M:%\f"
+
+
+
+
'${iso}'
+
+
Iso format, same as "%Y-%m-%dT%T"
+
+
+
+
'${http}'
+
+
http format, same as "%a, %d %b %Y %T GMT"
+
+
+
+
'${ctime}'
+
+
ctime format, same as "%a %b %d %T GMT %Y"
+
+
+
+
'${rfc850}'
+
+
RFC850 format, same as "%A, %d-%b-%y %T GMT"
+
+
+
+
'${rfc1123}'
+
+
RFC1123 format, same as "%a, %d %b %Y %T GMT"
+
+
+
+
'${asctime}'
+
+
asctime format, same as "%a %b %d %T %Y"
+
+
+
+
+
+
+
+
+
+
+
Remarks
+
+
Only English names are supported
+
+
Example
+
+
+
d = date(1582,10,5)
-assert(d:fmt('%D') == d:fmt("%m/%d/%y")) -- month/day/year from 01/01/00 (12/02/79)
-assert(d:fmt('%F') == d:fmt("%Y-%m-%d")) -- year-month-day (1979-12-02)
-assert(d:fmt('%h') == d:fmt("%b")) -- same as %b (Dec)
-assert(d:fmt('%r') == d:fmt("%I:%M:%S %p")) -- 12-hour time, from 01:00:00 AM (06:55:15 AM)
-assert(d:fmt('%T') == d:fmt("%H:%M:%S")) -- 24-hour time, from 00:00:00 (06:55:15)
+assert(d:fmt('%D') == d:fmt("%m/%d/%y")) -- month/day/year from 01/01/00 (12/02/79)
+assert(d:fmt('%F') == d:fmt("%Y-%m-%d")) -- year-month-day (1979-12-02)
+assert(d:fmt('%h') == d:fmt("%b")) -- same as %b (Dec)
+assert(d:fmt('%r') == d:fmt("%I:%M:%S %p")) -- 12-hour time, from 01:00:00 AM (06:55:15 AM)
+assert(d:fmt('%T') == d:fmt("%H:%M:%S")) -- 24-hour time, from 00:00:00 (06:55:15)
assert(d:fmt('%a %A %b %B') == "Tue Tuesday Oct October")
assert(d:fmt('%C %d') == "15 05", d:fmt('%C %d'))
@@ -349,7 +2161,14 @@ ${rfc850} -- rfc850
${rfc1123} -- rfc1123
${asctime} -- asctime
]])
-
Example (Prints the current date and time)
+
+
+
+
Example
+ (Prints the current date and time)
+
+
+
-- Prints the current date and time, including time zone
d = date(false);
print(d:fmt("Today is %c GMT%z"))
@@ -364,35 +2183,292 @@ print(d:fmt("Today is ${iso}%z"))
d = date(true);
print(d:fmt("Today is ${iso}Z"))
--> "Today is 2000-10-31T05:28:14Z"
-
7.3.10. getbias
Assuming dateObject is a local time.
- Returns the time zone offset.
- Returns nil on failure.
-
Syntax
dateObject:getbias()
Example
+
+
+
+
+
+
+
+
+
+
+
7.3.10. getbias
+
+
+
Assuming dateObject is a local time. Returns the time zone offset.
+ Returns nil on failure.
+
+
+
+
Syntax
+
+
+
+dateObject:getbias()
+
+
+
+
Example
+
+
+
a = date(2^16)
print(a:getbias())
-
7.3.11. getclockhour
Returns the hours value using a 12-hour clock in a dateObject.
Syntax
dateObject:getclockhour()
Example
+
+
+
+
+
+
+
+
+
+
+
7.3.11. getclockhour
+
+
+
Returns the hours
+ value using a 12-hour clock in a dateObject.
+
+
+
+
Syntax
+
+
+
+dateObject:getclockhour()
+
+
+
+
Example
+
+
+
a = date("10:59:59 pm")
assert(a:getclockhour()==10)
-
7.3.12. getdate
Returns the
- year,
- month, and
- day value in a dateObject.
Syntax
dateObject:getdate()
Example
+
+
+
+
+
+
+
+
+
+
+
7.3.12. getdate
+
+
+
Returns the
+ year, month, and day value in a dateObject.
+
+
+
+
Syntax
+
+
+
+dateObject:getdate()
+
+
+
+
Example
+
+
+
a = date(1970, 1, 1)
y, m, d = a:getdate()
assert(y == 1970 and m == 1 and d == 1)
-
Optional integer value.
- The starting day of week (1 for sunday, 2 for monday, ... 7 for saturday).
- If omitted the starting day of week is sunday.
-
Example
+
+
+
+
+
+
+
+
+
+
+
7.3.25. getweeknumber
+
+
+
Returns the week
+ number value in a dateObject.
+
+
+
+
Syntax
+
+
+
+dateObject:getweeknumber([int_wdaybase])
+
+
+
+
Arguments
+
+
+
+
+
int_wdaybase
+
+
Optional integer value. The
+ starting day of week (1 for sunday, 2 for monday, ... 7 for
+ saturday). If omitted the starting day of week is sunday.
+
+
+
+
+
Example
+
+
+
a = date("12/31/1972")
b,c = a:getweeknumber(), a:getweeknumber(2)
assert(b==53 and c==52)
-
LuaDate is a Lua module for date and time
- calculation and retrieval using the Gregorian Date system.
-
-
To Load the module call local date = require"date" in
- your script. Make sure Lua can find the source file date.lua. No global table date
- will be created. Use the metamethod __call to construct
- a dateObject see example below:
-
-local date = require "date"
--- prints all FRIDAY the 13TH dates between year 2000 and 2010
-for i = 2000, 2010 do
- -- year jan 1
- x = date(i, 1, 1)
- -- from january to december
- for j = 1, 12 do
- -- set date to 13, check if friday
- if x:setmonth(j, 13):getweekday() == 6 then
- print(x:fmt("%A, %B %d %Y"))
- end
- end
-end
-
---- OUTPUT ---
---> Friday, October 13 2000
---> Friday, April 13 2001
---> Friday, July 13 2001
---> Friday, September 13 2002
---> Friday, December 13 2002
---> Friday, June 13 2003
---> Friday, February 13 2004
---> Friday, August 13 2004
---> Friday, May 13 2005
---> Friday, January 13 2006
---> Friday, October 13 2006
---> Friday, April 13 2007
---> Friday, July 13 2007
---> Friday, June 13 2008
---> Friday, February 13 2009
---> Friday, March 13 2009
---> Friday, November 13 2009
---> Friday, August 13 2010
-
-
-
-
-
-
-
-
2. Limits
-
-
-
-
-
-
-
This module does not recognize leap seconds.
-
-
It assumes that a day has exactly 24*60*60
- seconds.
-
-
The Lua number must be a double C data type
-
-
This module supports dates that are greater than Mon
- Jan 01 1000000 BCE 00:00:00 and less than Mon Jan
- 01 1000001 00:00:00.
This module also supports local time. Local Time is;
-
-
-
- Local = UTC + bias
-
-
The bias is time zone offset plus the
- daylight savings if in effect. The bias is
- retrieve using the Lua function os.date and os.time. It assumes that the Lua function os.timereturns the number of seconds
- since the start time (called "epoch"). If the time value is outside
- the allowable range of times, usually Jan 01 1970
- 00:00:00 to Jan 19 2038 03:14:07 the bias will
- be retrieve using the equivalent year inside the allowable range. Two years are
- considered to equivalent if they have the same leap year ness and starting weekday.
-
-
Parsable date value is a lua value that can be converted to a dateObject. This value must be num_time
- or tbl_date or str_date or
- bool_now argument describe in the date library __call method.
-
-
-
-
-
-
-
5. Parsable month value
-
-
-
If a function needs a month value it must be a string or a number. If the
- value is a string, it must be the name of the month
- full or abbreviated. If the value is a number, that
- number must be 1-12 (January-December). see table below
-
-
-
-
-
Table 1.
-
-
-
-
-
-
-
-
-
-
-
-
Index
-
-
Abbreviation
-
-
Full Name
-
-
-
-
-
-
1
-
-
Jan
-
-
January
-
-
-
-
2
-
-
Feb
-
-
February
-
-
-
-
3
-
-
Mar
-
-
March
-
-
-
-
4
-
-
Apr
-
-
April
-
-
-
-
5
-
-
May
-
-
May
-
-
-
-
6
-
-
Jun
-
-
June
-
-
-
-
7
-
-
Jul
-
-
July
-
-
-
-
8
-
-
Aug
-
-
August
-
-
-
-
9
-
-
Sep
-
-
September
-
-
-
-
10
-
-
Oct
-
-
October
-
-
-
-
11
-
-
Nov
-
-
November
-
-
-
-
12
-
-
Dec
-
-
December
-
-
-
-
-
-
-
If the value does not represent month, that is equivalent to passing a nil
- value.
true if var_year leap year. false
- if var_year not leap year.
-
-
Remarks
-
-
A leap year in the Gregorian calendar is defined as a year that is
- evenly divisible by four, except if it is divisible by 100; however, years
- that are divisible by 400 are leap years.
day - an integer,
- the day of month from 1 to 31. Required if year and month is
- given
-
-
hour - a number,
- hours value, from 0 to 23, indicating the number of hours since
- midnight. (default = 0)
-
-
min - a number,
- minutes value, from 0 to 59. (default = 0)
-
-
sec - a number,
- seconds value, from 0 to 59. (default = 0)
-
-
Time (hour or min or sec or
- msec) must be supplied if date (year and month and day) is not
- given, vice versa.
-
-
-
-
-
-
-
str_date
-
-
- Required string value. It must have
- number/words representing date and/or time. Use commas and spaces
- as delimiters. Strings enclosed by parenthesis is treated as a
- comment and is ignored, these parentheses may be nested. The stated
- day of the week is ignored whether its correct or not. A string
- containing an invalid date is an error. For example, a string
- containing two years or two months is an error. Time must be
- supplied if date is not given, vice versa.
-
-
Time Format. Hours, minutes, and seconds are
- separated by colons, although all need not be specified. "10:",
- "10:11", and "10:11:12" are all valid. If the 24-hour clock is
- used, it is an error to specify "PM" for times later than 12 noon.
- For example, "23:15 PM" is an error.
-
-
Time Zone Format. First character is a sign "+"
- (east of UTC) or "-" (west of UTC). Hours and minutes offset are
- separated by colons:
Another format is [sign][number]
- If [number] is less than 24, it is
- the offset in hours e.g. "-10" = -10 hours. Otherwise it is the
- offset in houndred hours e.g. "+75" = "+115" = +1.25 hours.
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.
- where YYYY is the year, MM is the month of the year, and DD
- is the day of the month.
-
-assert(date("2000-12-31")==date(2000,12,31))
-assert(date(" 20001231 ")==date(2000,12,31)) -- Compact version
-
-
-
-
YYYY-DDD
-
-
- where YYYY is the year, DDD is the day of the year.
-
-assert(date("1995-035")==date(1995,02,04))
-assert(date("1995035 ")==date(1995,02,04)) -- Compact version
-
-
-
-
YYYY-WDD-D
-
-
- where YYYY is the year, DD is the week of the year, D is the
- day of the week.
-
-assert(date("1997-W01-1")==date(1996,12,30))
-assert(date(" 1997W017")==date(1997,01,05)) -- Compact version
-
-
-
-
DATE HH:MM:SS.SSS
-
-
- Where DATE is the date
- format discuss above, HH is the hour, MM is the miute, SS.SSS
- is the seconds (fraction is optional).
-
-assert(date("1995-02-04 24:00:51.536")==date(1995,2,5,0,0,51.536))
-assert(date("1976-W01-1 12:12:12.123")==date(1975,12,29,12,12,12.123))
-assert(date("1995-035 23:59:59.99999")==date(1995,02,04,23,59,59.99999))
--- Compact version separated by latin capital letter T
-assert(date(" 19950205T000051.536 ")==date(1995,2,5,0,0,51.536))
-assert(date(" 1976W011T121212.123 ")==date(1975,12,29,12,12,12.123))
-assert(date(" 1995035T235959.99999 ")==date(1995,02,04,23,59,59.99999))
-
-
-
-
DATETIME +HH:MM, DATE
- TIME -HHMM,
- DATETIME Z,
-
-
- Where DATE and
- TIME is the dateand
- 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.
-
Required boolean value. if
- bool_now is false it returns the current local date and time.
- if bool_now is true it returns the current UTC date and
- time.
dateObject is a table containing date and time
- value. It has a metatable for manipulation and retrieval of dates and times. Use
- the __call method of date to
- construct a dateObject.
-
-
-
-
-
-
7.1. How
- Date and Time are stored in dateObject
-
-
-
Time is stored in dateObject as Ticks or Day
- Fraction. Date is stored in dateObject as Day
- Number. Ticks is time unit per seconds. For example, if the tick unit is 1000000.
- 0.25 seconds is equivalent to 250000 ticks (0.25*1000000). Day number, is the
- number days since the epoch, which is January 1, 0001 AD. Example.
-
-dobj = date("15:49:59.3669")
-
If the tick unit is 1000000, dobj store this time as
-56999366900 ticks and 0 days.
-
If the tick unit is 1000000, dobj store this date and
-time as 37815000000 ticks and 4 days. 4 days becuase:
-
-
-
-
Day#
-
-
Date
-
-
-
-
0
-
-
Jan 1 0001
-
-
-
-
1
-
-
Jan 2 0001
-
-
-
-
2
-
-
Jan 3 0001
-
-
-
-
3
-
-
Jan 4 0001
-
-
-
-
4
-
-
Jan 5 0001
-
-
-
-
5
-
-
Jan 6 0001
-
-
-
-
...
-
-
...
-
-
-
-
The default tick unit is 1000000 (micro-second-ticks)
-
-
-
-
-
-
-
7.2. Supported MetaMethods
-
-
-
-
-
-
-
The a < b
- operation.
-
-
Returns true if date value of a is later
- than date value of b. a > b is equivalent to
- b < a.
-
-
The a <= b
- operation.
-
-
Returns true if date value of a is later
- than or equal to the date value of b. a >= b
- is equivalent to b <= a.
-
-
The a == b
- operation.
-
-
Returns true if date value of a is equal
- equal to the date value of b. a ~= b is
- equivalent to not (a == b).
-
-
The a .. b
- operation.
-
-
Equivalent to tostring(a) ..
- tostring(b).
-
-
The a - b
- operation.
-
-
Subtract the date and time value of a to
- date and time value of b.
-
-
The a + b
- operation.
-
-
Add the date and time value of a to date and
- time value of b.
-
-
a and b must be a
- parsable date value or an error rises
-
-a = date(1521,5,2)
-b = a:copy():addseconds(0.001)
-
-assert((a - b):spanseconds() == -0.001)
-assert((a + b) == (b + a))
-assert(a == (b - date("00:00:00.001")) )
-assert(b == (a + date("00:00:00.001")) )
-
-b:addseconds(-0.01)
-
-assert(a > b and b < a)
-assert(a >= b and b <= a)
-assert(a ~= b and (not(a == b)))
-
-a = b:copy()
-
-assert(not (a > b and b < a))
-assert(a >= b and b <= a)
-assert(a == b and (not(a ~= b)))
-
-assert((a .. 565369) == (b .. 565369))
-assert((a .. "????") == (b .. "????"))
-
-
- string value. The format string
- follows the same rules as the strftime standard C function.
-
-
-
-
-
Table 3. Format Spec
-
-
-
-
-
-
-
-
-
-
-
Spec
-
-
Description
-
-
-
-
-
-
'%a'
-
-
Abbreviated weekday name (Sun)
-
-
-
-
'%A'
-
-
Full weekday name (Sunday)
-
-
-
-
'%b'
-
-
Abbreviated month name (Dec)
-
-
-
-
'%B'
-
-
Full month name (December)
-
-
-
-
'%C'
-
-
Year/100 (19, 20, 30)
-
-
-
-
'%d'
-
-
The day of the month as a number (range 1 - 31)
-
-
-
-
'%g'
-
-
year for ISO 8601 week, from 00 (79)
-
-
-
-
'%G'
-
-
year for ISO 8601 week, from 0000 (1979)
-
-
-
-
'%h'
-
-
same as %b
-
-
-
-
'%H'
-
-
hour of the 24-hour day, from 00 (06)
-
-
-
-
'%I'
-
-
The hour as a number using a 12-hour clock (01 -
- 12)
-
-
-
-
'%j'
-
-
The day of the year as a number (001 - 366)
-
-
-
-
'%m'
-
-
Month of the year, from 01 to 12
-
-
-
-
'%M'
-
-
Minutes after the hour 55
-
-
-
-
'%p'
-
-
AM/PM indicator (AM)
-
-
-
-
'%S'
-
-
The second as a number (59, 20 , 01)
-
-
-
-
'%u'
-
-
ISO 8601 day of the week, to 7 for Sunday (7, 1)
-
-
-
-
'%U'
-
-
Sunday week of the year, from 00 (48)
-
-
-
-
'%V'
-
-
ISO 8601 week of the year, from 01 (48)
-
-
-
-
'%w'
-
-
The day of the week as a decimal, Sunday being 0
-
-
-
-
'%W'
-
-
Monday week of the year, from 00 (48)
-
-
-
-
'%y'
-
-
The year as a number without a century (range 00 to
- 99)
-
-
-
-
'%Y'
-
-
Year with century (2000, 1914, 0325, 0001)
-
-
-
-
'%z'
-
-
Time zone offset, the date object is assumed local
- time (+1000, -0230)
-
-
-
-
'%Z'
-
-
Time zone name, the date object is assumed local
- time
-
-
-
-
'%\b'
-
-
Year, if year is in BCE, prints the BCE Year
- representation, otherwise result is similar to "%Y" (1
- BCE, 40 BCE) #
-
-
-
-
'%\f'
-
-
Seconds including fraction (59.998, 01.123) #
-
-
-
-
'%%'
-
-
percent character %
-
-
-
-
'%r'
-
-
12-hour time, from 01:00:00 AM (06:55:15 AM); same as
- "%I:%M:%S %p"
-
-
-
-
'%R'
-
-
hour:minute, from 01:00 (06:55); same as "%I:%M"
-
-
-
-
'%T'
-
-
24-hour time, from 00:00:00 (06:55:15); same as
- "%H:%M:%S"
-
-
-
-
'%D'
-
-
month/day/year from 01/01/00 (12/02/79); same as
- "%m/%d/%y"
-
-
-
-
'%F'
-
-
year-month-day (1979-12-02); same as "%Y-%m-%d"
-
-
-
-
'%c'
-
-
The preferred date and time representation; same as
- "%x %X"
-
-
-
-
'%x'
-
-
The preferred date representation, same as "%a %b %d
- %\b"
-
-
-
-
'%X'
-
-
The preferred time representation, same as
- "%H:%M:%\f"
-
-
-
-
'${iso}'
-
-
Iso format, same as "%Y-%m-%dT%T"
-
-
-
-
'${http}'
-
-
http format, same as "%a, %d %b %Y %T GMT"
-
-
-
-
'${ctime}'
-
-
ctime format, same as "%a %b %d %T GMT %Y"
-
-
-
-
'${rfc850}'
-
-
RFC850 format, same as "%A, %d-%b-%y %T GMT"
-
-
-
-
'${rfc1123}'
-
-
RFC1123 format, same as "%a, %d %b %Y %T GMT"
-
-
-
-
'${asctime}'
-
-
asctime format, same as "%a %b %d %T %Y"
-
-
-
-
-
-
-
-
-
-
-
Remarks
-
-
Only English names are supported
-
-
Example
-
-
-
-d = date(1582,10,5)
-assert(d:fmt('%D') == d:fmt("%m/%d/%y")) -- month/day/year from 01/01/00 (12/02/79)
-assert(d:fmt('%F') == d:fmt("%Y-%m-%d")) -- year-month-day (1979-12-02)
-assert(d:fmt('%h') == d:fmt("%b")) -- same as %b (Dec)
-assert(d:fmt('%r') == d:fmt("%I:%M:%S %p")) -- 12-hour time, from 01:00:00 AM (06:55:15 AM)
-assert(d:fmt('%T') == d:fmt("%H:%M:%S")) -- 24-hour time, from 00:00:00 (06:55:15)
-assert(d:fmt('%a %A %b %B') == "Tue Tuesday Oct October")
-assert(d:fmt('%C %d') == "15 05", d:fmt('%C %d'))
-
-print(d:fmt[[
-${iso} -- iso
-${http} -- http
-${ctime} -- ctime
-${rfc850} -- rfc850
-${rfc1123} -- rfc1123
-${asctime} -- asctime
-]])
-
-
-
-
Example
- (Prints the current date and time)
-
-
-
--- Prints the current date and time, including time zone
-d = date(false);
-print(d:fmt("Today is %c GMT%z"))
---> "Today is Tue Oct 31 2000 01:58:14 GMT-0330"
-
--- Prints the current date and time in ISO format including time zone
-d = date(false);
-print(d:fmt("Today is ${iso}%z"))
---> "Today is 2000-10-31T01:58:14-0330"
-
--- Prints the current date and time in ISO format, indicates UTC
-d = date(true);
-print(d:fmt("Today is ${iso}Z"))
---> "Today is 2000-10-31T05:28:14Z"
-
-
-
-
-
-
-
-
-
-
-
7.3.10. getbias
-
-
-
Assuming dateObject is a local time. Returns the time zone offset.
- Returns nil on failure.
-
-
-
-
Syntax
-
-
-
-dateObject:getbias()
-
-
-
-
Example
-
-
-
-a = date(2^16)
-print(a:getbias())
-
-
-
-
-
-
-
-
-
-
-
7.3.11. getclockhour
-
-
-
Returns the hours
- value using a 12-hour clock in a dateObject.
-
-
-
-
Syntax
-
-
-
-dateObject:getclockhour()
-
-
-
-
Example
-
-
-
-a = date("10:59:59 pm")
-assert(a:getclockhour()==10)
-
-
-
-
-
-
-
-
-
-
-
7.3.12. getdate
-
-
-
Returns the
- year, month, and day value in a dateObject.
-
-
-
-
Syntax
-
-
-
-dateObject:getdate()
-
-
-
-
Example
-
-
-
-a = date(1970, 1, 1)
-y, m, d = a:getdate()
-assert(y == 1970 and m == 1 and d == 1)
-
-
-
-
-
-
-
-
-
-
-
7.3.13. getday
-
-
-
Returns the day of
- month value in a dateObject
-
-