3 /// Time related conversion routines.
4 /// time_t is the POSIX time.
5 /// min1900_t is the minutes from Jan 1, 1900
9 Copyright (C) 2005-2013, Net Direct Inc. (http://www.netdirect.ca/)
11 This program is free software; you can redistribute it and/or modify
12 it under the terms of the GNU General Public License as published by
13 the Free Software Foundation; either version 2 of the License, or
14 (at your option) any later version.
16 This program is distributed in the hope that it will be useful,
17 but WITHOUT ANY WARRANTY; without even the implied warranty of
18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
20 See the GNU General Public License in the COPYING file at the
21 root directory of this project for more details.
24 #ifndef __BARRY_TIME_H__
25 #define __BARRY_TIME_H__
28 #include <sys/time.h> // for struct timespec
33 // Calculate the number of minutes between Jan 01, 1900 and Jan 01, 1970
35 // There are 17 leap years between 1900 and 1970
36 // (1969-1900) / 4 = 17.25
38 // 1900 itself is not a leap year (not divisible by 400)
40 #define DAY_MINUTES (24 * 60)
41 #define YEAR_MINUTES (365 * DAY_MINUTES)
42 #define LEAP_YEAR_COUNT ((1970-1901) / 4)
43 #define YEAR_COUNT (1970 - 1900)
45 // therefore, the difference between standard C's time and min1900_t's
47 #define STDC_MIN1900_DIFF (YEAR_COUNT * YEAR_MINUTES + LEAP_YEAR_COUNT * DAY_MINUTES)
51 typedef long min1900_t
;
53 BXEXPORT min1900_t
time2min(time_t t
);
54 BXEXPORT
time_t min2time(min1900_t m
);
56 // FIXME - turn StaticTimeZone into a C typedef and wrap this in extern "C"
57 // so the data can be used in both C and C++ libraries
59 // This is named StaticTimeZone since the time zone table is hard coded
60 // in the library. If you want to know what the device's idea of time zones
61 // is, then extract the time zone database using the TimeZone record class.
63 // See also the TimeZones class, which unifies access to the static and
64 // dynamic time zone tables in one class API.
66 struct BXEXPORT StaticTimeZone
69 signed short HourOffset
;
70 signed short MinOffset
;
74 // FIXME - put this somewhere for both C and C++
75 #define STATIC_TIME_ZONE_CODE_ERR 0xffff
77 BXEXPORT
const StaticTimeZone
* GetStaticTimeZoneTable();
78 BXEXPORT
const StaticTimeZone
* GetStaticTimeZone(uint16_t Code
);
79 BXEXPORT
unsigned short GetStaticTimeZoneCode(signed short HourOffset
,
80 signed short MinOffset
= 0);
82 // Message time conversion stuff
83 BXEXPORT
time_t DayToDate( uint16_t Day
);
84 BXEXPORT
time_t Message2Time(uint16_t r_date
, uint16_t r_time
);
86 // Thread timeout creation
87 BXEXPORT
struct timespec
* ThreadTimeout(int timeout_ms
, struct timespec
*spec
);
90 BXEXPORT
int DaysInMonth(struct tm
&t
);