Repository navigation
Expand file tree
/
Copy pathtest_date_module.pie
More file actions
180 lines (142 loc) · 5.09 KB
/
Copy pathtest_date_module.pie
File metadata and controls
180 lines (142 loc) · 5.09 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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
import date;
int main() {
output("=== PIE Date Module Test ===\n\n", string);
// Get current timestamp
output("1. Current Time:\n", string);
int now = date.now();
output("Current timestamp: ", string);
output(now, int);
output("\n", string);
// Format current date/time in different ways
output("\n2. Formatting:\n", string);
string isoFormat = date.format_iso(now);
output("ISO 8601 format: ", string);
output(isoFormat, string);
output("\n", string);
string dateOnly = date.format_date(now);
output("Date only: ", string);
output(dateOnly, string);
output("\n", string);
string timeOnly = date.format_time(now);
output("Time only: ", string);
output(timeOnly, string);
output("\n", string);
string customFormat = date.format(now, "%A, %B %d, %Y at %I:%M %p");
output("Custom format: ", string);
output(customFormat, string);
output("\n", string);
// Extract date components
output("\n3. Date Components:\n", string);
int year = date.get_year(now);
output("Year: ", string);
output(year, int);
output("\n", string);
int month = date.get_month(now);
output("Month: ", string);
output(month, int);
output(" (", string);
output(date.get_month_name(now), string);
output(")\n", string);
int day = date.get_day(now);
output("Day: ", string);
output(day, int);
output("\n", string);
int weekday = date.get_weekday(now);
output("Weekday: ", string);
output(weekday, int);
output(" (", string);
output(date.get_weekday_name(now), string);
output(")\n", string);
int hour = date.get_hour(now);
output("Hour: ", string);
output(hour, int);
output("\n", string);
int minute = date.get_minute(now);
output("Minute: ", string);
output(minute, int);
output("\n", string);
int second = date.get_second(now);
output("Second: ", string);
output(second, int);
output("\n", string);
// Date arithmetic
output("\n4. Date Arithmetic:\n", string);
int tomorrow = date.add_days(now, 1);
output("Tomorrow: ", string);
output(date.format_date(tomorrow), string);
output("\n", string);
int nextWeek = date.add_days(now, 7);
output("Next week: ", string);
output(date.format_date(nextWeek), string);
output("\n", string);
int nextMonth = date.add_days(now, 30);
output("In 30 days: ", string);
output(date.format_date(nextMonth), string);
output("\n", string);
int inThreeHours = date.add_hours(now, 3);
output("In 3 hours: ", string);
output(date.format_time(inThreeHours), string);
output("\n", string);
// Date differences
output("\n5. Date Differences:\n", string);
int yesterday = date.add_days(now, -1);
int diffDays = date.diff_days(now, yesterday);
output("Days between now and yesterday: ", string);
output(diffDays, int);
output("\n", string);
int diffHours = date.diff_hours(inThreeHours, now);
output("Hours between now and 3 hours from now: ", string);
output(diffHours, int);
output("\n", string);
// Date properties
output("\n6. Date Properties:\n", string);
int isLeap = date.is_leap_year(now);
output("Is leap year: ", string);
if (isLeap == 1) {
output("Yes\n", string);
}
if (isLeap == 0) {
output("No\n", string);
}
int daysInMonth = date.days_in_month(now);
output("Days in current month: ", string);
output(daysInMonth, int);
output("\n", string);
// Start/end of day
output("\n7. Day Boundaries:\n", string);
int startDay = date.start_of_day(now);
output("Start of day: ", string);
output(date.format_time(startDay), string);
output("\n", string);
int endDay = date.end_of_day(now);
output("End of day: ", string);
output(date.format_time(endDay), string);
output("\n", string);
// Start/end of month
output("\n8. Month Boundaries:\n", string);
int startMonth = date.start_of_month(now);
output("Start of month: ", string);
output(date.format_date(startMonth), string);
output("\n", string);
int endMonth = date.end_of_month(now);
output("End of month: ", string);
output(date.format_date(endMonth), string);
output("\n", string);
// Parse dates
output("\n9. Parsing Dates:\n", string);
int parsed = date.parse_iso("2025-12-25T00:00:00");
output("Parsed Christmas 2025: ", string);
output(date.format_iso(parsed), string);
output("\n", string);
int customParsed = date.parse("2025/01/01", "%Y/%m/%d");
output("Parsed New Year 2025: ", string);
output(date.format_date(customParsed), string);
output("\n", string);
// Calculate days until Christmas
int daysUntilChristmas = date.diff_days(parsed, now);
output("\nDays until Christmas 2025: ", string);
output(daysUntilChristmas, int);
output("\n", string);
output("\n=== Test Complete ===\n", string);
return 0;
}