das2C
das core C utilities (v3)
time.h
Go to the documentation of this file.
1 /* Copyright (C) 1997-2017 Larry Granroth <larry-granroth@uiowa.edu>
2  * Chris Piker <chris-piker@uiowa.edu>
3  *
4  * This file is part of libdas2, the Core Das2 C Library.
5  *
6  * Libdas2 is free software; you can redistribute it and/or modify it under
7  * the terms of the GNU Lesser General Public License version 2.1 as published
8  * by the Free Software Foundation.
9  *
10  * Libdas2 is distributed in the hope that it will be useful, but WITHOUT ANY
11  * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
12  * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for
13  * more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public License
16  * version 2.1 along with libdas2; if not, see <http://www.gnu.org/licenses/>.
17  */
18 
19 
26 #ifndef _das_time_h_
27 #define _das_time_h_
28 
29 #include <das2/defs.h>
30 
31 #ifdef __cplusplus
32 extern "C" {
33 #endif
34 
43 typedef struct das_time_t{
44 
46  int year;
47 
49  int month;
50 
52  int mday;
53 
57  int yday;
58 
60  int hour;
61 
63  int minute;
64 
69  double second;
70 
71 } das_time;
72 
76 /* A version of above that would only use 16 bytes instead of 32 ....
77  to implement and test later
78 
79 typedef struct das_time_t{
80  / ** Calendar month number, 1 = January * /
81  int8_t month;
82 
83  / ** Calender Day of month, starts at 1 * /
84  int8_t mday;
85 
86  / ** Hour of day, range is 0 to 23 * /
87  int8_t hour;
88 
89  / ** Minute of the hour, range 0 to 59 * /
90  int8_t minute;
91 
92  / ** Calendar year number, cannot hold years before 1 AD * /
93  int16_t year;
94 
95  / ** Integer Day of year, Jan. 1st = 1.
96  * This field is <b>output only</b> for most Das1 functions see the
97  * warning in dt_tnorm() * /
98  int16_t yday;
99 
100  / ** Second of the minute, range 0.0 to 60.0 - epsilon.
101  * Note, there is no provision for leap seconds in the library. All
102  * minutes are assumed to have 60 seconds.
103  * /
104  double second;
105 
106 } das_time;
107 */
108 
109 #define DAS_TIME_NULL {0, 0, 0, 0, 0, 0, 0.0}
110 
111 
117 DAS_API void dt_null(das_time* pDt);
118 
119 
128 DAS_API bool dt_parsetime(const char* string, das_time* dt);
129 
130 
136 DAS_API bool dt_now(das_time* pDt);
137 
138 
143 DAS_API void dt_from_1958(
144  unsigned short int daysSince1958, unsigned int msOfDay, das_time* dt
145 );
146 
155 DAS_API int64_t dt_nano_1970(const das_time* dt);
156 
167 DAS_API bool dt_in_range(
168  const das_time* begin, const das_time* end, const das_time* test
169 );
170 
175 DAS_API void dt_copy(das_time* pDest, const das_time* pSrc);
176 
184 DAS_API void dt_set(
185  das_time* pDt, int year, int month, int mday, int yday, int hour,
186  int minute, double second
187 );
188 
201 DAS_API int dt_compare(const das_time* pA, const das_time* pB);
202 
203 #define dt_cmp dt_compare
204 
205 
220 DAS_API double dt_diff(const das_time* pA, const das_time* pB);
221 
238 DAS_API char* dt_isoc(char* sBuf, size_t nLen, const das_time* pDt, int nFracSec);
239 
256 DAS_API char* dt_isod(char* sBuf, size_t nLen, const das_time* pDt, int nFracSec);
257 
258 
276 DAS_API char* dt_dual_str(char* sBuf, size_t nLen, const das_time* pDt, int nFracSec);
277 
278 
279 /* Julian Day at January 1, 1958, 12:00:00 UT */
280 #define EPOCH 2436205
281 
282 
300 DAS_API double dt_ttime(const das_time* dt);
301 
308 DAS_API void dt_emitt (double tt, das_time* dt);
309 
314 DAS_API int64_t dt_to_tt2k(const das_time* dt);
315 
320 DAS_API void dt_from_tt2k(das_time* dt, int64_t nTime);
321 
333 DAS_API void dt_tnorm(das_time* dt);
334 
335 /* return Julian Day number given year, month, and day, not exported no purpose */
336 int jday (int year, int month, int day);
337 
338 #ifdef __cplusplus
339 }
340 #endif
341 
342 #endif /* _das_time_h_ */
Minimal definitions for das2 utilities that can safely be run without calling das_init().
Basic date-time structure used throughout the Das1 & Das2 utilities.
Definition: time.h:43
double second
Second of the minute, range 0.0 to 60.0 - epsilon.
Definition: time.h:69
DAS_API void dt_from_1958(unsigned short int daysSince1958, unsigned int msOfDay, das_time *dt)
Get a das time given days since 1958 and optional milliseconds of day.
DAS_API double dt_ttime(const das_time *dt)
Convert time components to double seconds since January 1st 1958.
DAS_API double dt_diff(const das_time *pA, const das_time *pB)
Get the difference of two das_time structures in seconds.
int hour
Hour of day, range is 0 to 23.
Definition: time.h:60
DAS_API int64_t dt_nano_1970(const das_time *dt)
Convert a das time to integer nanoseconds since 1970-01-01.
DAS_API bool dt_now(das_time *pDt)
Initialize a das_time to the current UTC time.
DAS_API void dt_tnorm(das_time *dt)
Normalize date and time components.
DAS_API bool dt_in_range(const das_time *begin, const das_time *end, const das_time *test)
Test for time within a time range The the standard exclusive upper bound test.
DAS_API int dt_compare(const das_time *pA, const das_time *pB)
Compare to dastime structures.
DAS_API void dt_copy(das_time *pDest, const das_time *pSrc)
Simple helper to copy values from one das time to another.
DAS_API void dt_from_tt2k(das_time *dt, int64_t nTime)
Convert a TT2000 time to a time structure.
DAS_API char * dt_dual_str(char *sBuf, size_t nLen, const das_time *pDt, int nFracSec)
Print time a string that provides both day of month and day of year given a das_time structure.
int minute
Minute of the hour, range 0 to 59.
Definition: time.h:63
int mday
Calender Day of month, starts at 1.
Definition: time.h:52
int yday
Integer Day of year, Jan.
Definition: time.h:57
DAS_API char * dt_isod(char *sBuf, size_t nLen, const das_time *pDt, int nFracSec)
Print an ISOD standard time string given a das_time structure.
DAS_API bool dt_parsetime(const char *string, das_time *dt)
Convert most human-parseable time strings to numeric components.
DAS_API char * dt_isoc(char *sBuf, size_t nLen, const das_time *pDt, int nFracSec)
Print an ISOC standard time string given a das_time structure.
int year
Calendar year number, cannot hold years before 1 AD.
Definition: time.h:46
DAS_API void dt_set(das_time *pDt, int year, int month, int mday, int yday, int hour, int minute, double second)
Simple helper to set values in a das time.
DAS_API void dt_emitt(double tt, das_time *dt)
convert double seconds since epoch to time components.
int month
Calendar month number, 1 = January.
Definition: time.h:49
DAS_API int64_t dt_to_tt2k(const das_time *dt)
Convert a time structure to a TT2000 time.
DAS_API void dt_null(das_time *pDt)
Zero out all values in a das_time structrue.