unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
From: ashish.is@lostca.se (Ashish SHUKLA)
To: Paul Eggert <eggert@cs.ucla.edu>
Cc: 19874@debbugs.gnu.org
Subject: bug#19874: 25.0.50; encode-time not working as expected
Date: Thu, 26 Feb 2015 05:54:19 +0530	[thread overview]
Message-ID: <86sidta5ak.fsf@chateau.d.if> (raw)
In-Reply-To: <54EE0959.5080901@cs.ucla.edu> (Paul Eggert's message of "Wed, 25 Feb 2015 09:41:45 -0800")


[-- Attachment #1.1: Type: text/plain, Size: 2874 bytes --]

On Wed, 25 Feb 2015 09:41:45 -0800, Paul Eggert <eggert@cs.ucla.edu> said:
| Thanks for the bug report.  My guess is that there's an
| incompatibility with FreeBSD 10.1 amd64 mktime.  I can't reproduce the
| problem on FreeBSD 9.1 x86.

| Please try the attached patch, just for debugging, and then run the
| following one-line shell command:

| src/emacs -Q -batch -eval '(progn (setenv "TZ" "Asia/Kolkata") (print
| (encode-time 44 42 6 15 2 2015 0 nil 0)))'

| What output do you get?  Here's what I get on Fedora 21 x86-64, which seems correct:

| oldtz=Asia/Kolkata tz=XXX-0:00:00 oldTZ=Asia/Kolkata TZ=XXX-0:00:00
| 2015-02-15 06:42:44 -1 -> 2015-02-15 06:42:44 0 = 1423982564

| Assuming you get different output, can you debug Emacs with GDB to
| send us more details about what's going wrong?  If not, can you give
| me access to a FreeBSD 10.1 amd64 machine like yours?

Hi,

