Change license from GPLv2+ to GPLv3+.
[pspp-builds.git] / src / libpspp / start-date.c
1 /* PSPP - a program for statistical analysis.
2    Copyright (C) 1997-9, 2000, 2006 Free Software Foundation, Inc.
3
4    This program is free software: you can redistribute it and/or modify
5    it under the terms of the GNU General Public License as published by
6    the Free Software Foundation, either version 3 of the License, or
7    (at your option) any later version.
8
9    This program is distributed in the hope that it will be useful,
10    but WITHOUT ANY WARRANTY; without even the implied warranty of
11    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12    GNU 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, see <http://www.gnu.org/licenses/>. */
16
17 #include <config.h>
18 #include "start-date.h"
19 #include <time.h>
20 #include "str.h"
21 #include "strftime.h"
22
23 /* Writes the current date into CUR_DATE in the format DD MMM
24    YYYY. */
25 static void
26 get_cur_date (char cur_date[12])
27 {
28   time_t now = time (NULL);
29   if (now != (time_t) -1)
30     {
31       struct tm *tm = localtime (&now);
32       if (tm != NULL)
33         {
34           strftime (cur_date, 12, "%d %b %Y", tm);
35           return;
36         }
37     }
38   strcpy (cur_date, "?? ??? 2???");
39 }
40
41 /* Returns the date at which PSPP was started, as a string in the
42    format DD MMM YYYY. */
43 const char *
44 get_start_date (void)
45 {
46   static char start_date[12];
47   if (start_date[0] == '\0')
48     get_cur_date (start_date);
49   return start_date;
50 }