feat: remove timezone abbreviation from !time response
The !time command now outputs only date and time (YYYY-MM-DD HH:MM:SS) without the timezone abbreviation. This keeps responses shorter and cleaner in IRC. Removed the dead abbreviation-matching code from tz_format() which previously mapped 45 IANA timezone names to their respective abbreviations (CEST, EDT, JST, etc.). Updated README to reflect the new output format.
This commit is contained in:
parent
c3e92b27b1
commit
9ba0601f5a
2 changed files with 12 additions and 72 deletions
|
|
@ -112,7 +112,7 @@ make CC=clang CFLAGS="-O2 -Wall -Wextra"
|
||||||
|
|
||||||
Shows the current date and time. Without arguments, displays the bot's local time. With a timezone argument, displays the time in that timezone using POSIX `TZ` format.
|
Shows the current date and time. Without arguments, displays the bot's local time. With a timezone argument, displays the time in that timezone using POSIX `TZ` format.
|
||||||
|
|
||||||
**Output format:** `YYYY-MM-DD HH:MM:SS TZ`
|
**Output format:** `YYYY-MM-DD HH:MM:SS`
|
||||||
|
|
||||||
**Examples:**
|
**Examples:**
|
||||||
|
|
||||||
|
|
|
||||||
82
zynk.c
82
zynk.c
|
|
@ -2803,90 +2803,30 @@ static const TzEntry *tz_lookup(const char *name) {
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* tz_format - Format a timestamp with timezone abbreviation.
|
* tz_format - Format a timestamp with a given UTC offset.
|
||||||
*
|
*
|
||||||
* Converts a Unix epoch timestamp plus UTC offset into a human-readable
|
* Converts a Unix epoch timestamp plus UTC offset into a human-readable
|
||||||
* string like "2025-07-20 14:30:00 CEST". Maps internal timezone names
|
* string like "2025-07-20 14:30:00". Used as a fallback when the system
|
||||||
* to their correct abbreviations, handling DST-aware names (e.g.
|
* lacks tzdata and cannot resolve IANA timezone names via localtime_r.
|
||||||
* "Europe/Berlin" becomes "CEST" in summer, "CET" in winter). Falls
|
|
||||||
* back to "UTC" for offset 0 if no other abbreviation matches.
|
|
||||||
*
|
*
|
||||||
* Parameters:
|
* Parameters:
|
||||||
* epoch - The Unix epoch timestamp to format.
|
* epoch - The Unix epoch timestamp to format.
|
||||||
* offset - The UTC offset in seconds (positive for east of UTC).
|
* offset - The UTC offset in seconds (positive for east of UTC).
|
||||||
* tzname - The IANA timezone name used for abbreviation lookup.
|
* tzname - The IANA timezone name (unused, kept for API compatibility).
|
||||||
* is_dst - Whether DST is currently in effect for this timezone.
|
* is_dst - Whether DST is currently in effect (unused).
|
||||||
* buf - Output buffer for the formatted string.
|
* buf - Output buffer for the formatted string.
|
||||||
* buflen - Size of the output buffer.
|
* buflen - Size of the output buffer.
|
||||||
*
|
*
|
||||||
* Returns: void (result written to buf).
|
* Returns: void (result written to buf).
|
||||||
*/
|
*/
|
||||||
static void tz_format(time_t epoch, int offset, const char *tzname, int is_dst, char *buf, size_t buflen) {
|
static void tz_format(time_t epoch, int offset, const char *tzname, int is_dst, char *buf, size_t buflen) {
|
||||||
|
(void)tzname; (void)is_dst;
|
||||||
time_t local = epoch + offset;
|
time_t local = epoch + offset;
|
||||||
struct tm tm;
|
struct tm tm;
|
||||||
gmtime_r(&local, &tm);
|
gmtime_r(&local, &tm);
|
||||||
const char *abbr = tzname;
|
snprintf(buf, buflen, "%04d-%02d-%02d %02d:%02d:%02d",
|
||||||
if (strcmp(tzname, "US/Eastern") == 0 || strcmp(tzname, "America/Toronto") == 0 || strcmp(tzname, "Canada/Toronto") == 0)
|
|
||||||
abbr = is_dst ? "EDT" : "EST";
|
|
||||||
else if (strcmp(tzname, "US/Central") == 0)
|
|
||||||
abbr = is_dst ? "CDT" : "CST";
|
|
||||||
else if (strcmp(tzname, "US/Mountain") == 0)
|
|
||||||
abbr = is_dst ? "MDT" : "MST";
|
|
||||||
else if (strcmp(tzname, "US/Pacific") == 0 || strcmp(tzname, "America/Vancouver") == 0 || strcmp(tzname, "Canada/Vancouver") == 0)
|
|
||||||
abbr = is_dst ? "PDT" : "PST";
|
|
||||||
else if (strcmp(tzname, "US/Alaska") == 0)
|
|
||||||
abbr = is_dst ? "AKDT" : "AKST";
|
|
||||||
else if (strcmp(tzname, "Europe/London") == 0 || strcmp(tzname, "Atlantic/Reykjavik") == 0)
|
|
||||||
abbr = is_dst ? "BST" : "GMT";
|
|
||||||
else if (strcmp(tzname, "Europe/Berlin") == 0 || strcmp(tzname, "Europe/Paris") == 0)
|
|
||||||
abbr = is_dst ? "CEST" : "CET";
|
|
||||||
else if (strcmp(tzname, "Europe/Moscow") == 0 || strcmp(tzname, "Europe/Istanbul") == 0)
|
|
||||||
abbr = "MSK";
|
|
||||||
else if (strcmp(tzname, "Asia/Tokyo") == 0)
|
|
||||||
abbr = "JST";
|
|
||||||
else if (strcmp(tzname, "Asia/Shanghai") == 0 || strcmp(tzname, "Asia/Hong_Kong") == 0 || strcmp(tzname, "Asia/Taipei") == 0)
|
|
||||||
abbr = "CST";
|
|
||||||
else if (strcmp(tzname, "Asia/Kolkata") == 0)
|
|
||||||
abbr = "IST";
|
|
||||||
else if (strcmp(tzname, "Asia/Dubai") == 0)
|
|
||||||
abbr = "GST";
|
|
||||||
else if (strcmp(tzname, "Asia/Singapore") == 0)
|
|
||||||
abbr = "SGT";
|
|
||||||
else if (strcmp(tzname, "Asia/Seoul") == 0)
|
|
||||||
abbr = "KST";
|
|
||||||
else if (strcmp(tzname, "Australia/Sydney") == 0 || strcmp(tzname, "Australia/Melbourne") == 0)
|
|
||||||
abbr = is_dst ? "AEDT" : "AEST";
|
|
||||||
else if (strcmp(tzname, "Australia/Brisbane") == 0)
|
|
||||||
abbr = "AEST";
|
|
||||||
else if (strcmp(tzname, "Australia/Perth") == 0)
|
|
||||||
abbr = "AWST";
|
|
||||||
else if (strcmp(tzname, "Australia/Adelaide") == 0)
|
|
||||||
abbr = is_dst ? "ACDT" : "ACST";
|
|
||||||
else if (strcmp(tzname, "Australia/Darwin") == 0)
|
|
||||||
abbr = "ACST";
|
|
||||||
else if (strcmp(tzname, "Pacific/Auckland") == 0)
|
|
||||||
abbr = is_dst ? "NZDT" : "NZST";
|
|
||||||
else if (strcmp(tzname, "Pacific/Fiji") == 0)
|
|
||||||
abbr = is_dst ? "FJDT" : "FJST";
|
|
||||||
else if (strcmp(tzname, "America/Sao_Paulo") == 0)
|
|
||||||
abbr = is_dst ? "BRT" : "BRST";
|
|
||||||
else if (strcmp(tzname, "America/Mexico_City") == 0)
|
|
||||||
abbr = is_dst ? "CDT" : "CST";
|
|
||||||
else if (strcmp(tzname, "America/Argentina/Buenos_Aires") == 0)
|
|
||||||
abbr = "ART";
|
|
||||||
else if (strcmp(tzname, "Africa/Cairo") == 0)
|
|
||||||
abbr = "EET";
|
|
||||||
else if (strcmp(tzname, "Africa/Johannesburg") == 0)
|
|
||||||
abbr = "SAST";
|
|
||||||
else if (strcmp(tzname, "Africa/Lagos") == 0)
|
|
||||||
abbr = "WAT";
|
|
||||||
else if (strcmp(tzname, "Africa/Nairobi") == 0)
|
|
||||||
abbr = "EAT";
|
|
||||||
else if (offset == 0)
|
|
||||||
abbr = "UTC";
|
|
||||||
snprintf(buf, buflen, "%04d-%02d-%02d %02d:%02d:%02d %s",
|
|
||||||
tm.tm_year + 1900, tm.tm_mon + 1, tm.tm_mday,
|
tm.tm_year + 1900, tm.tm_mon + 1, tm.tm_mday,
|
||||||
tm.tm_hour, tm.tm_min, tm.tm_sec, abbr);
|
tm.tm_hour, tm.tm_min, tm.tm_sec);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
@ -2937,8 +2877,8 @@ static int cmd_time(Session *s, const char *msg, const char *reply_target, const
|
||||||
int system_works = (sys_offset != 0 || strcasecmp(tzname, "UTC") == 0 || strcasecmp(tzname, "GMT") == 0);
|
int system_works = (sys_offset != 0 || strcasecmp(tzname, "UTC") == 0 || strcasecmp(tzname, "GMT") == 0);
|
||||||
if (system_works) {
|
if (system_works) {
|
||||||
char buf[64];
|
char buf[64];
|
||||||
strftime(buf, sizeof buf, "%Y-%m-%d %H:%M:%S %Z", &local_tm);
|
strftime(buf, sizeof buf, "%Y-%m-%d %H:%M:%S", &local_tm);
|
||||||
snprintf(resp, sizeof resp, "%s: %s %s", src_nick, tzname, buf);
|
snprintf(resp, sizeof resp, "%s: %s", src_nick, buf);
|
||||||
} else {
|
} else {
|
||||||
const TzEntry *tz = tz_lookup(tzname);
|
const TzEntry *tz = tz_lookup(tzname);
|
||||||
if (tz) {
|
if (tz) {
|
||||||
|
|
@ -2961,7 +2901,7 @@ static int cmd_time(Session *s, const char *msg, const char *reply_target, const
|
||||||
time_t now = time(NULL);
|
time_t now = time(NULL);
|
||||||
struct tm *tm = localtime(&now);
|
struct tm *tm = localtime(&now);
|
||||||
char buf[64];
|
char buf[64];
|
||||||
strftime(buf, sizeof buf, "%Y-%m-%d %H:%M:%S %Z", tm);
|
strftime(buf, sizeof buf, "%Y-%m-%d %H:%M:%S", tm);
|
||||||
snprintf(resp, sizeof resp, "%s: %s", src_nick, buf);
|
snprintf(resp, sizeof resp, "%s: %s", src_nick, buf);
|
||||||
}
|
}
|
||||||
irc_msg(s, reply_target, resp);
|
irc_msg(s, reply_target, resp);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue