home_run 0.9.0-x86-mingw32 → 0.9.1-x86-mingw32

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,187 @@
1
+
2
+ #ifndef DATE_EXT_H
3
+ #define DATE_EXT_H 1
4
+
5
+ #include <math.h>
6
+ #include <stdio.h>
7
+ #include <stdlib.h>
8
+ #include <string.h>
9
+ #include <inttypes.h>
10
+ #include <ruby.h>
11
+
12
+ #if defined(HAVE_RUBY_ENCODING_H) && HAVE_RUBY_ENCODING_H
13
+ #define RHR_ENCODING 1
14
+ #include <ruby/encoding.h>
15
+ #endif
16
+
17
+ #ifdef RUBY19
18
+ #define RHR_DEFAULT_CWYEAR -4713
19
+ #define RHR_DEFAULT_CWEEK 1
20
+ #define RHR_DEFAULT_CWDAY 1
21
+ #else
22
+ #define RHR_DEFAULT_CWYEAR 1582
23
+ #define RHR_DEFAULT_CWEEK 41
24
+ #define RHR_DEFAULT_CWDAY 5
25
+ #endif
26
+
27
+ #define RHR_JD_MJD 2400001
28
+ #define RHR_JD_LD 2299160
29
+ #define RHR_JD_ITALY 2299161
30
+ #define RHR_JD_ENGLAND 2361222
31
+ #define RHR_UNIX_EPOCH 2440588
32
+ #define RHR_SECONDS_PER_HOUR 3600
33
+ #define RHR_MINUTES_PER_DAYD 1440.0
34
+ #define RHR_SECONDS_PER_DAY 86400
35
+ #define RHR_SECONDS_PER_DAYD 86400.0
36
+ #define RHR_MAX_OFFSET 840
37
+ #define RHR_MIN_OFFSET -840
38
+
39
+ /*
40
+ In both the 32-bit and 64-bit cases, the limits are chosen so that you cannot
41
+ store a civil date where converting it to a jd would cause an overflow.
42
+ */
43
+ #if __LP64__
44
+ /*
45
+ On 64-bit systems, the limits depend on the number of significant digits in
46
+ a double (15). These are slightly below the maximum so that all numbers used
47
+ in calculations have fewer than 15 digits.
48
+ */
49
+ #define RHR_JD_MAX 999979466117609
50
+ #define RHR_JD_MIN -999979466119058
51
+ #define RHR_YEAR_MAX 2737850782415
52
+ #define RHR_MONTH_MAX 12
53
+ #define RHR_DAY_MAX 5
54
+ #define RHR_YEAR_MIN -2737850791845
55
+ #define RHR_MONTH_MIN 11
56
+ #define RHR_DAY_MIN 26
57
+
58
+ #else
59
+ /*
60
+ On 32-bit systems, the limits depend on the storage limits of 32-bit integers.
61
+ The numbers are slightly less than 2**31 - 1 and slightly greater than -2**31
62
+ so that no calculations can overflow.
63
+ */
64
+ #define RHR_JD_MAX 2147438064
65
+ #define RHR_JD_MIN -2145083647
66
+ #define RHR_YEAR_MAX 5874773
67
+ #define RHR_MONTH_MAX 8
68
+ #define RHR_DAY_MAX 15
69
+ #define RHR_YEAR_MIN -5877752
70
+ #define RHR_MONTH_MIN 5
71
+ #define RHR_DAY_MIN 8
72
+ #endif
73
+
74
+ #define RHR_HAVE_JD 1
75
+ #define RHR_HAVE_CIVIL 2
76
+ #define RHR_HAVE_NANOS 4
77
+ #define RHR_HAVE_HMS 8
78
+
79
+ #define RHR_NO_RAISE 0
80
+ #define RHR_OVERLIMIT_RAISE 1
81
+
82
+ #define RHR_NANOS_PER_MILLISECOND 1000000LL
83
+ #define RHR_NANOS_PER_SECOND 1000000000LL
84
+ #define RHR_NANOS_PER_MINUTE 60000000000LL
85
+ #define RHR_NANOS_PER_DAY 86400000000000LL
86
+ #define RHR_NANOS_PER_DAYD 86400000000000.0
87
+ #define RHR_NANOS_PER_SECONDD 1000000000.0
88
+
89
+ #define RHRR_YEAR_SET 0x1
90
+ #define RHRR_MONTH_SET 0x2
91
+ #define RHRR_DAY_SET 0x4
92
+ #define RHRR_YDAY_SET 0x8
93
+ #define RHRR_HOUR_SET 0x10
94
+ #define RHRR_MINUTE_SET 0x20
95
+ #define RHRR_SECOND_SET 0x40
96
+ #define RHRR_WDAY_SET 0x80
97
+ #define RHRR_CENTURY_SET 0x100
98
+ #define RHRR_CWYEAR_SET 0x200
99
+ #define RHRR_CWEEK_SET 0x400
100
+ #define RHRR_CWDAY_SET 0x800
101
+ #define RHRR_SEC_FRACTION_SET 0x1000
102
+ #define RHRR_UNIX_SET 0x2000
103
+ #define RHRR_WNUM0_SET 0x4000
104
+ #define RHRR_WNUM1_SET 0x8000
105
+ #define RHRR_MERIDIAN_SET 0x10000
106
+ #define RHRR_ZONE_SET 0x20000
107
+ #define RHRR_OFFSET_SET 0x40000
108
+ #define RHRR_UNIXM_SET 0x80000
109
+
110
+ #define RHR_HAS_JD(d) (((d)->flags & RHR_HAVE_JD) == RHR_HAVE_JD)
111
+ #define RHR_HAS_CIVIL(d) (((d)->flags & RHR_HAVE_CIVIL) == RHR_HAVE_CIVIL)
112
+
113
+ #define RHR_FILL_JD(d) if (((d)->flags & RHR_HAVE_JD) == 0) { rhrd__civil_to_jd(d); }
114
+ #define RHR_FILL_CIVIL(d) if (((d)->flags & RHR_HAVE_CIVIL) == 0) { rhrd__jd_to_civil(d); }
115
+
116
+ #define RHRDT_FILL_JD(d) if (!((d)->flags & RHR_HAVE_JD)) { rhrdt__civil_to_jd(d); }
117
+ #define RHRDT_FILL_CIVIL(d) if (!((d)->flags & RHR_HAVE_CIVIL)) { rhrdt__jd_to_civil(d); }
118
+ #define RHRDT_FILL_HMS(d) if (!((d)->flags & RHR_HAVE_HMS)) { rhrdt__nanos_to_hms(d); }
119
+ #define RHRDT_FILL_NANOS(d) if (!((d)->flags & RHR_HAVE_NANOS)) { rhrdt__hms_to_nanos(d); }
120
+
121
+ #ifdef RHR_ENCODING
122
+ int rhrd_encoding_index;
123
+ #define RHR_ASCII_ENCODING(s) s = rb_enc_associate_index(s, rhrd_encoding_index); \
124
+ if(rb_default_internal_encoding()) {s = rb_str_export_to_enc(s, rb_default_internal_encoding());}
125
+ #else
126
+ #define RHR_ASCII_ENCODING(s) /* do nothing */
127
+ #endif
128
+
129
+ #ifdef RUBY186
130
+ #define RHR_RETURN_RESIZED_STR(s, len) return rb_str_resize(s, len);
131
+ #else
132
+ #define RHR_RETURN_RESIZED_STR(s, len) rb_str_set_len(s, len); RHR_ASCII_ENCODING(s); return s;
133
+ #endif
134
+
135
+ #define RHR_SPACE_SHIP(x, l, r) if (l < r) { x = -1; } else if (l == r) { x = 0; } else { x = 1; }
136
+
137
+ #define RHR_CHECK_JD(d) if ((d->jd > RHR_JD_MAX) || (d->jd < RHR_JD_MIN)) { rb_raise(rb_eRangeError, "date out of range: jd = %li", d->jd);}
138
+ #define RHR_CHECK_CIVIL(d) if (!rhrd__valid_civil_limits(d->year, d->month, d->day)) { rb_raise(rb_eRangeError, "date out of range: year = %li, month = %hhi, day = %hhi", d->year, d->month, d->day);}
139
+
140
+ #define RHR_CACHED_IV(self, iv) VALUE v = rb_ivar_get(self, iv); if (RTEST(v)) {return v;}
141
+
142
+ typedef struct rhrd_s {
143
+ long jd;
144
+ long year;
145
+ unsigned char month;
146
+ unsigned char day;
147
+ unsigned char flags;
148
+ } rhrd_t;
149
+
150
+ typedef struct rhrdt_s {
151
+ long long nanos; /* Nanoseconds since start of day */
152
+ long jd;
153
+ long year;
154
+ short offset; /* Offset from UTC in minutes */
155
+ unsigned char month;
156
+ unsigned char day;
157
+ unsigned char hour;
158
+ unsigned char minute;
159
+ unsigned char second;
160
+ unsigned char flags;
161
+ } rhrdt_t;
162
+
163
+ void rhrdt__civil_to_jd(rhrdt_t *d);
164
+ void rhrdt__hms_to_nanos(rhrdt_t *d);
165
+ int rhrd__leap_year(long year);
166
+ int rhrd__valid_civil_limits(long year, long month, long day);
167
+ long rhrd__ymd_to_jd(long year, long month, long day);
168
+ long rhrd__commercial_to_jd(long cwyear, long cweek, long cwday);
169
+ void rhrd__fill_commercial(rhrd_t *d);
170
+ long rhrd__unix_to_jd(long long t);
171
+ long rhrd__mod(long a, long b);
172
+ long rhrd__modll(long long a, long b);
173
+ long rhrd__safe_add_long(long a, long b);
174
+ unsigned char rhrd__days_in_month(long year, unsigned char month);
175
+ int rhrd__fill_from_hash(rhrd_t *d, VALUE hash);
176
+ void rhrd__today(rhrd_t * d);
177
+ VALUE rhrd__strptime(VALUE rstr, const char *fmt_str, long fmt_len);
178
+ long rhrd__jd_to_wday(long jd);
179
+ void rhrd__set_cw_ivs(VALUE self, rhrd_t *d);
180
+ void rhrd__civil_to_jd(rhrd_t *d);
181
+ VALUE rhrd_s_zone_to_diff(VALUE self, VALUE zone);
182
+ VALUE rhrd__strftime(rhrdt_t *d, const char * fmt, int fmt_len);
183
+ long rhrd__ordinal_day(long year, unsigned char month, unsigned char day);
184
+ VALUE rhrd__ragel_parse(char * p, long len);
185
+ void Init_datetime(void);
186
+
187
+ #endif /* DATE_EXT_H */