Skip to content

Commit c2c6ce8

Browse files
author
Rick Hull
committed
rename e.g. WEE_DAYS to MON30
1 parent cc5f80c commit c2c6ce8

File tree

1 file changed

+10
-10
lines changed

1 file changed

+10
-10
lines changed

lib/compsci/date.rb

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -32,21 +32,21 @@ def self.leap_days(year)
3232
#
3333

3434
# define month lengths
35-
MAX_DAYS = 31
36-
WEE_DAYS = 30
37-
LEP_DAYS = 29
38-
FEB_DAYS = 28
35+
MON31 = 31 # Jan, Mar, May, Jul, Aug, Oct, Dec
36+
MON30 = 30 # Apr, Jun, Sep, Nov
37+
MON29 = 29 # Feb (leap)
38+
MON28 = 28 # Feb
3939

4040
# define lookup by month number, zero-indexed
4141
MONTH_DAYS =
42-
[MAX_DAYS, FEB_DAYS, MAX_DAYS, WEE_DAYS, MAX_DAYS, WEE_DAYS,
43-
MAX_DAYS, MAX_DAYS, WEE_DAYS, MAX_DAYS, WEE_DAYS, MAX_DAYS].freeze
42+
[MON31, MON28, MON31, MON30, MON31, MON30,
43+
MON31, MON31, MON30, MON31, MON30, MON31].freeze
4444
NUM_MONTHS = 12 # MONTH_DAYS.size
4545

4646
# derive CUMULATIVE_DAYS from MONTH_DAYS, zero-indexed
4747
CUMULATIVE_DAYS = MONTH_DAYS.reduce([0]) { |acc, days|
4848
acc + [acc.last + days]
49-
}
49+
} # [0, 31, 59, 90, 120, ... 365]
5050
ANNUAL_DAYS = CUMULATIVE_DAYS.pop # 365
5151
LEAP_YEAR_DAYS = ANNUAL_DAYS + 1 # 366
5252
CUMULATIVE_DAYS.freeze
@@ -56,7 +56,7 @@ def self.leap_days(year)
5656

5757
# implementation considerations
5858
MIN_Y, MIN_M, MIN_D = 1, 1, 1
59-
MAX_Y, MAX_M, MAX_D = 9999, NUM_MONTHS, MAX_DAYS
59+
MAX_Y, MAX_M, MAX_D = 9999, NUM_MONTHS, MON31
6060
EPOCH_Y, EPOCH_M, EPOCH_D = 1, 1, 1
6161

6262
#
@@ -66,13 +66,13 @@ def self.leap_days(year)
6666
# perform lookup by month number and year, one-indexed, with leap days
6767
def self.month_days(month, year)
6868
(month == 2 and self.leap_year?(year)) ?
69-
LEP_DAYS : MONTH_DAYS.fetch(month - 1)
69+
MON29 : MONTH_DAYS.fetch(month - 1)
7070
end
7171

7272
# given a day count, what is the current month?
7373
# despite leap years, never guess too low, only too high
7474
def self.guess_month(days)
75-
(days / WEE_DAYS + 1).clamp(EPOCH_M, NUM_MONTHS)
75+
(days / MON30 + 1).clamp(MIN_M, MAX_M)
7676
end
7777

7878
# perform lookup by month number and year, one-indexed, with leap days

0 commit comments

Comments
 (0)