Hi Jeff:

Am 27.03.17 15:28 schrieb(en) Jeffrey Stedfast via balsa-list:
When the timezone is "EDT" or "-0400", g_time_zone_new(const char *name) 
returns a GTimeZone just fine and I pass it off to g_date_time_new(), but if I then ask for the UTC 
offset from the GDateTime, I get back 0.

If I change the string to "EST" or "-0500", everything works perfectly and I 
get back exactly the UTC offset that I would expect (-5 hours).

I guess the GLib functions (like tzset) use the iana zone info data base 
(<https://www.iana.org/time-zones>).  On my Ubuntu 16.04 system it is living in the 
folder /usr/share/zoneinfo.  But there is no "EDT" (or other daylight saving, like 
CEST) definition file.

I wrote the tiny attached test app - passing "EDT" or "CEST" as 1st parameter fails as you described.  
Passing "EST" or "CET" or *any* numerical offset, including "-0400", returns the proper result.  If 
the time zone names are given, of course depending upon the input date:

---8<----------------------------------------------------------------------------------
albrecht@deneb:~/Work$ ./gdatetimetest CET $(date +%s)
** Message: 1490643491 = 19:38:11 2017-03-27: interval 95: offset vs. UTC = 120 
minutes
albrecht@deneb:~/Work$ ./gdatetimetest CET 1490000000
** Message: 1490000000 = 08:53:20 2017-03-20: interval 94: offset vs. UTC = 60 
minutes
albrecht@deneb:~/Work$ ./gdatetimetest +0100 $(date +%s)
** Message: 1490643494 = 19:38:14 2017-03-27: interval 0: offset vs. UTC = 60 
minutes
---8<----------------------------------------------------------------------------------

Do you get a different result when using the pure libc functions (i.e. set TZ, use 
tzset(), and then localtime())?  At least running the "date" command from the 
console with TZ set to a dst time zone will /also/ return UTC:

---8<----------------------------------------------------------------------------------
albrecht@deneb:~/Work$ TZ=CET date
Mo 27. Mär 21:53:22 CEST 2017
albrecht@deneb:~/Work$ TZ=CEST date
Mo 27. Mär 19:53:24 CEST 2017
albrecht@deneb:~/Work$ TZ=UTC date
Mo 27. Mär 19:53:37 UTC 2017
---8<----------------------------------------------------------------------------------

Hope this helps,
Albrecht.
#include <glib.h>
#include <time.h>
#include <stdlib.h>

int main(int argc, char **argv)
{
	GTimeZone *tz;
	time_t ref_time;
	char buf[64];
	gint interval;

	g_assert(argc >= 3);
	tz = g_time_zone_new(argv[1]);
	ref_time = (time_t) strtol(argv[2], NULL, 0);
	interval = g_time_zone_find_interval(tz, G_TIME_TYPE_UNIVERSAL, ref_time);
	strftime(buf, sizeof(buf), "%T %F", gmtime(&ref_time));
	g_message("%ld = %s: interval %d: offset vs. UTC = %d minutes",
		(long int) ref_time, buf, interval, g_time_zone_get_offset(tz, interval) / 60);
	g_time_zone_unref(tz);
	return 0;
}

Attachment: pgprBNHSiOPkl.pgp
Description: PGP signature

_______________________________________________
balsa-list mailing list
[email protected]
https://mail.gnome.org/mailman/listinfo/balsa-list

Reply via email to