-
Notifications
You must be signed in to change notification settings - Fork 0
/
DateOps.h
100 lines (77 loc) · 2.61 KB
/
DateOps.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
/*****************************************************************************\
* DateOps.h
*
* DateOps contains misc. time and date operations
*
* author: mark huss ([email protected])
* Based on Bill Gray's open-source code at projectpluto.com
*
\*****************************************************************************/
// uncomment the following line to include an assortment of non-western
// calendars:
/* #define CALENDARS_OF_THE_WORLD */
#if !defined( DATE_OPS__H )
#define DATE_OPS__H
typedef int MonthDays[13];
typedef long YearEndDays[2];
class DateOps {
public:
enum CalendarType {
T_GREGORIAN = 0,
T_JULIAN = 1,
// these are only used if CALENDARS_OF_THE_WORLD is defined:
T_HEBREW = 2,
T_ISLAMIC = 3,
T_REVOLUTIONARY = 4,
T_PERSIAN = 5
};
static long dmyToDay(
int day, int month, long year, int calendar = T_GREGORIAN );
static void dayToDmy(
long jd, int& day, int& month, long& year, int calendar = T_GREGORIAN );
static void dayToDmy(
long jd, int* day, int* month, long* year, int calendar = T_GREGORIAN )
{
dayToDmy( jd, *day, *month, *year, calendar );
}
static long dstStart(int year);
static long dstEnd(int year);
//private:
enum CalendarEpoch {
E_JULIAN_GREGORIAN = 1721060L,
// these are only used if CALENDARS_OF_THE_WORLD is defined:
E_ISLAMIC = 1948086L,
E_HEBREW = 347996L,
E_REVOLUTIONARY = 2375475L
};
static void getJulGregYearData(
long year, long& days, MonthDays& md, bool julian );
static int getCalendarData(
long year, YearEndDays& days, MonthDays& md, int calendar );
#if defined( CALENDARS_OF_THE_WORLD )
enum {
HALAKIM_IN_DAY = (24L * 1080L),
JALALI_ZERO = 1947954L,
LOWER_PERSIAN_YEAR = -1096,
UPPER_PERSIAN_YEAR = 2327
};
static long mod( long x, long y );
// Islamic calendar
static void getIslamicYearData( long year, long& days, MonthDays& md );
// Hebrew calendar
static long lunationsToTishri1( long year );
static void lunationsToDaysAndHalakim(
long lunations, long& days, long& halakim);
static void findTishri1( long year, long& days, long& halakim );
static void getHebrewYearData( long year, YearEndDays& days, MonthDays& md );
// French Revolutionary calendar
static long jdOfFrenchRevYear( long year );
static void getRevolutionaryYearData(
long year, YearEndDays& days, MonthDays& md );
// Persian (Jalaali) calendar
static long jalaliJd0( long jalaliYear );
static void getJalaliYearData(
const long year, YearEndDays& days, MonthDays& md );
#endif
};
#endif /* #if !defined( DATE_OPS__H ) */