ptsname_r: Fix test failures on IRIX, Solaris.
[gnulib.git] / tests / test-parse-datetime.c
index b9d08a6..4c0370d 100644 (file)
@@ -1,5 +1,5 @@
 /* Test of parse_datetime() function.
-   Copyright (C) 2008-2011 Free Software Foundation, Inc.
+   Copyright (C) 2008-2012 Free Software Foundation, Inc.
 
    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
@@ -12,8 +12,7 @@
    GNU General Public License for more details.
 
    You should have received a copy of the GNU General Public License
-   along with this program; if not, write to the Free Software Foundation,
-   Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.  */
+   along with this program; if not, see <http://www.gnu.org/licenses/>.  */
 
 /* Written by Simon Josefsson <simon@josefsson.org>, 2008.  */
 
@@ -30,7 +29,7 @@
 
 #ifdef DEBUG
 #define LOG(str, now, res)                                              \
-  printf ("string `%s' diff %d %d\n",                   \
+  printf ("string '%s' diff %d %d\n",                                 \
           str, res.tv_sec - now.tv_sec, res.tv_nsec - now.tv_nsec);
 #else
 #define LOG(str, now, res) (void) 0
@@ -94,20 +93,17 @@ tm_diff (struct tm const *a, struct tm const *b)
 #endif /* ! HAVE_TM_GMTOFF */
 
 static long
-gmt_offset ()
+gmt_offset (time_t s)
 {
-  time_t now;
   long gmtoff;
 
-  time (&now);
-
 #if !HAVE_TM_GMTOFF
-  struct tm tm_local = *localtime (&now);
-  struct tm tm_gmt   = *gmtime (&now);
+  struct tm tm_local = *localtime (&s);
+  struct tm tm_gmt   = *gmtime (&s);
 
   gmtoff = tm_diff (&tm_local, &tm_gmt);
 #else
-  gmtoff = localtime (&now)->tm_gmtoff;
+  gmtoff = localtime (&s)->tm_gmtoff;
 #endif
 
   return gmtoff;
@@ -123,16 +119,17 @@ main (int argc _GL_UNUSED, char **argv)
   const char *p;
   int i;
   long gmtoff;
+  time_t ref_time = 1304250918;
 
   set_program_name (argv[0]);
 
-  gmtoff = gmt_offset ();
+  gmtoff = gmt_offset (ref_time);
 
 
   /* ISO 8601 extended date and time of day representation,
      'T' separator, local time zone */
   p = "2011-05-01T11:55:18";
-  expected.tv_sec = 1304250918 - gmtoff;
+  expected.tv_sec = ref_time - gmtoff;
   expected.tv_nsec = 0;
   ASSERT (parse_datetime (&result, p, 0));
   LOG (p, expected, result);
@@ -142,7 +139,7 @@ main (int argc _GL_UNUSED, char **argv)
   /* ISO 8601 extended date and time of day representation,
      ' ' separator, local time zone */
   p = "2011-05-01 11:55:18";
-  expected.tv_sec = 1304250918 - gmtoff;
+  expected.tv_sec = ref_time - gmtoff;
   expected.tv_nsec = 0;
   ASSERT (parse_datetime (&result, p, 0));
   LOG (p, expected, result);
@@ -153,7 +150,7 @@ main (int argc _GL_UNUSED, char **argv)
   /* ISO 8601, extended date and time of day representation,
      'T' separator, UTC */
   p = "2011-05-01T11:55:18Z";
-  expected.tv_sec = 1304250918;
+  expected.tv_sec = ref_time;
   expected.tv_nsec = 0;
   ASSERT (parse_datetime (&result, p, 0));
   LOG (p, expected, result);
@@ -163,7 +160,7 @@ main (int argc _GL_UNUSED, char **argv)
   /* ISO 8601, extended date and time of day representation,
      ' ' separator, UTC */
   p = "2011-05-01 11:55:18Z";
-  expected.tv_sec = 1304250918;
+  expected.tv_sec = ref_time;
   expected.tv_nsec = 0;
   ASSERT (parse_datetime (&result, p, 0));
   LOG (p, expected, result);