When I looked into this before filing this bug report, from what I noticed
that it's not using libc's `mktime' function, unlike what you seem to
indicate. I'm not sure quite why it's doing that when libc provided mktime
works just fine, as evident by output of attached program:

--8<---------------cut here---------------start------------->8---
% ./gmtime
Staying at localtime zone
Time (in seconds): 1423962764
Updated environment
Switching to UTC
Time (in seconds): 1423982564
Didn't update environment
Switching to UTC+1
Time (in seconds): 1423978964
Didn't update environment
Switching to UTC+3
Time (in seconds): 1423971764
--8<---------------cut here---------------end--------------->8---

--8<---------------cut here---------------start------------->8---
>>> print gmtime(1423962764)
time.struct_time(tm_year=2015, tm_mon=2, tm_mday=15, tm_hour=1, tm_min=12, tm_sec=44, tm_wday=6, tm_yday=46, tm_isdst=0)
>>> print gmtime(1423982564)
time.struct_time(tm_year=2015, tm_mon=2, tm_mday=15, tm_hour=6, tm_min=42, tm_sec=44, tm_wday=6, tm_yday=46, tm_isdst=0)
>>> print gmtime(1423978964)
time.struct_time(tm_year=2015, tm_mon=2, tm_mday=15, tm_hour=5, tm_min=42, tm_sec=44, tm_wday=6, tm_yday=46, tm_isdst=0)
>>> print gmtime(1423971764)
time.struct_time(tm_year=2015, tm_mon=2, tm_mday=15, tm_hour=3, tm_min=42, tm_sec=44, tm_wday=6, tm_yday=46, tm_isdst=0)
--8<---------------cut here---------------end--------------->8---

The built-in mktime implementation (__mktime_internal) in Emacs sources don't
seem to take into account timezone offsets. I might be completely wrong here,
but the code seemed to be doing it.

I'll get back to you with the output of your command-line from patched Emacs
in few, but the results of my past investigation were handy so I've attached
them.

HTH
-- 
Ashish SHUKLA

“"Intellectual Property" is nowhere near as valuable as "Intellect"” ("Ion-Mihai Tetcu")

Sent from my Emacs

[-- Attachment #1.2: gmtime.c --]
[-- Type: text/plain, Size: 1141 bytes --]

#include <time.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#define BUFSIZE 256

void
settz(const char* tz)
{
	static char *tzvalbuf;
	static size_t tzvalbufsize;

	if( tzvalbufsize <= 3 + strlen(tz)) {
		tzvalbuf = malloc(tzvalbufsize = BUFSIZE);
		snprintf( tzvalbuf, BUFSIZE, "TZ=%s", tz );
		putenv( tzvalbuf );
		puts( "Updated environment" );
	} else {
		puts( "Didn't update environment" );
		snprintf( tzvalbuf, BUFSIZE, "TZ=%s", tz );
	}
	tzset();
}

int
main()
{
	struct tm t = {
		.tm_sec = 44,
		.tm_min = 42,
		.tm_hour = 6,
		.tm_mday = 15,
		.tm_mon = 2 - 1,
		.tm_year = 2015 - 1900,
		.tm_isdst = -1,
	};
	time_t val;

	puts( "Staying at localtime zone" );
	val = mktime( &t );
	printf( "Time (in seconds): %ld\n", val );
	settz( "TZ=XXX-0:00:00" );
	puts( "Switching to UTC" );
	val = mktime( &t );
	printf( "Time (in seconds): %ld\n", val );
	settz( "TZ=XXX-1:00:00" );
	puts( "Switching to UTC+1" );
	val = mktime( &t );
	printf( "Time (in seconds): %ld\n", val );
	settz( "TZ=XXX-3:00:00" );
	puts( "Switching to UTC+3" );
	val = mktime( &t );
	printf( "Time (in seconds): %ld\n", val );

	return 0;
}

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 818 bytes --]

  reply	other threads:[~2015-02-26  0:24 UTC|newest]

Thread overview: 34+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-02-15 13:40 bug#19874: 25.0.50; encode-time not working as expected Ashish SHUKLA
2015-02-15 23:33 ` Ashish SHUKLA
2015-02-25 17:41 ` Paul Eggert
2015-02-26  0:24   ` Ashish SHUKLA [this message]
2015-02-26  8:15     ` Paul Eggert
2015-02-26 13:42       ` Wolfgang Jenkner
2015-02-26 17:36         ` Wolfgang Jenkner
2015-02-26 17:58         ` Paul Eggert
2015-02-26 16:03       ` Ashish SHUKLA
2015-02-26  6:51   ` Ashish SHUKLA
2015-02-26  8:39     ` Paul Eggert
2015-02-26 15:58       ` Ashish SHUKLA
2015-02-27  5:13         ` Paul Eggert
2015-02-26 19:00 ` Wolfgang Jenkner
2015-02-26 19:44   ` Ashish SHUKLA
2015-02-26 20:05     ` Wolfgang Jenkner
2015-02-26 21:47       ` Ashish SHUKLA
2015-02-27  0:16         ` Wolfgang Jenkner
2015-02-27  2:51         ` Wolfgang Jenkner
2015-02-27  4:59           ` Ashish SHUKLA
2015-02-27  6:38             ` Paul Eggert
2015-02-27  8:09             ` Paul Eggert
2015-02-27  8:49               ` Ashish SHUKLA
2015-02-27  6:31   ` Paul Eggert
2015-02-27  8:28 ` Ashish SHUKLA
2015-02-27 16:41   ` Paul Eggert
2015-02-27 17:33 ` Wolfgang Jenkner
2015-02-27 23:54   ` Paul Eggert
2015-02-28 14:10     ` Wolfgang Jenkner
2015-02-28 14:18       ` Wolfgang Jenkner
2015-02-28 19:43       ` Paul Eggert
2015-03-01 16:42 ` Wolfgang Jenkner
2015-03-01 18:28   ` Paul Eggert
2015-03-01 22:49 ` Wolfgang Jenkner

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=86sidta5ak.fsf@chateau.d.if \
    --to=ashish.is@lostca.se \
    --cc=19874@debbugs.gnu.org \
    --cc=eggert@cs.ucla.edu \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).