68aa3a78461cbdb868a6b30cc21bde58bbde4759
[pspp-builds.git] / src / libpspp / start-date.c
1 /* PSPP - computes sample statistics.
2    Copyright (C) 1997-9, 2000, 2006 Free Software Foundation, Inc.
3
4    This program is free software; you can redistribute it and/or
5    modify it under the terms of the GNU General Public License as
6    published by the Free Software Foundation; either version 2 of the
7    License, or (at your option) any later version.
8
9    This program is distributed in the hope that it will be useful, but
10    WITHOUT ANY WARRANTY; without even the implied warranty of
11    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12    General Public License for more details.
13
14    You should have received a copy of the GNU General Public License
15    along with this program; if not, write to the Free Software
16    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
17    02110-1301, USA. */
18
19 #include <config.h>
20 #include "start-date.h"
21 #include <time.h>
22 #include "str.h"
23 #include "strftime.h"
24
25 /* Writes the current date into CUR_DATE in the format DD MMM
26    YYYY. */
27 static void
28 get_cur_date (char cur_date[12])
29 {
30   time_t now = time (NULL);
31   if (now != (time_t) -1)
32     {
33       struct tm *tm = localtime (&now);
34       if (tm != NULL)
35         {
36           strftime (cur_date, 12, "%d %b %Y", tm);
37           return;
38         }
39     }
40   strcpy (cur_date, "?? ??? 2???");
41 }
42
43 /* Returns the date at which PSPP was started, as a string in the
44    format DD MMM YYYY. */
45 const char *
46 get_start_date (void)
47 {
48   static char start_date[12];
49   if (start_date[0] == '\0')
50     get_cur_date (start_date);
51   return start_date;
52 }