MCPcopy Create free account
hub / github.com/dop251/goja / parseDateISOString

Function parseDateISOString

date_parser.go:184–245  ·  view source on GitHub ↗
(s string)

Source from the content-addressed store, hash-verified

182}
183
184func parseDateISOString(s string) (date, bool) {
185 if len(s) == 0 {
186 return date{}, false
187 }
188 var d = date{month: 1, day: 1}
189 var ok bool
190
191 // year is either yyyy digits or [+-]yyyyyy
192 sign := s[0]
193 if sign == '-' || sign == '+' {
194 s = s[1:]
195 if d.year, s, ok = getDigits(s, 6, 6); !ok {
196 return date{}, false
197 }
198 if sign == '-' {
199 if d.year == 0 {
200 // reject -000000
201 return date{}, false
202 }
203 d.year = -d.year
204 }
205 } else if d.year, s, ok = getDigits(s, 4, 4); !ok {
206 return date{}, false
207 }
208 if s, ok = skip(s, '-'); ok {
209 if d.month, s, ok = getDigits(s, 2, 2); !ok || d.month < 1 {
210 return date{}, false
211 }
212 if s, ok = skip(s, '-'); ok {
213 if d.day, s, ok = getDigits(s, 2, 2); !ok || d.day < 1 {
214 return date{}, false
215 }
216 }
217 }
218 if s, ok = skip(s, 'T'); ok {
219 if d.hour, s, ok = getDigits(s, 2, 2); !ok {
220 return date{}, false
221 }
222 if s, ok = skip(s, ':'); !ok {
223 return date{}, false
224 }
225 if d.min, s, ok = getDigits(s, 2, 2); !ok {
226 return date{}, false
227 }
228 if s, ok = skip(s, ':'); ok {
229 if d.sec, s, ok = getDigits(s, 2, 2); !ok {
230 return date{}, false
231 }
232 d.msec, s = getMilliseconds(s)
233 }
234 d.isLocal = true
235 }
236 // parse the time zone offset if present
237 if len(s) > 0 {
238 if d.timeZoneOffset, s, ok = getTimeZoneOffset(s, true); !ok {
239 return date{}, false
240 }
241 d.isLocal = false

Callers 1

dateParseFunction · 0.85

Calls 4

getDigitsFunction · 0.85
skipFunction · 0.85
getMillisecondsFunction · 0.85
getTimeZoneOffsetFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…