From a79b3c2216d386e705603c6dcbf10c1c391fcd99 Mon Sep 17 00:00:00 2001 From: Bruce Hill Date: Fri, 28 Mar 2025 13:45:16 -0400 Subject: [PATCH] Rename `timezone` to avoid shadowing --- src/stdlib/moments.c | 80 ++++++++++++++++++++++---------------------- 1 file changed, 40 insertions(+), 40 deletions(-) diff --git a/src/stdlib/moments.c b/src/stdlib/moments.c index a48e40b..d1abdfb 100644 --- a/src/stdlib/moments.c +++ b/src/stdlib/moments.c @@ -63,7 +63,7 @@ public Moment_t Moment$now(void) return (Moment_t){.tv_sec=ts.tv_sec, .tv_usec=ts.tv_nsec/1000}; } -public Moment_t Moment$new(Int_t year, Int_t month, Int_t day, Int_t hour, Int_t minute, double second, OptionalText_t timezone) +public Moment_t Moment$new(Int_t year, Int_t month, Int_t day, Int_t hour, Int_t minute, double second, OptionalText_t tz) { struct tm info = { .tm_min=Int32$from_int(minute, false), @@ -75,17 +75,17 @@ public Moment_t Moment$new(Int_t year, Int_t month, Int_t day, Int_t hour, Int_t }; time_t t; - WITH_TIMEZONE(timezone, t = mktime(&info)); + WITH_TIMEZONE(tz, t = mktime(&info)); return (Moment_t){.tv_sec=t + (time_t)second, .tv_usec=(suseconds_t)(fmod(second, 1.0) * 1e9)}; } -public Moment_t Moment$after(Moment_t moment, double seconds, double minutes, double hours, Int_t days, Int_t weeks, Int_t months, Int_t years, OptionalText_t timezone) +public Moment_t Moment$after(Moment_t moment, double seconds, double minutes, double hours, Int_t days, Int_t weeks, Int_t months, Int_t years, OptionalText_t tz) { double offset = seconds + 60.*minutes + 3600.*hours; moment.tv_sec += (time_t)offset; struct tm info = {}; - WITH_TIMEZONE(timezone, localtime_r(&moment.tv_sec, &info)); + WITH_TIMEZONE(tz, localtime_r(&moment.tv_sec, &info)); info.tm_mday += Int32$from_int(days, false) + 7*Int32$from_int(weeks, false); info.tm_mon += Int32$from_int(months, false); @@ -115,10 +115,10 @@ CONSTFUNC public double Moment$hours_till(Moment_t now, Moment_t then) public void Moment$get( Moment_t moment, Int_t *year, Int_t *month, Int_t *day, Int_t *hour, Int_t *minute, Int_t *second, - Int_t *nanosecond, Int_t *weekday, OptionalText_t timezone) + Int_t *nanosecond, Int_t *weekday, OptionalText_t tz) { struct tm info = {}; - WITH_TIMEZONE(timezone, localtime_r(&moment.tv_sec, &info)); + WITH_TIMEZONE(tz, localtime_r(&moment.tv_sec, &info)); if (year) *year = I(info.tm_year + 1900); if (month) *month = I(info.tm_mon + 1); @@ -130,89 +130,89 @@ public void Moment$get( if (weekday) *weekday = I(info.tm_wday + 1); } -public Int_t Moment$year(Moment_t moment, OptionalText_t timezone) +public Int_t Moment$year(Moment_t moment, OptionalText_t tz) { struct tm info = {}; - WITH_TIMEZONE(timezone, localtime_r(&moment.tv_sec, &info)); + WITH_TIMEZONE(tz, localtime_r(&moment.tv_sec, &info)); return I(info.tm_year + 1900); } -public Int_t Moment$month(Moment_t moment, OptionalText_t timezone) +public Int_t Moment$month(Moment_t moment, OptionalText_t tz) { struct tm info = {}; - WITH_TIMEZONE(timezone, localtime_r(&moment.tv_sec, &info)); + WITH_TIMEZONE(tz, localtime_r(&moment.tv_sec, &info)); return I(info.tm_mon + 1); } -public Int_t Moment$day_of_week(Moment_t moment, OptionalText_t timezone) +public Int_t Moment$day_of_week(Moment_t moment, OptionalText_t tz) { struct tm info = {}; - WITH_TIMEZONE(timezone, localtime_r(&moment.tv_sec, &info)); + WITH_TIMEZONE(tz, localtime_r(&moment.tv_sec, &info)); return I(info.tm_wday + 1); } -public Int_t Moment$day_of_month(Moment_t moment, OptionalText_t timezone) +public Int_t Moment$day_of_month(Moment_t moment, OptionalText_t tz) { struct tm info = {}; - WITH_TIMEZONE(timezone, localtime_r(&moment.tv_sec, &info)); + WITH_TIMEZONE(tz, localtime_r(&moment.tv_sec, &info)); return I(info.tm_mday); } -public Int_t Moment$day_of_year(Moment_t moment, OptionalText_t timezone) +public Int_t Moment$day_of_year(Moment_t moment, OptionalText_t tz) { struct tm info = {}; - WITH_TIMEZONE(timezone, localtime_r(&moment.tv_sec, &info)); + WITH_TIMEZONE(tz, localtime_r(&moment.tv_sec, &info)); return I(info.tm_yday); } -public Int_t Moment$hour(Moment_t moment, OptionalText_t timezone) +public Int_t Moment$hour(Moment_t moment, OptionalText_t tz) { struct tm info = {}; - WITH_TIMEZONE(timezone, localtime_r(&moment.tv_sec, &info)); + WITH_TIMEZONE(tz, localtime_r(&moment.tv_sec, &info)); return I(info.tm_hour); } -public Int_t Moment$minute(Moment_t moment, OptionalText_t timezone) +public Int_t Moment$minute(Moment_t moment, OptionalText_t tz) { struct tm info = {}; - WITH_TIMEZONE(timezone, localtime_r(&moment.tv_sec, &info)); + WITH_TIMEZONE(tz, localtime_r(&moment.tv_sec, &info)); return I(info.tm_min); } -public Int_t Moment$second(Moment_t moment, OptionalText_t timezone) +public Int_t Moment$second(Moment_t moment, OptionalText_t tz) { struct tm info = {}; - WITH_TIMEZONE(timezone, localtime_r(&moment.tv_sec, &info)); + WITH_TIMEZONE(tz, localtime_r(&moment.tv_sec, &info)); return I(info.tm_sec); } -public Int_t Moment$microsecond(Moment_t moment, OptionalText_t timezone) +public Int_t Moment$microsecond(Moment_t moment, OptionalText_t tz) { - (void)timezone; + (void)tz; return I(moment.tv_usec); } -public Text_t Moment$format(Moment_t moment, Text_t fmt, OptionalText_t timezone) +public Text_t Moment$format(Moment_t moment, Text_t fmt, OptionalText_t tz) { struct tm info; - WITH_TIMEZONE(timezone, localtime_r(&moment.tv_sec, &info)); + WITH_TIMEZONE(tz, localtime_r(&moment.tv_sec, &info)); static char buf[256]; size_t len = strftime(buf, sizeof(buf), Text$as_c_string(fmt), &info); return Text$format("%.*s", (int)len, buf); } -public Text_t Moment$date(Moment_t moment, OptionalText_t timezone) +public Text_t Moment$date(Moment_t moment, OptionalText_t tz) { - return Moment$format(moment, Text("%F"), timezone); + return Moment$format(moment, Text("%F"), tz); } -public Text_t Moment$time(Moment_t moment, bool seconds, bool am_pm, OptionalText_t timezone) +public Text_t Moment$time(Moment_t moment, bool seconds, bool am_pm, OptionalText_t tz) { Text_t text; if (seconds) - text = Moment$format(moment, am_pm ? Text("%l:%M:%S%P") : Text("%T"), timezone); + text = Moment$format(moment, am_pm ? Text("%l:%M:%S%P") : Text("%T"), tz); else - text = Moment$format(moment, am_pm ? Text("%l:%M%P") : Text("%H:%M"), timezone); + text = Moment$format(moment, am_pm ? Text("%l:%M%P") : Text("%H:%M"), tz); return Text$trim(text, Pattern(" "), true, true); } @@ -228,7 +228,7 @@ public OptionalMoment_t Moment$parse(Text_t text, Text_t format) if (!invalid || invalid[0] != '\0') return NONE_MOMENT; - long offset = info.tm_gmtoff; // Need to cache this because mktime() mutates it to local timezone >:( + long offset = info.tm_gmtoff; // Need to cache this because mktime() mutates it to local tz >:( time_t t = mktime(&info); return (Moment_t){.tv_sec=t + offset - info.tm_gmtoff}; } @@ -240,11 +240,11 @@ static INLINE Text_t num_format(long n, const char *unit) return Text$format((n == 1 || n == -1) ? "%ld %s %s" : "%ld %ss %s", n < 0 ? -n : n, unit, n < 0 ? "ago" : "later"); } -public Text_t Moment$relative(Moment_t moment, Moment_t relative_to, OptionalText_t timezone) +public Text_t Moment$relative(Moment_t moment, Moment_t relative_to, OptionalText_t tz) { struct tm info = {}; struct tm relative_info = {}; - WITH_TIMEZONE(timezone, { + WITH_TIMEZONE(tz, { localtime_r(&moment.tv_sec, &info); localtime_r(&relative_to.tv_sec, &relative_info); }); @@ -282,14 +282,14 @@ CONSTFUNC public Moment_t Moment$from_unix_timestamp(Int64_t timestamp) return (Moment_t){.tv_sec=(time_t)timestamp}; } -public void Moment$set_local_timezone(OptionalText_t timezone) +public void Moment$set_local_timezone(OptionalText_t tz) { - if (timezone.length >= 0) { - setenv("TZ", Text$as_c_string(timezone), 1); + if (tz.length >= 0) { + setenv("TZ", Text$as_c_string(tz), 1); } else { unsetenv("TZ"); } - _local_timezone = timezone; + _local_timezone = tz; tzset(); } @@ -299,13 +299,13 @@ public Text_t Moment$get_local_timezone(void) static char buf[PATH_MAX]; ssize_t len = readlink("/etc/localtime", buf, sizeof(buf)); if (len < 0) - fail("Could not get local timezone!"); + fail("Could not get local tz!"); char *zoneinfo = strstr(buf, "/zoneinfo/"); if (zoneinfo) _local_timezone = Text$from_str(zoneinfo + strlen("/zoneinfo/")); else - fail("Could not resolve local timezone!"); + fail("Could not resolve local tz!"); } return _local_timezone; }