libtime++: Date and time calculation
ctime_sprint.c
Go to the documentation of this file.
1 /* this is <ctime_sprint.c>
2  * ----------------------------------------------------------------------------
3  *
4  * Copyright 2000 by Thomas Forbriger (IfG Stuttgart)
5  *
6  * ----
7  * libtime is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation; either version 2 of the License, or
10  * (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program; if not, write to the Free Software
19  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
20  * ----
21  *
22  * libtime C kernel function
23  *
24  * NOTICE: This routine returns a pointer to a static character array. The
25  * next call to time_sprint will destroy the contents of this string.
26  *
27  * REVISIONS and CHANGES
28  * 06/08/2000 V1.0 Thomas Forbriger
29  * 17/12/2007 V1.1 use integer type
30  * 12/12/2008 V1.2 use dots not slashes in the date string
31  * 19/07/2010 V1.3 Daniel Armbruster: cast of variables to (int)
32  *
33  * ============================================================================
34  */
35 
36 #include <libtime.h>
37 #include <stdio.h>
38 
39 char *time_sprint(time_Ts Date)
40 {
41  integer day;
42  integer month;
43  static char sdate[TIME_SLEN];
44 
45  time_norm(&Date);
46 
47  if (Date.year == 0L) {
48  sprintf(sdate, "%03dd %02dh %02dm %02d.%03d%03ds", (int)Date.doy,
49  (int)Date.hour, (int)Date.minute, (int)Date.second, (int)Date.milsec, (int)Date.micsec);
50  } else {
51  time_getdate(&day, &month, Date);
52  sprintf(sdate, "%03d %02d.%02d.%04d %02d:%02d:%02d.%03d%03d",
53  (int)Date.doy, (int)day, (int)month, (int)Date.year,
54  (int)Date.hour, (int)Date.minute, (int)Date.second, (int)Date.milsec, (int)Date.micsec);
55  }
56  return(sdate);
57 } /* time_setdoy */
58 
59 /* ----- END OF ctime_sprint.c ----- */
integer milsec
Definition: libtime.h:127
char * time_sprint(time_Ts Date)
Definition: ctime_sprint.c:39
integer minute
Definition: libtime.h:125
integer hour
Definition: libtime.h:124
integer doy
Definition: libtime.h:123
void time_getdate(timeint *day, timeint *month, time_Ts Date)
Definition: ctime_getdate.c:36
void time_norm(time_Ts *Pdate)
Definition: ctime_norm.c:33
integer second
Definition: libtime.h:126
long int integer
Definition: libtime.h:64
integer year
Definition: libtime.h:122
integer micsec
Definition: libtime.h:128
#define TIME_SLEN
Definition: libtime.h:113