MCPcopy
hub / github.com/yuin/gopher-lua / osDate

Function osDate

oslib.go:106–140  ·  view source on GitHub ↗
(L *LState)

Source from the content-addressed store, hash-verified

104}
105
106func osDate(L *LState) int {
107 t := time.Now()
108 isUTC := false
109 cfmt := "%c"
110 if L.GetTop() >= 1 {
111 cfmt = L.CheckString(1)
112 if strings.HasPrefix(cfmt, "!") {
113 cfmt = strings.TrimLeft(cfmt, "!")
114 isUTC = true
115 }
116 if L.GetTop() >= 2 {
117 t = time.Unix(L.CheckInt64(2), 0)
118 }
119 if isUTC {
120 t = t.UTC()
121 }
122 if strings.HasPrefix(cfmt, "*t") {
123 ret := L.NewTable()
124 ret.RawSetString("year", LNumber(t.Year()))
125 ret.RawSetString("month", LNumber(t.Month()))
126 ret.RawSetString("day", LNumber(t.Day()))
127 ret.RawSetString("hour", LNumber(t.Hour()))
128 ret.RawSetString("min", LNumber(t.Minute()))
129 ret.RawSetString("sec", LNumber(t.Second()))
130 ret.RawSetString("wday", LNumber(t.Weekday()+1))
131 // TODO yday & dst
132 ret.RawSetString("yday", LNumber(0))
133 ret.RawSetString("isdst", LFalse)
134 L.Push(ret)
135 return 1
136 }
137 }
138 L.Push(LString(strftime(t, cfmt)))
139 return 1
140}
141
142func osGetEnv(L *LState) int {
143 v := os.Getenv(L.CheckString(1))

Callers

nothing calls this directly

Calls 9

LNumberTypeAlias · 0.85
LStringTypeAlias · 0.85
strftimeFunction · 0.85
CheckStringMethod · 0.80
CheckInt64Method · 0.80
RawSetStringMethod · 0.80
PushMethod · 0.65
GetTopMethod · 0.45
NewTableMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…