Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue #417: support nil params on os.date() #420

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions _glua-tests/issues.lua
Original file line number Diff line number Diff line change
Expand Up @@ -404,3 +404,15 @@ function test()
assert(2 % 2 == 0)
end
test()

-- issue #417
function test()
assert(type(os.date(nil)) == "string")
assert(type(os.date(nil, nil)) == "string")
local t = os.time()
assert(os.date(nil, t) == os.date("%c", t))
assert(os.date(2) == "2")
local ok, msg = pcall(os.date, {})
assert(not ok and string.find(msg, "string expected, got table", 1, true))
end
test()
9 changes: 7 additions & 2 deletions oslib.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,13 +108,18 @@ func osDate(L *LState) int {
t := time.Now()
cfmt := "%c"
if L.GetTop() >= 1 {
cfmt = L.CheckString(1)
lv := L.Get(1)
if LVCanConvToString(lv) {
cfmt = lv.String()
} else if lv != LNil {
L.TypeError(1, LTString)
}
if strings.HasPrefix(cfmt, "!") {
t = time.Now().UTC()
cfmt = strings.TrimLeft(cfmt, "!")
}
if L.GetTop() >= 2 {
t = time.Unix(L.CheckInt64(2), 0)
t = time.Unix(L.OptInt64(2, t.Unix()), 0)
}
if strings.HasPrefix(cfmt, "*t") {
ret := L.NewTable()
Expand Down