From 3e59e5048d0f20debe4ad79b2e02ca2a76c5daed Mon Sep 17 00:00:00 2001 From: Tom Lane Date: Fri, 17 Mar 2023 17:47:15 -0400 Subject: Refactor datetime functions' timezone lookup code to reduce duplication. We already had five copies of essentially the same logic, and an upcoming patch introduces yet another use-case. That's past my threshold of pain, so introduce a common subroutine. There's not that much net code savings, but the chance of typos should go down. Inspired by a patch from Przemysław Sztoch, but different in detail. Discussion: https://postgr.es/m/01a84551-48dd-1359-bf7e-f6b0203a6bd0@sztoch.pl --- src/include/utils/datetime.h | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'src/include') diff --git a/src/include/utils/datetime.h b/src/include/utils/datetime.h index c8f78a9f1ec..a871e3223de 100644 --- a/src/include/utils/datetime.h +++ b/src/include/utils/datetime.h @@ -295,6 +295,11 @@ typedef struct DateTimeErrorExtra const char *dtee_abbrev; /* relevant time zone abbreviation */ } DateTimeErrorExtra; +/* Result codes for DecodeTimezoneName() */ +#define TZNAME_FIXED_OFFSET 0 +#define TZNAME_DYNTZ 1 +#define TZNAME_ZONE 2 + extern void GetCurrentDateTime(struct pg_tm *tm); extern void GetCurrentTimeUsec(struct pg_tm *tm, fsec_t *fsec, int *tzp); @@ -340,6 +345,9 @@ extern int DecodeTimezoneAbbrev(int field, const char *lowtoken, extern int DecodeSpecial(int field, const char *lowtoken, int *val); extern int DecodeUnits(int field, const char *lowtoken, int *val); +extern int DecodeTimezoneName(const char *tzname, int *offset, pg_tz **tz); +extern pg_tz *DecodeTimezoneNameToTz(const char *tzname); + extern int j2day(int date); extern struct Node *TemporalSimplify(int32 max_precis, struct Node *node); -- cgit v1.2.3