In an effort to level the playing field between languages with built-in date libraries and those without, let's work with a fictional calendar. The Forgotten Realms are a (the?) campaign setting for Dungeons & Dragons. Of course, each have their own calendar.
The Calendar of Harptos
Conveniently, a year in the Forgotten Realms also has 365 days. Furthermore, the calendar also has 12 months. However, this is where it gets interesting. Each month is exactly 30 days long. The remaining 5 days are holidays which fall between the months. Here are the months and holidays in order (with holidays indented):
1 Deepwinter
Midwinter
2 The Claw of Winter
3 The Claw of the Sunsets
4 The Claw of the Storms
Greengrass
5 The Melting
6 The Time of Flowers
7 Summertide
Midsummer
[Shieldmeet]
8 Highsun
9 The Fading
Highharvestide
10 Leaffall
11 The Rotting
The Feast of the Moon
12 The Drawing Down
Notice that I've inserted a sixth holiday in brackets. This is the leap day which only occurs every four years (yes, that's it — there are no additional shenanigans with the centuries).
Side note about month names: each month has a formal and a common name. The above are the common names. I've picked those because I think they allow for more interesting compression.
There are several numberings of the years, but the most widespread one is Dalereckoning, shortened to DR. (Also, every year has one or more names, but we're not going to bother with that.)
The components of a date should be separated by a comma and a space. All in all, a valid date might look like:
4, The Melting, 1491 DR
or
Shieldmeet, 1464 DR
Note that there is no day number for the holidays. (I suppose 4th of The Melting
would be nicer for the days of the months, but I don't want to drag ordinal numbers into this.)
Footnote: I came up with this when xnor complained that every single date challenge needs the leap year computation. I've failed in eliminating it completely, but at least it's only a single modulo in this calendar.
The Challenge
Given a valid date of the Calendar of Harptos, as well as an integer D
, output the date D
days later. Note that D
may be negative, in which case you should return the date D
days earlier.
You may write a program or function, taking input via STDIN (or closest alternative), command-line argument or function argument and outputting the result via STDOUT (or closest alternative), function return value or function (out) parameter.
You may assume that the year is positive and less than 2000.
Standard code-golf rules apply.
Test Cases
The first dozen or so test cases should test all the edge cases surrounding holidays and leap years. The next set are to test that ranges across multiple years work and all months and holidays have been implemented. The second half is all the same test cases again but with negative offsets.
"30, Summertide, 1491 DR" 1 => "Midsummer, 1491 DR"
"30, Summertide, 1491 DR" 2 => "1, Highsun, 1491 DR"
"Midsummer, 1491 DR" 1 => "1, Highsun, 1491 DR"
"30, Summertide, 1492 DR" 1 => "Midsummer, 1492 DR"
"30, Summertide, 1492 DR" 2 => "Shieldmeet, 1492 DR"
"30, Summertide, 1492 DR" 3 => "1, Highsun, 1492 DR"
"Midsummer, 1492 DR" 1 => "Shieldmeet, 1492 DR"
"Midsummer, 1492 DR" 2 => "1, Highsun, 1492 DR"
"Shieldmeet, 1492 DR" 1 => "1, Highsun, 1492 DR"
"1, Highsun, 1490 DR" 365 => "1, Highsun, 1491 DR"
"1, Highsun, 1491 DR" 365 => "Shieldmeet, 1492 DR"
"Shieldmeet, 1492 DR" 365 => "Midsummer, 1493 DR"
"Midsummer, 1493 DR" 365 => "Midsummer, 1494 DR"
"Shieldmeet, 1500 DR" 365 => "Midsummer, 1501 DR"
"14, Deepwinter, 654 DR" 5069 => "The Feast of the Moon, 667 DR"
"Midwinter, 17 DR" 7897 => "15, The Fading, 38 DR"
"3, The Claw of Winter, 1000 DR" 813 => "25, The Claw of the Storms, 1002 DR"
"Greengrass, 5 DR" 26246 => "9, The Claw of the Sunsets, 77 DR"
"30, The Melting, 321 DR" 394 => "29, The Time of Flowers, 322 DR"
"17, The Time of Flowers, 867 DR" 13579 => "20, Highsun, 904 DR"
"Highharvestide, 1814 DR" 456 => "30, The Drawing Down, 1815 DR"
"23, The Rotting, 1814 DR" 3616 => "16, Leaffall, 1824 DR"
"1, Deepwinter, 1 DR" 730499 => "30, The Drawing Down, 2000 DR"
"Midsummer, 1491 DR" -1 => "30, Summertide, 1491 DR"
"1, Highsun, 1491 DR" -2 => "30, Summertide, 1491 DR"
"1, Highsun, 1491 DR" -1 => "Midsummer, 1491 DR"
"Midsummer, 1492 DR" -1 => "30, Summertide, 1492 DR"
"Shieldmeet, 1492 DR" -2 => "30, Summertide, 1492 DR"
"1, Highsun, 1492 DR" -3 => "30, Summertide, 1492 DR"
"Shieldmeet, 1492 DR" -1 => "Midsummer, 1492 DR"
"1, Highsun, 1492 DR" -2 => "Midsummer, 1492 DR"
"1, Highsun, 1492 DR" -1 => "Shieldmeet, 1492 DR"
"1, Highsun, 1491 DR" -365 => "1, Highsun, 1490 DR"
"Shieldmeet, 1492 DR" -365 => "1, Highsun, 1491 DR"
"Midsummer, 1493 DR" -365 => "Shieldmeet, 1492 DR"
"Midsummer, 1494 DR" -365 => "Midsummer, 1493 DR"
"Midsummer, 1501 DR" -365 => "Shieldmeet, 1500 DR"
"The Feast of the Moon, 667 DR" -5069 => "14, Deepwinter, 654 DR"
"15, The Fading, 38 DR" -7897 => "Midwinter, 17 DR"
"25, The Claw of the Storms, 1002 DR" -813 => "3, The Claw of Winter, 1000 DR"
"9, The Claw of the Sunsets, 77 DR" -26246 => "Greengrass, 5 DR"
"29, The Time of Flowers, 322 DR" -394 => "30, The Melting, 321 DR"
"20, Highsun, 904 DR" -13579 => "17, The Time of Flowers, 867 DR"
"30, The Drawing Down, 1815 DR" -456 => "Highharvestide, 1814 DR"
"16, Leaffall, 1824 DR" -3616 => "23, The Rotting, 1814 DR"
"30, The Drawing Down, 2000 DR" -730499 => "1, Deepwinter, 1 DR"