Contains time-related functions: mtime(), convert_date_time(), mtimes().
- Copyright
- (c) 2002 The University of Chicago, as Operator of Argonne National Laboratory.
- (c) 2002 The Regents of the University of California, as Operator of Los Alamos National Laboratory.
- License
- This file is distributed under the terms of the Software License Agreement found in the file LICENSE included with this distribution.
- Author
- M. Borland, C. Saunders, R. Soliday
Definition in file time.c.
#include "mdb.h"
#include "time_utils.h"
#include <ctype.h>
#include <time.h>
Go to the source code of this file.
|
| char * | mtime (void) |
| | Generates a formatted time string.
|
| |
| char * | mtimes (void) |
| | Generates a detailed formatted time string.
|
| |
◆ mtime()
Generates a formatted time string.
This function returns a compact local time string.
Format Comparison:
ctime: "wkd mmm dd hh:mm:ss 19yy\n"
mtime: "dd mmm yy hh:mm"
- Returns
- A pointer to the newly allocated formatted time string.
Definition at line 102 of file time.c.
102 {
103 char *mt;
104 struct tm timeBreakdown;
105 time_t i;
106
107 while ((mt =
tmalloc((
unsigned)30 *
sizeof(*mt))) == NULL)
108 puts("allocation failure in mtime()");
109 time(&i);
110 if (!mdb_localtime_copy(&i, &timeBreakdown)) {
111 mt[0] = 0;
112 return mt;
113 }
114
115 sprintf(mt, "%d %s %02d %02d:%02d",
116 timeBreakdown.tm_mday,
117 MonthAbbreviation[timeBreakdown.tm_mon],
118 (timeBreakdown.tm_year + 1900) % 100,
119 timeBreakdown.tm_hour,
120 timeBreakdown.tm_min);
121 return (mt);
122}
void * tmalloc(uint64_t size_of_block)
Allocates a memory block of the specified size with zero initialization.
◆ mtimes()
Generates a detailed formatted time string.
This function returns a compact local time string including seconds.
Format Comparison:
ctime: "wkd mmm dd hh:mm:ss 19yy\n"
mtimes: "dd mmm yy hh:mm:ss"
- Returns
- A pointer to the newly allocated detailed formatted time string.
Definition at line 135 of file time.c.
135 {
136 char *mt;
137 struct tm timeBreakdown;
138 time_t i;
139
140 while ((mt =
tmalloc((
unsigned)30 *
sizeof(*mt))) == NULL)
141 puts("allocation failure in mtime()");
142 time(&i);
143 if (!mdb_localtime_copy(&i, &timeBreakdown)) {
144 mt[0] = 0;
145 return mt;
146 }
147
148 sprintf(mt, "%d %s %02d %02d:%02d:%02d",
149 timeBreakdown.tm_mday,
150 MonthAbbreviation[timeBreakdown.tm_mon],
151 (timeBreakdown.tm_year + 1900) % 100,
152 timeBreakdown.tm_hour,
153 timeBreakdown.tm_min,
154 timeBreakdown.tm_sec);
155 return (mt);
156}