-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdatetime_utility.ruff
More file actions
52 lines (43 loc) · 1.92 KB
/
Copy pathdatetime_utility.ruff
File metadata and controls
52 lines (43 loc) · 1.92 KB
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
// Date/Time Utility
// Demonstrates date/time functions from stdlib
print("=== Date/Time Utility ===")
print("")
// Current timestamp
timestamp := now()
print("Current Unix Timestamp: " + timestamp)
print("")
// Format current date/time in various ways
print("Formatted Date/Time:")
print(" ISO Format: " + format_date(timestamp, "YYYY-MM-DD"))
print(" US Format: " + format_date(timestamp, "MM/DD/YYYY"))
print(" European Format: " + format_date(timestamp, "DD/MM/YYYY"))
print(" Full DateTime: " + format_date(timestamp, "YYYY-MM-DD HH:mm:ss"))
print(" Time Only: " + format_date(timestamp, "HH:mm:ss"))
print("")
// Historical dates
print("Historical Dates:")
moon_landing := parse_date("1969-07-20", "YYYY-MM-DD")
print(" Moon Landing: " + format_date(moon_landing, "YYYY-MM-DD") + " (" + moon_landing + ")")
independence := parse_date("1776-07-04", "YYYY-MM-DD")
print(" US Independence: " + format_date(independence, "YYYY-MM-DD") + " (" + independence + ")")
millennium := parse_date("2000-01-01", "YYYY-MM-DD")
print(" Y2K Millennium: " + format_date(millennium, "YYYY-MM-DD") + " (" + millennium + ")")
print("")
// Date calculations
print("Date Calculations:")
today := now()
week_ago := today - (7 * 24 * 60 * 60) // 7 days in seconds
print(" Today: " + format_date(today, "YYYY-MM-DD"))
print(" Week Ago: " + format_date(week_ago, "YYYY-MM-DD"))
month_future := today + (30 * 24 * 60 * 60) // ~30 days in seconds
print(" ~30 Days Later: " + format_date(month_future, "YYYY-MM-DD"))
print("")
// Age calculator
print("Age Calculator:")
birth_date := parse_date("1990-05-15", "YYYY-MM-DD")
age_seconds := today - birth_date
age_days := age_seconds / (24 * 60 * 60)
age_years := age_days / 365.25
print(" Birth Date: " + format_date(birth_date, "YYYY-MM-DD"))
print(" Age (approx): " + floor(age_years) + " years")
print(" Days Lived: " + floor(age_days) + " days")