Skip to content

Commit

Permalink
fix: Implement WEEK()
Browse files Browse the repository at this point in the history
fixes #438
  • Loading branch information
tomsci committed Oct 13, 2024
1 parent 1733021 commit d477f34
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 1 deletion.
Binary file modified examples/Tests/datetest.opo
Binary file not shown.
7 changes: 7 additions & 0 deletions examples/Tests/datetest.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ INCLUDE "DATE.OXH"
PROC main:
LOCAL d&, dh&, epoch&, s&
LOCAL year%, month%, day%, hour%, min%, sec%, yday%
LOCAL week%

d& = DATETOSECS(1970, 1, 1, 0, 0, 0)
PRINT "DATETOSECS(1970, 1, 1, 0, 0, 0) = "; d&
Expand Down Expand Up @@ -39,5 +40,11 @@ PROC main:
RAISE -1
ENDIF

week% = WEEK(30, 9, 2024)
PRINT "WEEK(30, 9, 2024) = "; week%
IF week% <> 40
RAISE -1
ENDIF

GET
ENDP
6 changes: 5 additions & 1 deletion src/fns.lua
Original file line number Diff line number Diff line change
Expand Up @@ -506,7 +506,11 @@ function SAddr(stack, runtime) -- 0x1F
end

function Week(stack, runtime) -- 0x20
unimplemented("fns.Week")
local dd, mm, yy = stack:pop(3)
local t = os.time({ day = dd, month = mm, year = yy })
-- %V matches LCSTARTOFWEEK which always returns Monday
local week = assert(tonumber(os.date("%V", t)))
stack:push(week)
end

function IoSeek(stack, runtime) -- 0x21
Expand Down

0 comments on commit d477f34

Please sign in to comment.