1 /*****************************************************************************\
2 * slurm_time.c - assorted time functions
3 *****************************************************************************
4 * This file is part of Slurm, a resource management program.
5 * For details, see <https://slurm.schedmd.com/>.
6 * Please also read the included file: DISCLAIMER.
7 *
8 * Slurm is free software; you can redistribute it and/or modify it under
9 * the terms of the GNU General Public License as published by the Free
10 * Software Foundation; either version 2 of the License, or (at your option)
11 * any later version.
12 *
13 * In addition, as a special exception, the copyright holders give permission
14 * to link the code of portions of this program with the OpenSSL library under
15 * certain conditions as described in each individual source file, and
16 * distribute linked combinations including the two. You must obey the GNU
17 * General Public License in all respects for all of the code used other than
18 * OpenSSL. If you modify file(s) with this exception, you may extend this
19 * exception to your version of the file(s), but you are not obligated to do
20 * so. If you do not wish to do so, delete this exception statement from your
21 * version. If you delete this exception statement from all source files in
22 * the program, then also delete it here.
23 *
24 * Slurm is distributed in the hope that it will be useful, but WITHOUT ANY
25 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
26 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
27 * details.
28 *
29 * You should have received a copy of the GNU General Public License along
30 * with Slurm; if not, write to the Free Software Foundation, Inc.,
31 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
32 \*****************************************************************************/
33
34 #include <stdio.h>
35 #include <time.h>
36
slurm_mktime(struct tm * tp)37 extern time_t slurm_mktime(struct tm *tp)
38 {
39 /* Force tm_isdt to -1. */
40 tp->tm_isdst = -1;
41 return mktime(tp);
42 }
43
44 /* Slurm variants of ctime and ctime_r without a trailing new-line */
slurm_ctime2(const time_t * timep)45 extern char *slurm_ctime2(const time_t *timep)
46 {
47 struct tm newtime;
48 static char time_str[25];
49 localtime_r(timep, &newtime);
50
51 strftime(time_str, sizeof(time_str), "%a %b %d %T %Y", &newtime);
52
53 return time_str;
54 }
55
slurm_ctime2_r(const time_t * timep,char * time_str)56 extern char *slurm_ctime2_r(const time_t *timep, char *time_str)
57 {
58 struct tm newtime;
59 localtime_r(timep, &newtime);
60
61 strftime(time_str, 25, "%a %b %d %T %Y", &newtime);
62
63 return time_str;
64 }
65
print_date(void)66 extern void print_date(void)
67 {
68 time_t now = time(NULL);
69 char time_str[25];
70
71 printf("%s\n", slurm_ctime2_r(&now, time_str));
72 }
73