das2C
das core C utilities (v3)
Loading...
Searching...
No Matches
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 das2C, the Core Das2 C Library.
5 *
6 * Das2C 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 * Das2C 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 das2C; if not, see <http://www.gnu.org/licenses/>.
17 */
18
19
26#ifndef _das_time_h_
27#define _das_time_h_
28
29#include <das3/defs.h>
30
31#ifdef __cplusplus
32extern "C" {
33#endif
34
43typedef 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 enable and test later
78
79typedef struct das_time_t{
80 / ** Calendar month number, 1 = January * /
81 int8_t month;
82
83 / ** Calendar 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
117DAS_API void dt_null(das_time* pDt);
118
119
128DAS_API bool dt_parsetime(das_time* pDt, const char* sTime);
129
130
136DAS_API bool dt_now(das_time* pDt);
137
138
148DAS_API void dt_from_1958(
149 das_time* pDt, unsigned short int daysSince1958, unsigned int msOfDay
150);
151
160DAS_API int64_t dt_nano_1970(const das_time* dt);
161
172DAS_API bool dt_in_range(
173 const das_time* begin, const das_time* end, const das_time* test
174);
175
180DAS_API void dt_copy(das_time* pDest, const das_time* pSrc);
181
189DAS_API void dt_set(
190 das_time* pDt, int year, int month, int mday, int yday, int hour,
191 int minute, double second
192);
193
206DAS_API int dt_compare(const das_time* pA, const das_time* pB);
207
208
223DAS_API double dt_diff(const das_time* pA, const das_time* pB);
224
243DAS_API char* dt_isoc(const das_time* pDt, char* sBuf, size_t uLen, int nFracSec);
244
263DAS_API char* dt_isod(const das_time* pDt, char* sBuf, size_t uLen, int nFracSec);
264
265
285DAS_API char* dt_dual_str(const das_time* pDt, char* sBuf, size_t uLen, int nFracSec);
286
287
288/* Julian Day at January 1, 1958, 12:00:00 UT */
289#define EPOCH 2436205
290
291
309DAS_API double dt_ttime(const das_time* dt);
310
321DAS_API void dt_emitt(das_time* pDt, double tt);
322
323/* Returned by dt_to_tt2k() for fields outside the TT2000 range or with
324 negative members. Also defined in tt2000.c, which is not installed; the
325 two must stay the same value. */
326#ifndef ILLEGAL_TT2000_VALUE
327#define ILLEGAL_TT2000_VALUE (-9223372036854775805LL)
328#endif
329
338DAS_API int64_t dt_to_tt2k(const das_time* dt);
339
347DAS_API void dt_from_tt2k(das_time* dt, int64_t nTime);
348
373 int year, int month, int mday, int hour, int minute, int second,
374 int32_t nanosec, int64_t* pTT
375);
376
387DAS_API void tt2k_to_parts(
388 int64_t nTT, int* pYear, int* pMonth, int* pMday, int* pHour,
389 int* pMinute, int* pSecond, int32_t* pNanosec
390);
391
407DAS_API void dt_tnorm(das_time* dt);
408
409/* return Julian Day number given year, month, and day, not exported no purpose */
410int jday (int year, int month, int day);
411
412#ifdef __cplusplus
413}
414#endif
415
416#endif /* _das_time_h_ */
Minimal definitions for das2 utilities that can safely be run without calling das_init().
int DasErrCode
return code type 0 indicates success, negative integer indicates failure
Definition defs.h:189
Basic date-time structure used throughout the Das1 & Das2 utilities.
Definition time.h:43
double second
Second of the minute.
Definition time.h:69
DAS_API double dt_ttime(const das_time *dt)
Convert time components to double seconds since January 1st 1958.
#define dt_parsetime(S, T)
Convert most human-parseable time strings to numeric components.
#define dt_isoc(B, N, T, F)
Print an ISOC standard time string given a das_time structure.
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
#define dt_dual_str(B, N, T, F)
Print time a string that provides both day of month and day of year given a das_time structure.
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.
int minute
Minute of the hour, range 0 to 59.
Definition time.h:63
#define dt_isod(B, N, T, F)
Print an ISOD standard time string given a das_time structure.
int mday
Calendar Day of month, starts at 1.
Definition time.h:52
int yday
Integer Day of year, Jan.
Definition time.h:57
#define dt_from_1958(D, MS, T)
Get a das time given days since 1958 and optional milliseconds of day.
int year
Calendar year number, cannot hold years before 1 AD.
Definition time.h:46
#define dt_emitt(TT, T)
convert double seconds since epoch to time components.
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.
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 structure.
DAS_API DasErrCode tt2k_from_parts(int year, int month, int mday, int hour, int minute, int second, int32_t nanosec, int64_t *pTT)
Convert broken out UTC fields to TT2000, without floating point seconds.
DAS_API void tt2k_to_parts(int64_t nTT, int *pYear, int *pMonth, int *pMday, int *pHour, int *pMinute, int *pSecond, int32_t *pNanosec)
Break a TT2000 time into UTC fields, without floating point seconds.