-
Notifications
You must be signed in to change notification settings - Fork 0
/
DateTimeFunctionLibrary.lua
70 lines (60 loc) · 1.94 KB
/
DateTimeFunctionLibrary.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
local dateTime = {}
function dateTime.Start()
-- Updates the current time to the os's time
function dateTime.update_current_date()
return os.date("*t")
end
-- prints the date as 11/11/24 format
function dateTime.whole_date()
local currentDate = dateTime.update_current_date()
return currentDate.month .. "/" .. currentDate.day .. "/" .. currentDate.year
end
-- prints the current month
function dateTime.month()
local currentDate = dateTime.update_current_date()
return currentDate.month
end
-- prints the current day
function dateTime.day()
local currentDate = dateTime.update_current_date()
return currentDate.day
end
-- prints the current year
function dateTime.year()
local currentDate = dateTime.update_current_date()
return currentDate.year
end
-- prints the current minute
function dateTime.minute()
local currentDate = dateTime.update_current_date()
if currentDate.min < 10 then
return "0" .. tostring(currentDate.min)
else
return tostring(currentDate.min)
end
end
-- prints the current hour
function dateTime.hour()
local currentDate = dateTime.update_current_date()
-- changes the time from a 24 hr clock to a 12 hr clock
if tonumber(currentDate.hour) > 12 then
return tonumber(currentDate.hour) - 12
else
return tonumber(currentDate.hour)
end
end
-- prints the hour and minute '3:45'
function dateTime.full_time()
return tostring(dateTime.hour()) .. ":" .. tostring(dateTime.minute())
end
-- prints am/pm
function dateTime.am_pm()
-- checks if the hour is more than 12
if tonumber(dateTime.hour()) > 12 then
return "pm"
else
return "am"
end
end
end
return dateTime