plum
git clone https://git.pyrossh.dev/plum
A statically typed, imperative programming language inspired by rust, python
710607b
— Peter John
2026-09-03T20:20:17+05:30
refactor(libs/std): move Duration's unit constructors to static methods
- libs/std/time.plum +23 -23
libs/std/time.plum
CHANGED
|
@@ -118,6 +118,21 @@ fun floorMod(a: Int, b: Int) -> Int =
|
|
|
118
118
|
type Duration =
|
|
119
119
|
value: Int
|
|
120
120
|
|
|
121
|
+
fun millis(n: Int) -> Duration =
|
|
122
|
+
return Duration(value: n)
|
|
123
|
+
|
|
124
|
+
fun seconds(n: Int) -> Duration =
|
|
125
|
+
return Duration(value: n * 1000)
|
|
126
|
+
|
|
127
|
+
fun minutes(n: Int) -> Duration =
|
|
128
|
+
return Duration(value: n * 60000)
|
|
129
|
+
|
|
130
|
+
fun hours(n: Int) -> Duration =
|
|
131
|
+
return Duration(value: n * 3600000)
|
|
132
|
+
|
|
133
|
+
fun days(n: Int) -> Duration =
|
|
134
|
+
return Duration(value: n * MILLIS_PER_DAY)
|
|
135
|
+
|
|
121
136
|
fun toMillis(self) -> Int =
|
|
122
137
|
return self.value
|
|
123
138
|
|
|
@@ -148,21 +163,6 @@ type Duration =
|
|
|
148
163
|
fun equals(self, other: Duration) -> Bool =
|
|
149
164
|
return self.value == other.value
|
|
150
165
|
|
|
151
|
-
fun millis(n: Int) -> Duration =
|
|
152
|
-
return Duration(value: n)
|
|
153
|
-
|
|
154
|
-
fun seconds(n: Int) -> Duration =
|
|
155
|
-
return Duration(value: n * 1000)
|
|
156
|
-
|
|
157
|
-
fun minutes(n: Int) -> Duration =
|
|
158
|
-
return Duration(value: n * 60000)
|
|
159
|
-
|
|
160
|
-
fun hours(n: Int) -> Duration =
|
|
161
|
-
return Duration(value: n * 3600000)
|
|
162
|
-
|
|
163
|
-
fun days(n: Int) -> Duration =
|
|
164
|
-
return Duration(value: n * MILLIS_PER_DAY)
|
|
165
|
-
|
|
166
166
|
test "Time.toStr formats the epoch as ISO 8601 in UTC"
|
|
167
167
|
expect Time(value: 0).toStr() == "1970-01-01T00:00:00.000Z"
|
|
168
168
|
|
|
@@ -182,12 +182,12 @@ test "Time accessors handle instants before the epoch correctly"
|
|
|
182
182
|
expect t.toStr() == "1969-12-31T23:59:59.000Z"
|
|
183
183
|
|
|
184
184
|
test "Duration arithmetic and unit constructors compute correctly"
|
|
185
|
-
expect seconds(90).toMillis() == 90000
|
|
185
|
+
expect Duration.seconds(90).toMillis() == 90000
|
|
186
|
-
expect minutes(2).toMillis() == 120000
|
|
186
|
+
expect Duration.minutes(2).toMillis() == 120000
|
|
187
|
-
expect hours(1).toMillis() == 3600000
|
|
187
|
+
expect Duration.hours(1).toMillis() == 3600000
|
|
188
|
-
expect days(1).toMillis() == 86400000
|
|
188
|
+
expect Duration.days(1).toMillis() == 86400000
|
|
189
|
-
expect seconds(90).negate().toMillis() == -90000
|
|
189
|
+
expect Duration.seconds(90).negate().toMillis() == -90000
|
|
190
|
-
expect seconds(90).negate().abs().toMillis() == 90000
|
|
190
|
+
expect Duration.seconds(90).negate().abs().toMillis() == 90000
|
|
191
191
|
expect Duration(value: 0).isZero() == True
|
|
192
|
-
expect seconds(1).isBefore(seconds(2)) == True
|
|
192
|
+
expect Duration.seconds(1).isBefore(Duration.seconds(2)) == True
|
|
193
|
-
expect seconds(2).isAfter(seconds(1)) == True
|
|
193
|
+
expect Duration.seconds(2).isAfter(Duration.seconds(1)) == True
|