Skip to content

Commit 25596ee

Browse files
authored
fix: Implement SECSTODATE (#424)
fixes #403
1 parent f2dd2ed commit 25596ee

File tree

4 files changed

+20
-3
lines changed

4 files changed

+20
-3
lines changed

examples/Tests/datetest.opo

163 Bytes
Binary file not shown.

examples/Tests/datetest.txt

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
INCLUDE "DATE.OXH"
22

33
PROC main:
4-
LOCAL d&, dh&, epoch&
5-
LOCAL year%, month%, day%
4+
LOCAL d&, dh&, epoch&, s&
5+
LOCAL year%, month%, day%, hour%, min%, sec%, yday%
66

77
d& = DATETOSECS(1970, 1, 1, 0, 0, 0)
88
PRINT "DATETOSECS(1970, 1, 1, 0, 0, 0) = "; d&
@@ -32,5 +32,12 @@ PROC main:
3232
RAISE -1
3333
ENDIF
3434

35+
s& = 1727425745
36+
SECSTODATE s&, year%, month%, day%, hour%, min%, sec%, yday%
37+
PRINT "SECSTODATE", s&, "=", year%, month%, day%, hour%, min%, sec%, yday%
38+
IF year% <> 2024 OR month% <> 9 OR day% <> 27 OR hour% <> 8 OR min% <> 29 OR sec% <> 5 OR yday% <> 271
39+
RAISE -1
40+
ENDIF
41+
3542
GET
3643
ENDP

src/compiler.lua

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -586,6 +586,7 @@ Callables = {
586586
SCREEN = SpecialOp({Int, Int, Int, Int, numParams = {2, 4}}),
587587
SCREENINFO = Op("ScreenInfo", {IntArrayArg}),
588588
SECOND = Fn("Second", {}, Int),
589+
SECSTODATE = Op("SecsToDate", {Long, IntVarArg, IntVarArg, IntVarArg, IntVarArg, IntVarArg, IntVarArg, IntVarArg}),
589590
SETDOC = Op("SetDoc", {String}),
590591
SETFLAGS = Op("SetFlags", {Long}),
591592
SETPATH = Op("SetPath", {String}),

src/ops.lua

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2321,7 +2321,16 @@ function SetPath(stack, runtime) -- 0xFA
23212321
end
23222322

23232323
function SecsToDate(stack, runtime) -- 0xFB
2324-
unimplemented("SecsToDate")
2324+
local s, year, month, day, hour, min, sec, yday = stack:pop(8)
2325+
2326+
local d = os.date("!*t", s)
2327+
runtime:addrAsVariable(year, DataTypes.EWord)(d.year)
2328+
runtime:addrAsVariable(month, DataTypes.EWord)(d.month)
2329+
runtime:addrAsVariable(day, DataTypes.EWord)(d.day)
2330+
runtime:addrAsVariable(hour, DataTypes.EWord)(d.hour)
2331+
runtime:addrAsVariable(min, DataTypes.EWord)(d.min)
2332+
runtime:addrAsVariable(sec, DataTypes.EWord)(d.sec)
2333+
runtime:addrAsVariable(yday, DataTypes.EWord)(d.yday)
23252334
end
23262335

23272336
function gIPrint(stack, runtime) -- 0xFC

0 commit comments

Comments
 (0)