1 /* PO/POT file timestamps.
2 Copyright (C) 1995-1998, 2000-2003, 2006 Free Software Foundation, Inc.
3 Written by Ulrich Drepper <drepper@gnu.ai.mit.edu>, April 1995.
5 This program is free software: you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 3 of the License, or
8 (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>. */
25 #include "xvasprintf.h"
28 #define TM_YEAR_ORIGIN 1900
30 /* Yield A - B, measured in seconds. */
32 difftm (const struct tm *a, const struct tm *b)
34 int ay = a->tm_year + TM_YEAR_ORIGIN - 1;
35 int by = b->tm_year + TM_YEAR_ORIGIN - 1;
36 /* Some compilers cannot handle this as a single return statement. */
38 /* difference in day of year */
39 a->tm_yday - b->tm_yday
40 /* + intervening leap days */
41 + ((ay >> 2) - (by >> 2))
42 - (ay / 100 - by / 100)
43 + ((ay / 100 >> 2) - (by / 100 >> 2))
44 /* + difference in years * 365 */
45 + (long) (ay - by) * 365l);
47 return 60l * (60l * (24l * days + (a->tm_hour - b->tm_hour))
48 + (a->tm_min - b->tm_min))
49 + (a->tm_sec - b->tm_sec);
54 po_strftime (const time_t *tp)
60 local_time = *localtime (tp);
62 tz_min = difftm (&local_time, gmtime (tp)) / 60;
68 return xasprintf ("%d-%02d-%02d %02d:%02d%c%02ld%02ld",
69 local_time.tm_year + TM_YEAR_ORIGIN,
70 local_time.tm_mon + 1,
74 tz_sign, tz_min / 60, tz_min % 60);