Strict C++ compliance.
[asdcplib.git] / src / KM_tai.h
1 /*
2
3 THIS IS A SUBSET OF THE FULL LIBTAI. CHANGES HAVE BEEN MADE TO SUIT
4 LIBKUMU STYLE AND TYPE CONVENTIONS. ALL BUGS BELONG TO JOHN HURST.
5 THE FOLLOWING IS FOR ATTRIBUTION, THANK YOU MR. BERNSTEIN FOR WRITING
6 AND DISTRIBUTING SUCH GREAT SOFTWARE:
7
8 libtai 0.60, alpha.
9 19981013
10 Copyright 1998
11 D. J. Bernstein, djb@pobox.com
12 http://pobox.com/~djb/libtai.html
13
14
15 libtai is a library for storing and manipulating dates and times.
16
17 libtai supports two time scales: (1) TAI64, covering a few hundred
18 billion years with 1-second precision; (2) TAI64NA, covering the same
19 period with 1-attosecond precision. Both scales are defined in terms of
20 TAI, the current international real time standard.
21
22 libtai provides an internal format for TAI64, struct tai, designed for
23 fast time manipulations. The tai_pack() and tai_unpack() routines
24 convert between struct tai and a portable 8-byte TAI64 storage format.
25 libtai provides similar internal and external formats for TAI64NA.
26
27 libtai provides struct caldate to store dates in year-month-day form. It
28 can convert struct caldate, under the Gregorian calendar, to a modified
29 Julian day number for easy date arithmetic.
30
31 libtai provides struct caltime to store calendar dates and times along
32 with UTC offsets. It can convert from struct tai to struct caltime in
33 UTC, accounting for leap seconds, for accurate date and time display. It
34 can also convert back from struct caltime to struct tai for user input.
35 Its overall UTC-to-TAI conversion speed is 100x better than the usual
36 UNIX mktime() implementation.
37
38 This version of libtai requires a UNIX system with gettimeofday(). It
39 will be easy to port to other operating systems with compilers
40 supporting 64-bit arithmetic.
41
42 The libtai source code is in the public domain.
43
44 */
45
46   /*! \file    KM_tai.h
47     \version $Id$
48     \brief   portable time functions
49   */
50
51 #ifndef _KUMU_TAI_H_
52 #define _KUMU_TAI_H_
53
54 #include <KM_platform.h>
55
56 //
57 namespace Kumu
58 {
59   namespace TAI
60   {
61     class caltime;
62
63     //
64     struct tai
65     {
66       ui64_t x;
67       inline void add_hours(i32_t h) { x += h * 3600; }
68       inline void add_days(i32_t h) { x += h * 86400; }
69       void now();
70
71       const tai& operator=(const caltime& rhs);
72     };
73     
74     //
75     struct caldate
76     {
77       i32_t year;
78       i32_t month;
79       i32_t day;
80     };
81
82     //
83     struct caltime
84     {
85       caldate date;
86       i32_t hour;
87       i32_t minute;
88       i32_t second;
89       i32_t offset;
90
91       const caltime& operator=(const tai& rhs);
92     };
93
94
95   } // namespace TAI
96
97 } // namespace Kumu
98
99
100 #endif // _KUMU_TAI_H_
101
102 //
103 // end KM_tai.h
104 //