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

Function parseDateOtherString

date_parser.go:247–426  ·  view source on GitHub ↗
(s string)

Source from the content-addressed store, hash-verified

245}
246
247func parseDateOtherString(s string) (date, bool) {
248 var d = date{
249 year: 2001,
250 month: 1,
251 day: 1,
252 isLocal: true,
253 }
254 var nums [3]int
255 var numIndex int
256 var hasYear, hasMon, hasTime, ok bool
257 for {
258 s = skipSpaces(s)
259 if len(s) == 0 {
260 break
261 }
262 c := s[0]
263 n, val := len(s), 0
264 if c == '+' || c == '-' {
265 if hasTime {
266 if val, s, ok = getTimeZoneOffset(s, false); ok {
267 d.timeZoneOffset = val
268 d.isLocal = false
269 }
270 }
271 if !hasTime || !ok {
272 s = s[1:]
273 if val, s, ok = getDigits(s, 1, 9); ok {
274 d.year = val
275 if c == '-' {
276 if d.year == 0 {
277 return date{}, false
278 }
279 d.year = -d.year
280 }
281 hasYear = true
282 }
283 }
284 } else if val, s, ok = getDigits(s, 1, 9); ok {
285 if s, ok = skip(s, ':'); ok {
286 // time part
287 d.hour = val
288 if d.min, s, ok = getDigits(s, 1, 2); !ok {
289 return date{}, false
290 }
291 if s, ok = skip(s, ':'); ok {
292 if d.sec, s, ok = getDigits(s, 1, 2); !ok {
293 return date{}, false
294 }
295 d.msec, s = getMilliseconds(s)
296 }
297 hasTime = true
298 if t := skipSpaces(s); len(t) > 0 {
299 if t, ok = match(t, "pm"); ok {
300 if d.hour < 12 {
301 d.hour += 12
302 }
303 s = t
304 continue

Callers 1

dateParseFunction · 0.85

Calls 9

skipSpacesFunction · 0.85
getTimeZoneOffsetFunction · 0.85
getDigitsFunction · 0.85
skipFunction · 0.85
getMillisecondsFunction · 0.85
matchFunction · 0.85
getMonthFunction · 0.85
skipUntilFunction · 0.85
getTimeZoneAbbrFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…