ruby-sdn 2.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: a68bc5e8882d9fd6cd7d53d6f8eff964f58063ba
4
+ data.tar.gz: 6672d0e346530f374134c4a2a5376cdabb7dffe7
5
+ SHA512:
6
+ metadata.gz: e48e42cba2916aeb26229e8e282b9e594a938a91c6bf4f008ee0e28056cc6af699c8ba1bd2d7edf74556a2d7a465923c7655fe70c4cf85cb57eda886671a0874
7
+ data.tar.gz: daec1e96ac8dafdcf650acc15eb8167c6e09672311fa749f03d7a6c30d44baefdefcf8f63524139c25e68e4834f2e4e57adc5048563c9d6337f12a1f0b69f4a8
data/LICENSE ADDED
@@ -0,0 +1,26 @@
1
+ Copyright (c) 1997-2014, Tadayoshi Funaba
2
+ All rights reserved.
3
+
4
+ Redistribution and use in source and binary forms, with or without
5
+ modification, are permitted provided that the following conditions are
6
+ met:
7
+
8
+ 1. Redistributions of source code must retain the above copyright
9
+ notice, this list of conditions and the following disclaimer.
10
+
11
+ 2. Redistributions in binary form must reproduce the above copyright
12
+ notice, this list of conditions and the following disclaimer in the
13
+ documentation and/or other materials provided with the
14
+ distribution.
15
+
16
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17
+ "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18
+ LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19
+ A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20
+ HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21
+ SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22
+ LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23
+ DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24
+ THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25
+ (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26
+ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
data/README ADDED
@@ -0,0 +1,35 @@
1
+ "Sdn" モジュール
2
+ ================
3
+
4
+ これはこよみモジュールです。核となる元のコードは Scott E. Lee 氏による
5
+ SDN こよみライブラリです。
6
+
7
+ このモジュールはつぎの暦をあつかいます:
8
+
9
+ グレゴリオ暦 (いわゆる新暦)、ユリウス暦 (欧州旧暦)、フランス革命暦、
10
+ ユダヤ暦
11
+
12
+
13
+ インストール
14
+ ------------
15
+
16
+ スクリプト "install.rb" をつかいます。
17
+
18
+ $ ruby install.rb config
19
+ $ ruby install.rb setup
20
+ ($ su)
21
+ # ruby install.rb install
22
+
23
+ くわしくは、"ruby install.rb --help" としてください。
24
+
25
+
26
+ 謝辞
27
+ ----
28
+
29
+ さまざまなこよみ計算のためのコードを書かれた Scott E. Lee 氏に感謝しま
30
+ す。
31
+
32
+
33
+ ふなばただよし
34
+ mailto:tadf@funaba.org
35
+ http://www.funaba.org/
@@ -0,0 +1,33 @@
1
+ An "Sdn" module
2
+ ===============
3
+
4
+ This is a calendar module. The original core code from SDN calendar
5
+ library which is written by Scott E. Lee.
6
+
7
+ This module supports the following calendars:
8
+
9
+ Gregorian, Julian, French Republican, Jewish
10
+
11
+
12
+ Install
13
+ -------
14
+
15
+ Use the script "install.rb".
16
+
17
+ $ ruby install.rb config
18
+ $ ruby install.rb setup
19
+ ($ su)
20
+ # ruby install.rb install
21
+
22
+ For more information, type "ruby install.rb --help".
23
+
24
+
25
+ Acknowledgments
26
+ ---------------
27
+
28
+ I thank Scott E. Lee who wrote various calendar code.
29
+
30
+
31
+ Tadayoshi Funaba
32
+ mailto:tadf@funaba.org
33
+ http://www.funaba.org/
@@ -0,0 +1,10 @@
1
+ MANIFEST
2
+ depend
3
+ dow.c
4
+ extconf.rb
5
+ french.c
6
+ gregor.c
7
+ jewish.c
8
+ julian.c
9
+ sdncal.h
10
+ sdnmodule.c
@@ -0,0 +1,31 @@
1
+ This package contains the source code of C language functions for date
2
+ arithmetic and for converting between the following calendar types:
3
+
4
+ Gregorian
5
+ Julian
6
+ French Republican
7
+ Jewish
8
+
9
+ Other calendars may be supported in the future. Let me know what other
10
+ calendars you would like to see added.
11
+
12
+ There are also verification programs for each calendar (file names starting
13
+ with "v").
14
+
15
+ There are general comments about using the software in the header file
16
+ (sdncal.h) and specific comments on each calendar in its source code file
17
+ (e.g., julian.c).
18
+
19
+ If you find bugs, have suggestions for improvement, etc., the author
20
+ welcomes your comments:
21
+
22
+ Scott E. Lee
23
+ scottlee@pobox.com
24
+ lees@dg-rtp.dg.com
25
+ CompuServe: 74223,1301
26
+
27
+ If you cannot find me at the above addresses, try looking for me in the
28
+ Internet White Page Directory at:
29
+
30
+ http://www.Four11.com/
31
+
@@ -0,0 +1,6 @@
1
+ dow.o: dow.c sdncal.h
2
+ french.o: french.c sdncal.h
3
+ gregor.o: gregor.c sdncal.h
4
+ jewish.o: jewish.c sdncal.h
5
+ julian.o: julian.c sdncal.h
6
+ sdnmodule.o: sdnmodule.c sdncal.h
@@ -0,0 +1,65 @@
1
+ /* $selId: dow.c,v 2.0 1995/10/24 01:13:06 lees Exp $
2
+ * Copyright 1993-1995, Scott E. Lee, all rights reserved.
3
+ * Permission granted to use, copy, modify, distribute and sell so long as
4
+ * the above copyright and this permission statement are retained in all
5
+ * copies. THERE IS NO WARRANTY - USE AT YOUR OWN RISK.
6
+ */
7
+
8
+ /**************************************************************************
9
+ *
10
+ * These are the externally visible components of this file:
11
+ *
12
+ * int
13
+ * DayOfWeek(
14
+ * long int sdn);
15
+ *
16
+ * Convert a SDN to a day-of-week number (0 to 6). Where 0 stands for
17
+ * Sunday, 1 for Monday, etc. and 6 stands for Saturday.
18
+ *
19
+ * char *DayNameShort[7];
20
+ *
21
+ * Convert a day-of-week number (0 to 6), as returned from DayOfWeek(), to
22
+ * the abbreviated (three character) name of the day.
23
+ *
24
+ * char *DayNameLong[7];
25
+ *
26
+ * Convert a day-of-week number (0 to 6), as returned from DayOfWeek(), to
27
+ * the name of the day.
28
+ *
29
+ **************************************************************************/
30
+
31
+ #include "sdncal.h"
32
+
33
+ int
34
+ DayOfWeek(
35
+ long int sdn)
36
+ {
37
+ int dow;
38
+
39
+ dow = (sdn + 1) % 7;
40
+ if (dow >= 0) {
41
+ return(dow);
42
+ } else {
43
+ return(dow + 7);
44
+ }
45
+ }
46
+
47
+ const char *DayNameShort[7] = {
48
+ "Sun",
49
+ "Mon",
50
+ "Tue",
51
+ "Wed",
52
+ "Thu",
53
+ "Fri",
54
+ "Sat"
55
+ };
56
+
57
+ const char *DayNameLong[7] = {
58
+ "Sunday",
59
+ "Monday",
60
+ "Tuesday",
61
+ "Wednesday",
62
+ "Thursday",
63
+ "Friday",
64
+ "Saturday"
65
+ };
@@ -0,0 +1,2 @@
1
+ require 'mkmf'
2
+ create_makefile('sdn')
@@ -0,0 +1,154 @@
1
+ /* $selId: french.c,v 2.0 1995/10/24 01:13:06 lees Exp $
2
+ * Copyright 1993-1995, Scott E. Lee, all rights reserved.
3
+ * Permission granted to use, copy, modify, distribute and sell so long as
4
+ * the above copyright and this permission statement are retained in all
5
+ * copies. THERE IS NO WARRANTY - USE AT YOUR OWN RISK.
6
+ */
7
+
8
+ /**************************************************************************
9
+ *
10
+ * These are the externally visible components of this file:
11
+ *
12
+ * void
13
+ * SdnToFrench(
14
+ * long int sdn,
15
+ * int *pYear,
16
+ * int *pMonth,
17
+ * int *pDay);
18
+ *
19
+ * Convert a SDN to a French republican calendar date. If the input SDN is
20
+ * before the first day of year 1 or after the last day of year 14, the
21
+ * three output values will all be set to zero, otherwise *pYear will be in
22
+ * the range 1 to 14 inclusive; *pMonth will be in the range 1 to 13
23
+ * inclusive; *pDay will be in the range 1 to 30 inclusive. If *pMonth is
24
+ * 13, the SDN represents one of the holidays at the end of the year and
25
+ * *pDay will be in the range 1 to 6 inclusive.
26
+ *
27
+ * long int
28
+ * FrenchToSdn(
29
+ * int year,
30
+ * int month,
31
+ * int day);
32
+ *
33
+ * Convert a French republican calendar date to a SDN. Zero is returned
34
+ * when the input date is detected as invalid or out of the supported
35
+ * range. The return value will be > 0 for all valid, supported dates, but
36
+ * there are some invalid dates that will return a positive value. To
37
+ * verify that a date is valid, convert it to SDN and then back and compare
38
+ * with the original.
39
+ *
40
+ * char *FrenchMonthName[14];
41
+ *
42
+ * Convert a French republican month number (1 to 13) to the name of the
43
+ * French republican month (null terminated). An index of 13 (for the
44
+ * "extra" days at the end of the year) will return the string "Extra". An
45
+ * index of zero will return a zero length string.
46
+ *
47
+ * VALID RANGE
48
+ *
49
+ * These routines only convert dates in years 1 through 14 (Gregorian
50
+ * dates 22 September 1792 through 22 September 1806). This more than
51
+ * covers the period when the calendar was in use.
52
+ *
53
+ * I would support a wider range of dates, but I have not been able to
54
+ * find an authoritative definition of when leap years were to have
55
+ * occurred. There are suggestions that it was to skip a leap year ever
56
+ * 100 years like the Gregorian calendar.
57
+ *
58
+ * CALENDAR OVERVIEW
59
+ *
60
+ * The French republican calendar was adopted in October 1793 during
61
+ * the French Revolution and was abandoned in January 1806. The intent
62
+ * was to create a new calendar system that was based on scientific
63
+ * principals, not religious traditions.
64
+ *
65
+ * The year is divided into 12 months of 30 days each. The remaining 5
66
+ * to 6 days in the year are grouped at the end and are holidays. Each
67
+ * month is divided into three decades (instead of weeks) of 10 days
68
+ * each.
69
+ *
70
+ * The epoch (first day of the first year) is 22 September 1792 in the
71
+ * Gregorian calendar. Leap years are every fourth year (year 3, 7,
72
+ * 11, etc.)
73
+ *
74
+ * TESTING
75
+ *
76
+ * This algorithm has been tested from the year 1 to 14. The source
77
+ * code of the verification program is included in this package.
78
+ *
79
+ * REFERENCES
80
+ *
81
+ * I have found no detailed, authoritative reference on this calendar.
82
+ * The algorithms are based on a preponderance of less authoritative
83
+ * sources.
84
+ *
85
+ **************************************************************************/
86
+
87
+ #include "sdncal.h"
88
+
89
+ #define SDN_OFFSET 2375474
90
+ #define DAYS_PER_4_YEARS 1461
91
+ #define DAYS_PER_MONTH 30
92
+ #define FIRST_VALID 2375840
93
+ #define LAST_VALID 2380952
94
+
95
+ void
96
+ SdnToFrench(
97
+ long int sdn,
98
+ int *pYear,
99
+ int *pMonth,
100
+ int *pDay)
101
+ {
102
+ long int temp;
103
+ int dayOfYear;
104
+
105
+ if (sdn < FIRST_VALID || sdn > LAST_VALID) {
106
+ *pYear = 0;
107
+ *pMonth = 0;
108
+ *pDay = 0;
109
+ return;
110
+ }
111
+
112
+ temp = (sdn - SDN_OFFSET) * 4 - 1;
113
+ *pYear = temp / DAYS_PER_4_YEARS;
114
+ dayOfYear = (temp % DAYS_PER_4_YEARS) / 4;
115
+ *pMonth = dayOfYear / DAYS_PER_MONTH + 1;
116
+ *pDay = dayOfYear % DAYS_PER_MONTH + 1;
117
+ }
118
+
119
+ long int
120
+ FrenchToSdn(
121
+ int year,
122
+ int month,
123
+ int day)
124
+ {
125
+ /* check for invalid dates */
126
+ if (year < 1 || year > 14 ||
127
+ month < 1 || month > 13 ||
128
+ day < 1 || day > 30)
129
+ {
130
+ return(0);
131
+ }
132
+
133
+ return( (year * DAYS_PER_4_YEARS) / 4
134
+ + (month - 1) * DAYS_PER_MONTH
135
+ + day
136
+ + SDN_OFFSET );
137
+ }
138
+
139
+ const char *FrenchMonthName[14] = {
140
+ "",
141
+ "Vendemiaire",
142
+ "Brumaire",
143
+ "Frimaire",
144
+ "Nivose",
145
+ "Pluviose",
146
+ "Ventose",
147
+ "Germinal",
148
+ "Floreal",
149
+ "Prairial",
150
+ "Messidor",
151
+ "Thermidor",
152
+ "Fructidor",
153
+ "Extra"
154
+ };
@@ -0,0 +1,268 @@
1
+ /* $selId: gregor.c,v 2.0 1995/10/24 01:13:06 lees Exp $
2
+ * Copyright 1993-1995, Scott E. Lee, all rights reserved.
3
+ * Permission granted to use, copy, modify, distribute and sell so long as
4
+ * the above copyright and this permission statement are retained in all
5
+ * copies. THERE IS NO WARRANTY - USE AT YOUR OWN RISK.
6
+ */
7
+
8
+ /**************************************************************************
9
+ *
10
+ * These are the externally visible components of this file:
11
+ *
12
+ * void
13
+ * SdnToGregorian(
14
+ * long int sdn,
15
+ * int *pYear,
16
+ * int *pMonth,
17
+ * int *pDay);
18
+ *
19
+ * Convert a SDN to a Gregorian calendar date. If the input SDN is less
20
+ * than 1, the three output values will all be set to zero, otherwise
21
+ * *pYear will be >= -4714 and != 0; *pMonth will be in the range 1 to 12
22
+ * inclusive; *pDay will be in the range 1 to 31 inclusive.
23
+ *
24
+ * long int
25
+ * GregorianToSdn(
26
+ * int inputYear,
27
+ * int inputMonth,
28
+ * int inputDay);
29
+ *
30
+ * Convert a Gregorian calendar date to a SDN. Zero is returned when the
31
+ * input date is detected as invalid or out of the supported range. The
32
+ * return value will be > 0 for all valid, supported dates, but there are
33
+ * some invalid dates that will return a positive value. To verify that a
34
+ * date is valid, convert it to SDN and then back and compare with the
35
+ * original.
36
+ *
37
+ * char *MonthNameShort[13];
38
+ *
39
+ * Convert a Gregorian month number (1 to 12) to the abbreviated (three
40
+ * character) name of the Gregorian month (null terminated). An index of
41
+ * zero will return a zero length string.
42
+ *
43
+ * char *MonthNameLong[13];
44
+ *
45
+ * Convert a Gregorian month number (1 to 12) to the name of the Gregorian
46
+ * month (null terminated). An index of zero will return a zero length
47
+ * string.
48
+ *
49
+ * VALID RANGE
50
+ *
51
+ * 4714 B.C. to at least 10000 A.D.
52
+ *
53
+ * Although this software can handle dates all the way back to 4714
54
+ * B.C., such use may not be meaningful. The Gregorian calendar was
55
+ * not instituted until October 15, 1582 (or October 5, 1582 in the
56
+ * Julian calendar). Some countries did not accept it until much
57
+ * later. For example, Britain converted in 1752, The USSR in 1918 and
58
+ * Greece in 1923. Most European countries used the Julian calendar
59
+ * prior to the Gregorian.
60
+ *
61
+ * CALENDAR OVERVIEW
62
+ *
63
+ * The Gregorian calendar is a modified version of the Julian calendar.
64
+ * The only difference being the specification of leap years. The
65
+ * Julian calendar specifies that every year that is a multiple of 4
66
+ * will be a leap year. This leads to a year that is 365.25 days long,
67
+ * but the current accepted value for the tropical year is 365.242199
68
+ * days.
69
+ *
70
+ * To correct this error in the length of the year and to bring the
71
+ * vernal equinox back to March 21, Pope Gregory XIII issued a papal
72
+ * bull declaring that Thursday October 4, 1582 would be followed by
73
+ * Friday October 15, 1582 and that centennial years would only be a
74
+ * leap year if they were a multiple of 400. This shortened the year
75
+ * by 3 days per 400 years, giving a year of 365.2425 days.
76
+ *
77
+ * Another recently proposed change in the leap year rule is to make
78
+ * years that are multiples of 4000 not a leap year, but this has never
79
+ * been officially accepted and this rule is not implemented in these
80
+ * algorithms.
81
+ *
82
+ * ALGORITHMS
83
+ *
84
+ * The calculations are based on three different cycles: a 400 year
85
+ * cycle of leap years, a 4 year cycle of leap years and a 5 month
86
+ * cycle of month lengths.
87
+ *
88
+ * The 5 month cycle is used to account for the varying lengths of
89
+ * months. You will notice that the lengths alternate between 30
90
+ * and 31 days, except for three anomalies: both July and August
91
+ * have 31 days, both December and January have 31, and February
92
+ * is less than 30. Starting with March, the lengths are in a
93
+ * cycle of 5 months (31, 30, 31, 30, 31):
94
+ *
95
+ * Mar 31 days \
96
+ * Apr 30 days |
97
+ * May 31 days > First cycle
98
+ * Jun 30 days |
99
+ * Jul 31 days /
100
+ *
101
+ * Aug 31 days \
102
+ * Sep 30 days |
103
+ * Oct 31 days > Second cycle
104
+ * Nov 30 days |
105
+ * Dec 31 days /
106
+ *
107
+ * Jan 31 days \
108
+ * Feb 28/9 days |
109
+ * > Third cycle (incomplete)
110
+ *
111
+ * For this reason the calculations (internally) assume that the
112
+ * year starts with March 1.
113
+ *
114
+ * TESTING
115
+ *
116
+ * This algorithm has been tested from the year 4714 B.C. to 10000
117
+ * A.D. The source code of the verification program is included in
118
+ * this package.
119
+ *
120
+ * REFERENCES
121
+ *
122
+ * Conversions Between Calendar Date and Julian Day Number by Robert J.
123
+ * Tantzen, Communications of the Association for Computing Machinery
124
+ * August 1963. (Also published in Collected Algorithms from CACM,
125
+ * algorithm number 199).
126
+ *
127
+ **************************************************************************/
128
+
129
+ #include "sdncal.h"
130
+
131
+ #define SDN_OFFSET 32045
132
+ #define DAYS_PER_5_MONTHS 153
133
+ #define DAYS_PER_4_YEARS 1461
134
+ #define DAYS_PER_400_YEARS 146097
135
+
136
+ void
137
+ SdnToGregorian(
138
+ long int sdn,
139
+ int *pYear,
140
+ int *pMonth,
141
+ int *pDay)
142
+ {
143
+ int century;
144
+ int year;
145
+ int month;
146
+ int day;
147
+ long int temp;
148
+ int dayOfYear;
149
+
150
+ if (sdn <= 0) {
151
+ *pYear = 0;
152
+ *pMonth = 0;
153
+ *pDay = 0;
154
+ return;
155
+ }
156
+
157
+ temp = (sdn + SDN_OFFSET) * 4 - 1;
158
+
159
+ /* Calculate the century (year/100). */
160
+ century = temp / DAYS_PER_400_YEARS;
161
+
162
+ /* Calculate the year and day of year (1 <= dayOfYear <= 366). */
163
+ temp = ((temp % DAYS_PER_400_YEARS) / 4) * 4 + 3;
164
+ year = (century * 100) + (temp / DAYS_PER_4_YEARS);
165
+ dayOfYear = (temp % DAYS_PER_4_YEARS) / 4 + 1;
166
+
167
+ /* Calculate the month and day of month. */
168
+ temp = dayOfYear * 5 - 3;
169
+ month = temp / DAYS_PER_5_MONTHS;
170
+ day = (temp % DAYS_PER_5_MONTHS) / 5 + 1;
171
+
172
+ /* Convert to the normal beginning of the year. */
173
+ if (month < 10) {
174
+ month += 3;
175
+ } else {
176
+ year += 1;
177
+ month -= 9;
178
+ }
179
+
180
+ /* Adjust to the B.C./A.D. type numbering. */
181
+ year -= 4800;
182
+ if (year <= 0) year--;
183
+
184
+ *pYear = year;
185
+ *pMonth = month;
186
+ *pDay = day;
187
+ }
188
+
189
+ long int
190
+ GregorianToSdn(
191
+ int inputYear,
192
+ int inputMonth,
193
+ int inputDay)
194
+ {
195
+ int year;
196
+ int month;
197
+
198
+ /* check for invalid dates */
199
+ if (inputYear == 0 || inputYear < -4714 ||
200
+ inputMonth <= 0 || inputMonth > 12 ||
201
+ inputDay <= 0 || inputDay > 31)
202
+ {
203
+ return(0);
204
+ }
205
+
206
+ /* check for dates before SDN 1 (Nov 25, 4714 B.C.) */
207
+ if (inputYear == -4714) {
208
+ if (inputMonth < 11) {
209
+ return(0);
210
+ }
211
+ if (inputMonth == 11 && inputDay < 25) {
212
+ return(0);
213
+ }
214
+ }
215
+
216
+ /* Make year always a positive number. */
217
+ if (inputYear < 0) {
218
+ year = inputYear + 4801;
219
+ } else {
220
+ year = inputYear + 4800;
221
+ }
222
+
223
+ /* Adjust the start of the year. */
224
+ if (inputMonth > 2) {
225
+ month = inputMonth - 3;
226
+ } else {
227
+ month = inputMonth + 9;
228
+ year--;
229
+ }
230
+
231
+ return( ((year / 100) * DAYS_PER_400_YEARS) / 4
232
+ + ((year % 100) * DAYS_PER_4_YEARS) / 4
233
+ + (month * DAYS_PER_5_MONTHS + 2) / 5
234
+ + inputDay
235
+ - SDN_OFFSET );
236
+ }
237
+
238
+ const char *MonthNameShort[13] = {
239
+ "",
240
+ "Jan",
241
+ "Feb",
242
+ "Mar",
243
+ "Apr",
244
+ "May",
245
+ "Jun",
246
+ "Jul",
247
+ "Aug",
248
+ "Sep",
249
+ "Oct",
250
+ "Nov",
251
+ "Dec"
252
+ };
253
+
254
+ const char *MonthNameLong[13] = {
255
+ "",
256
+ "January",
257
+ "February",
258
+ "March",
259
+ "April",
260
+ "May",
261
+ "June",
262
+ "July",
263
+ "August",
264
+ "September",
265
+ "October",
266
+ "November",
267
+ "December"
268
+ };