1
0
mirror of https://github.com/aclindsa/moneygo.git synced 2024-10-31 16:00:05 -04:00

lua: Add ability to add/subtract dates

This commit is contained in:
Aaron Lindsay 2017-02-11 07:28:15 -05:00
parent 5c7dc5df4c
commit 55d0e718c8

View File

@ -19,6 +19,8 @@ func luaRegisterDates(L *lua.LState) {
L.SetField(mt, "__eq", L.NewFunction(luaDate__eq)) L.SetField(mt, "__eq", L.NewFunction(luaDate__eq))
L.SetField(mt, "__lt", L.NewFunction(luaDate__lt)) L.SetField(mt, "__lt", L.NewFunction(luaDate__lt))
L.SetField(mt, "__le", L.NewFunction(luaDate__le)) L.SetField(mt, "__le", L.NewFunction(luaDate__le))
L.SetField(mt, "__add", L.NewFunction(luaDate__add))
L.SetField(mt, "__sub", L.NewFunction(luaDate__sub))
L.SetField(mt, "__metatable", lua.LString("protected")) L.SetField(mt, "__metatable", lua.LString("protected"))
} }
@ -146,3 +148,23 @@ func luaDate__le(L *lua.LState) int {
return 1 return 1
} }
func luaDate__add(L *lua.LState) int {
a := luaCheckTime(L, 1)
b := luaCheckTime(L, 2)
date := a.AddDate(b.Year(), int(b.Month()), b.Day())
L.Push(TimeToLua(L, &date))
return 1
}
func luaDate__sub(L *lua.LState) int {
a := luaCheckTime(L, 1)
b := luaCheckTime(L, 2)
date := a.AddDate(-b.Year(), -int(b.Month()), -b.Day())
L.Push(TimeToLua(L, &date))
return 1
}