diff options
| author | Bruce Hill <bruce@bruce-hill.com> | 2025-03-30 17:27:52 -0400 |
|---|---|---|
| committer | Bruce Hill <bruce@bruce-hill.com> | 2025-03-30 17:27:52 -0400 |
| commit | 8cba6c3c24c2122c843aa0feaa26fd6e5c2412e2 (patch) | |
| tree | ae0583da790de2416f03a27e9f94953be7d4a803 /src/parse.c | |
| parent | d853d7b8dc1586f6b2fad3bf05998bfbe935b8f3 (diff) | |
Deprecate built-in Moment datatype in favor of a `time` module
Diffstat (limited to 'src/parse.c')
| -rw-r--r-- | src/parse.c | 55 |
1 files changed, 0 insertions, 55 deletions
diff --git a/src/parse.c b/src/parse.c index 5e2894f0..5190d92c 100644 --- a/src/parse.c +++ b/src/parse.c @@ -120,7 +120,6 @@ static PARSER(parse_holding); static PARSER(parse_if); static PARSER(parse_inline_c); static PARSER(parse_int); -static PARSER(parse_moment); static PARSER(parse_lambda); static PARSER(parse_lang_def); static PARSER(parse_mutexed); @@ -498,59 +497,6 @@ PARSER(parse_int) { return NewAST(ctx->file, start, pos, Int, .str=str); } -PARSER(parse_moment) { - const char *start = pos; - bool negative = match(&pos, "-"); - if (!isdigit(*pos)) return NULL; - - struct tm info = {.tm_isdst=-1}; - char *after = strptime(pos, "%Y-%m-%d", &info); - if (!after) return NULL; - if (negative) info.tm_year = -(info.tm_year + 1900) - 1900; - pos = after; - if (match(&pos, "T") || spaces(&pos) >= 1) { - after = strptime(pos, "%H:%M", &info); - if (after) { - pos = after; - after = strptime(pos, ":%S", &info); - if (after) pos = after; - // TODO parse nanoseconds - } - } - - const char *before_spaces = pos; - spaces(&pos); - Moment_t moment; - if (match(&pos, "[")) { - size_t tz_len = strcspn(pos, "\r\n]"); - const char *tz = heap_strf("%.*s", tz_len, pos); - // TODO: check that tz is a valid timezone - pos += tz_len; - expect_closing(ctx, &pos, "]", "I wasn't able to parse the rest of this moment timezone"); - const char *old_tz = getenv("TZ"); - setenv("TZ", tz, 1); - tzset(); - moment = (Moment_t){.tv_sec=mktime(&info)}; - if (old_tz) setenv("TZ", old_tz, 1); - else unsetenv("TZ"); - } else if (*pos == 'Z' || *pos == '-' || *pos == '+') { - after = strptime(pos, "%z", &info); - if (after) { - pos = after; - long offset = info.tm_gmtoff; // Need to cache this because mktime() mutates it to local timezone >:( - time_t t = mktime(&info); - moment = (Moment_t){.tv_sec=t + offset - info.tm_gmtoff}; - } else { - moment = (Moment_t){.tv_sec=mktime(&info)}; - } - } else { - pos = before_spaces; - moment = (Moment_t){.tv_sec=mktime(&info)}; - } - - return NewAST(ctx->file, start, pos, Moment, .moment=moment); -} - type_ast_t *parse_table_type(parse_ctx_t *ctx, const char *pos) { const char *start = pos; if (!match(&pos, "{")) return NULL; @@ -1590,7 +1536,6 @@ PARSER(parse_term_no_suffix) { ast_t *term = NULL; (void)( false - || (term=parse_moment(ctx, pos)) // Must come before num/int || (term=parse_none(ctx, pos)) || (term=parse_num(ctx, pos)) // Must come before int || (term=parse_int(ctx, pos)) |
