Skip to content

Commit 1de9416

Browse files
committed
fix: include string
1 parent d8b2f49 commit 1de9416

File tree

5 files changed

+34
-2
lines changed

5 files changed

+34
-2
lines changed

datetime.gs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
%include inflator/time
2+
%include inflator/string
23

34
%include inflator/datetime/src/struct
45
%include inflator/datetime/src/to
6+
%include inflator/datetime/src/get

demo/main.gs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,8 @@ costumes "blank.svg";
44

55
onflag {main;}
66
proc main {
7-
say dt_str(DT_NOW());
7+
local datetime d = DT_NOW();
8+
say dt_str(d);
9+
10+
say dt_get_weekday_number(d);
811
}

inflator.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,5 @@ version = "v0.0.0"
44
username = "inflated-goboscript"
55

66
[dependencies]
7-
time = "time"
7+
time = "time"
8+
string = "string"

src/get.gs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# 'getter functions' for datetime struct
2+
3+
list DT_WEEKDAYS = [
4+
"Monday",
5+
"Tuesday",
6+
"Wednesday",
7+
"Thursday",
8+
"Friday",
9+
"Saturday",
10+
"Sunday"
11+
];
12+
13+
# Get the day of the week for a date `$d`
14+
# https://www.geeksforgeeks.org/dsa/zellers-congruence-find-day-date/
15+
func dt_get_weekday_number(datetime d) {
16+
# 0 = Saturday, 1 = Sunday, 2 = Monday, ..., 6 = Friday
17+
# uses zeller's rule
18+
local q = $d.day;
19+
local m = $d.month;
20+
local K = $d.year % 100;
21+
local J = $d.year // 100;
22+
23+
return floor(q + (13*(m+1))/5 + K + K/4 + J/4 + 5*J) % 7;
24+
}

src/struct.gs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
# Struct definition and constructors
22

3+
# also serves the same role as python's datetime.date
4+
# Gregorian date
35
struct datetime {
46
year = 1970,
57
month = 1,

0 commit comments

Comments
 (0)