libdas2
das2 core C utilities
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
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 
31 #ifndef _das_time_h_
32 #define _das_time_h_
33 
34 #include <stdbool.h>
35 #include <stdint.h>
36 
37 #ifdef __cplusplus
38 extern "C" {
39 #endif
40 
47 typedef struct das_time_t{
48 
50  int year;
51 
53  int month;
54 
56  int mday;
57 
61  int yday;
62 
64  int hour;
65 
67  int minute;
68 
73  double second;
74 
75 } das_time;
76 
77 
82 void dt_null(das_time* pDt);
83 
84 
93 bool dt_parsetime(const char* string, das_time* dt);
94 
95 
100 bool dt_now(das_time* pDt);
101 
102 
107 void dt_from_1958(
108  unsigned short int daysSince1958, unsigned int msOfDay, das_time* dt
109 );
110 
119 int64_t dt_nano_1970(const das_time* dt);
120 
131 bool dt_in_range(
132  const das_time* begin, const das_time* end, const das_time* test
133 );
134 
139 void dt_copy(das_time* pDest, const das_time* pSrc);
140 
148 void dt_set(
149  das_time* pDt, int year, int month, int mday, int yday, int hour,
150  int minute, double second
151 );
152 
165 int dt_compare(const das_time* pA, const das_time* pB);
166 
167 
181 double dt_diff(const das_time* pA, const das_time* pB);
182 
199 char* dt_isoc(char* sBuf, size_t nLen, const das_time* pDt, int nFracSec);
200 
217 char* dt_isod(char* sBuf, size_t nLen, const das_time* pDt, int nFracSec);
218 
219 
237 char* dt_dual_str(char* sBuf, size_t nLen, const das_time* pDt, int nFracSec);
238 
239 
240 /* Julian Day at January 1, 1958, 12:00:00 UT */
241 #define EPOCH 2436205
242 
243 
261 double dt_ttime(const das_time* dt);
262 
269 void dt_emitt (double tt, das_time* dt);
270 
271 
283 void dt_tnorm(das_time* dt);
284 
285 /* return Julian Day number given year, month, and day */
286 int jday (int year, int month, int day);
287 
290 #ifdef __cplusplus
291 }
292 #endif
293 
294 #endif /* _das_time_h_ */
int dt_compare(const das_time *pA, const das_time *pB)
Compare to dastime structures.
double dt_ttime(const das_time *dt)
Convert time components to double seconds since January 1st 1958.
int yday
Integer Day of year, Jan.
Definition: time.h:61
bool dt_parsetime(const char *string, das_time *dt)
Convert most human-parseable time strings to numeric components.
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 mday
Calender Day of month, starts at 1.
Definition: time.h:56
double second
Second of the minute, range 0.0 to 60.0 - epsilon.
Definition: time.h:73
void dt_emitt(double tt, das_time *dt)
convert double seconds since epoch to time components.
int year
Calendar year number, cannot hold years before 1 AD.
Definition: time.h:50
bool dt_now(das_time *pDt)
Initialize a das_time to the current UTC time.
double dt_diff(const das_time *pA, const das_time *pB)
Get the difference of two das_time structures in seconds.
void dt_tnorm(das_time *dt)
Normalize date and time components.
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.
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.
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.
void dt_copy(das_time *pDest, const das_time *pSrc)
Simple helper to copy values from one das time to another.
int month
Calendar month number, 1 = January.
Definition: time.h:53
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 hour
Hour of day, range is 0 to 23.
Definition: time.h:64
int minute
Minute of the hour, range 0 to 59.
Definition: time.h:67
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.
Basic date-time structure used throughout the Das1 &amp; Das2 utilities.
Definition: time.h:47
int64_t dt_nano_1970(const das_time *dt)
Convert a das time to integer nanoseconds since 1970-01-01.
void dt_null(das_time *pDt)
Zero out all values in a das_time structrue.