Date.lua: Difference between revisions
No edit summary |
Dubiousjim (talk | contribs) (Category:Lua) |
||
(18 intermediate revisions by 2 users not shown) | |||
Line 1: | Line 1: | ||
=Functions= | |||
== date_to_seconds == | == date_to_seconds == | ||
'''INPUT:'''<BR> | '''INPUT:'''<BR> | ||
Line 5: | Line 6: | ||
** Example: t = { {year=2000,month=12,day=13}, {year=1987,month=4,day=30,hour=10}, {year=2020,month=1,day=10} } | ** Example: t = { {year=2000,month=12,day=13}, {year=1987,month=4,day=30,hour=10}, {year=2020,month=1,day=10} } | ||
'''OUTPUT:'''<BR> | '''OUTPUT:'''<BR> | ||
This library function | This library function delivers the following output/parameters. | ||
* Sorted table of dates in seconds since 1970 | * Sorted table of dates in seconds since 1970 | ||
** | ** temp = { 546775200, 976708800, 1578657600 } | ||
'''CODING EXAMPLE:''' | '''CODING EXAMPLE:''' | ||
-- Include/Call for this library | -- Include/Call for this library | ||
Line 17: | Line 18: | ||
--1578657600 | --1578657600 | ||
==seconds_to_date == | == seconds_to_date == | ||
'''INPUT:'''<BR> | |||
This library function required the following inputs/parameters. | |||
* Table of seconds since 1970 | |||
** Example: t = { 546775200, 976708800, 1578657600 } | |||
'''OUTPUT:'''<BR> | |||
This library function deliverers the following output/parameters. | |||
* Will give a table with a formated string | |||
** temp = { {Thu Apr 30 10:00:00 UTC 1987}, {Wed Dec 13 12:00:00 UTC 2000}, {Fri Jan 10 12:00:00 UTC 2020} } | |||
'''CODING EXAMPLE:''' | |||
-- Include/Call for this library | |||
require("date") | |||
temp = date.seconds_to_date(t) --see t above | |||
-- the formated string is found in the top of date.lua | |||
-- is format = "%a %b %d %X %Z %Y" | |||
== string_to_table == | |||
'''INPUT:'''<BR> | |||
This library function required the following inputs/parameters. | |||
* Formatted string with date (of format os.date("%a %b %d %X %Z %Y")) | |||
** Example: str = "Mon Nov 26 19:56:10 UTC 2007" | |||
'''OUTPUT:'''<BR> | |||
This library function deliverers the following output/parameters. | |||
* Will give a table with year, month, day, hour, min, sec, isdst | |||
'''CODING EXAMPLE:''' | |||
-- Include/Call for this library | |||
require("date") | |||
temp = date.string_to_table(os.date(date.format)) | |||
==date_diff == | ==date_diff == | ||
'''INPUT:'''<BR> | |||
This library function required the following inputs/parameters. | |||
* Two dates as seconds to difference | |||
** Example: (546775200, 976708800) | |||
*** Thu Apr 30 10:00:00 UTC 1987, Wed Dec 13 12:00:00 UTC 2000 | |||
'''OUTPUT:'''<BR> | |||
This library function deliverers the following output/parameters. | |||
* A table | |||
** temp = { min=0, day=17, month=8,sec=0,hour=2, year=13} | |||
'''CODING EXAMPLE:''' | |||
-- Include/Call for this library | |||
require("date") | |||
temp = date.date_diff(546775200, 976708800) | |||
--temp will be valued as above. This will not be completely accurate in relation to leap years... | |||
==num_month_name == | ==num_month_name == | ||
'''INPUT:'''<BR> | |||
This library function required the following inputs/parameters. | |||
* Number of month to match | |||
'''OUTPUT:'''<BR> | |||
This library function deliverers the following output/parameters. | |||
* String of Full name of the month | |||
'''CODING EXAMPLE:''' | |||
-- Include/Call for this library | |||
require("date") | |||
print(date.num_month_name(7) | |||
--July | |||
==num_month_name_abr== | ==num_month_name_abr== | ||
'''INPUT:'''<BR> | |||
This library function required the following inputs/parameters. | |||
* Number | |||
'''OUTPUT:'''<BR> | |||
This library function deliverers the following output/parameters. | |||
* String of 3 letter abbreviation of | |||
'''CODING EXAMPLE:''' | |||
-- Include/Call for this library | |||
require("date") | |||
print(date.num_month_name_abr(7) | |||
--Jul | |||
==name_month_num == | ==name_month_num == | ||
'''INPUT:'''<BR> | |||
This library function required the following inputs/parameters. | |||
* String - Full name of month to match | |||
'''OUTPUT:'''<BR> | |||
This library function deliverers the following output/parameters. | |||
* Number of Month matched | |||
'''CODING EXAMPLE:''' | |||
-- Include/Call for this library | |||
require("date") | |||
print(date.name_month_num("July") | |||
--7 | |||
==abr_month_num == | ==abr_month_num == | ||
'''INPUT:'''<BR> | |||
This library function required the following inputs/parameters. | |||
* String of Abbreviation of month name | |||
'''OUTPUT:'''<BR> | |||
This library function deliverers the following output/parameters. | |||
* Number of Month | |||
'''CODING EXAMPLE:''' | |||
-- Include/Call for this library | |||
require("date") | |||
print(date.abr_month_num("Jul") | |||
--7 | |||
== num_dow_name == | == num_dow_name == | ||
'''INPUT:'''<BR> | |||
This library function required the following inputs/parameters. | |||
* Number of Day of Week | |||
**Starts with Sunday -Saturday | |||
'''OUTPUT:'''<BR> | |||
This library function deliverers the following output/parameters. | |||
* String of Full name of the month | |||
'''CODING EXAMPLE:''' | |||
-- Include/Call for this library | |||
require("date") | |||
print(date.num_dow_name(6) | |||
--Friday | |||
== num_dow_abr == | == num_dow_abr == | ||
'''INPUT:'''<BR> | |||
This library function required the following inputs/parameters. | |||
* Number of Day of Week | |||
**Starts with Sunday -Saturday | |||
'''OUTPUT:'''<BR> | |||
This library function deliverers the following output/parameters. | |||
* String of Full name of the month | |||
'''CODING EXAMPLE:''' | |||
-- Include/Call for this library | |||
require("date") | |||
print(date.num_dow_abr(6) | |||
--Fri | |||
==name_dow_num == | ==name_dow_num == | ||
'''INPUT:'''<BR> | |||
This library function required the following inputs/parameters. | |||
* Give the full name of a Day of Week | |||
**Starts with Sunday -Saturday | |||
'''OUTPUT:'''<BR> | |||
This library function deliverers the following output/parameters. | |||
* Number of day of week | |||
'''CODING EXAMPLE:''' | |||
-- Include/Call for this library | |||
require("date") | |||
print(date.name_dow_num("Friday") | |||
--6 | |||
== abr_dow_num == | == abr_dow_num == | ||
'''INPUT:'''<BR> | |||
This library function required the following inputs/parameters. | |||
* Give the abbreviated name of a Day of Week | |||
**Starts with Sunday -Saturday | |||
'''OUTPUT:'''<BR> | |||
This library function deliverers the following output/parameters. | |||
* Number of day of week | |||
'''CODING EXAMPLE:''' | |||
-- Include/Call for this library | |||
require("date") | |||
print(date.name_dow_num("Fri") | |||
--6 | |||
== what_tz == | |||
'''INPUT:'''<BR> | |||
This library function required the following inputs/parameters. | |||
* No input needed | |||
'''OUTPUT:'''<BR> | |||
This library function deliverers the following output/parameters. | |||
* Will read /etc/TZ and output the contents | |||
'''CODING EXAMPLE:''' | |||
-- Include/Call for this library | |||
require("date") | |||
print(date.what_tz()) | |||
--great if want to do os.date() and want the timezone also. | |||
-- lua os.date() doesn't show the timezone | |||
== change_tz == | |||
<span style="color:red">This may change a bit in the future. /etc/TZ maybe buggy</span> | |||
'''INPUT:'''<BR> | |||
This library function required the following inputs/parameters. | |||
* String of Timezone name and offset | |||
** EST-5 | |||
'''OUTPUT:'''<BR> | |||
This library function deliverers the following output/parameters. | |||
* Output result and what the timezone is | |||
**result Success or failure | |||
**just runs what_tz and outputs | |||
'''CODING EXAMPLE:''' | |||
-- Include/Call for this library | |||
require("date") | |||
print(date.change_tz("EST+5")) -- has to be reverse or EST-5. Still don't know why | |||
--will output if able to write to the file and the set timezone | |||
[[Category:Lua]] |
Latest revision as of 08:02, 12 March 2012
Functions
date_to_seconds
INPUT:
This library function required the following inputs/parameters.
- Table of dates
- Example: t = { {year=2000,month=12,day=13}, {year=1987,month=4,day=30,hour=10}, {year=2020,month=1,day=10} }
OUTPUT:
This library function delivers the following output/parameters.
- Sorted table of dates in seconds since 1970
- temp = { 546775200, 976708800, 1578657600 }
CODING EXAMPLE:
-- Include/Call for this library require("date") temp = date.date_to_seconds(t) --see table t above for a,b in ipairs(temp) do print(b) end --546775200 --976708800 --1578657600
seconds_to_date
INPUT:
This library function required the following inputs/parameters.
- Table of seconds since 1970
- Example: t = { 546775200, 976708800, 1578657600 }
OUTPUT:
This library function deliverers the following output/parameters.
- Will give a table with a formated string
- temp = { {Thu Apr 30 10:00:00 UTC 1987}, {Wed Dec 13 12:00:00 UTC 2000}, {Fri Jan 10 12:00:00 UTC 2020} }
CODING EXAMPLE:
-- Include/Call for this library require("date") temp = date.seconds_to_date(t) --see t above -- the formated string is found in the top of date.lua -- is format = "%a %b %d %X %Z %Y"
string_to_table
INPUT:
This library function required the following inputs/parameters.
- Formatted string with date (of format os.date("%a %b %d %X %Z %Y"))
- Example: str = "Mon Nov 26 19:56:10 UTC 2007"
OUTPUT:
This library function deliverers the following output/parameters.
- Will give a table with year, month, day, hour, min, sec, isdst
CODING EXAMPLE:
-- Include/Call for this library require("date") temp = date.string_to_table(os.date(date.format))
date_diff
INPUT:
This library function required the following inputs/parameters.
- Two dates as seconds to difference
- Example: (546775200, 976708800)
- Thu Apr 30 10:00:00 UTC 1987, Wed Dec 13 12:00:00 UTC 2000
- Example: (546775200, 976708800)
OUTPUT:
This library function deliverers the following output/parameters.
- A table
- temp = { min=0, day=17, month=8,sec=0,hour=2, year=13}
CODING EXAMPLE:
-- Include/Call for this library require("date") temp = date.date_diff(546775200, 976708800) --temp will be valued as above. This will not be completely accurate in relation to leap years...
num_month_name
INPUT:
This library function required the following inputs/parameters.
- Number of month to match
OUTPUT:
This library function deliverers the following output/parameters.
- String of Full name of the month
CODING EXAMPLE:
-- Include/Call for this library require("date") print(date.num_month_name(7) --July
num_month_name_abr
INPUT:
This library function required the following inputs/parameters.
- Number
OUTPUT:
This library function deliverers the following output/parameters.
- String of 3 letter abbreviation of
CODING EXAMPLE:
-- Include/Call for this library require("date") print(date.num_month_name_abr(7) --Jul
name_month_num
INPUT:
This library function required the following inputs/parameters.
- String - Full name of month to match
OUTPUT:
This library function deliverers the following output/parameters.
- Number of Month matched
CODING EXAMPLE:
-- Include/Call for this library require("date") print(date.name_month_num("July") --7
abr_month_num
INPUT:
This library function required the following inputs/parameters.
- String of Abbreviation of month name
OUTPUT:
This library function deliverers the following output/parameters.
- Number of Month
CODING EXAMPLE:
-- Include/Call for this library require("date") print(date.abr_month_num("Jul") --7
num_dow_name
INPUT:
This library function required the following inputs/parameters.
- Number of Day of Week
- Starts with Sunday -Saturday
OUTPUT:
This library function deliverers the following output/parameters.
- String of Full name of the month
CODING EXAMPLE:
-- Include/Call for this library require("date") print(date.num_dow_name(6) --Friday
num_dow_abr
INPUT:
This library function required the following inputs/parameters.
- Number of Day of Week
- Starts with Sunday -Saturday
OUTPUT:
This library function deliverers the following output/parameters.
- String of Full name of the month
CODING EXAMPLE:
-- Include/Call for this library require("date") print(date.num_dow_abr(6) --Fri
name_dow_num
INPUT:
This library function required the following inputs/parameters.
- Give the full name of a Day of Week
- Starts with Sunday -Saturday
OUTPUT:
This library function deliverers the following output/parameters.
- Number of day of week
CODING EXAMPLE:
-- Include/Call for this library require("date") print(date.name_dow_num("Friday") --6
abr_dow_num
INPUT:
This library function required the following inputs/parameters.
- Give the abbreviated name of a Day of Week
- Starts with Sunday -Saturday
OUTPUT:
This library function deliverers the following output/parameters.
- Number of day of week
CODING EXAMPLE:
-- Include/Call for this library require("date") print(date.name_dow_num("Fri") --6
what_tz
INPUT:
This library function required the following inputs/parameters.
- No input needed
OUTPUT:
This library function deliverers the following output/parameters.
- Will read /etc/TZ and output the contents
CODING EXAMPLE:
-- Include/Call for this library require("date") print(date.what_tz()) --great if want to do os.date() and want the timezone also. -- lua os.date() doesn't show the timezone
change_tz
This may change a bit in the future. /etc/TZ maybe buggy
INPUT:
This library function required the following inputs/parameters.
- String of Timezone name and offset
- EST-5
OUTPUT:
This library function deliverers the following output/parameters.
- Output result and what the timezone is
- result Success or failure
- just runs what_tz and outputs
CODING EXAMPLE:
-- Include/Call for this library require("date") print(date.change_tz("EST+5")) -- has to be reverse or EST-5. Still don't know why --will output if able to write to the file and the set timezone