Easter change month
up vote
1
down vote
favorite
I need to print every Easter Sunday of 21st century. I need to determine the month: 4 (April) when the day d
is no more than 30; if it's greater, then I need to convert that to the proper day in May. For instance, d=32
would be m=5, d=2
or May 2.
import calendar
import datetime
def easter():
for y in range(2001, 2101):
m2 = 2 * (y % 4)
m4 = 4 * (y % 7)
m19 = 19 * (y % 19)
v2 = (16 + m19) % 30
v1 = (6 * v2 + m4 + m2) % 7
p = v1 + v2
d = 3 + p
print ('Easter Sunday for the year', y, 'is',
datetime.date(2015, m, 1).strftime('%B'),
'{}.'.format(int(d)))
easter()
python calendar
|
show 3 more comments
up vote
1
down vote
favorite
I need to print every Easter Sunday of 21st century. I need to determine the month: 4 (April) when the day d
is no more than 30; if it's greater, then I need to convert that to the proper day in May. For instance, d=32
would be m=5, d=2
or May 2.
import calendar
import datetime
def easter():
for y in range(2001, 2101):
m2 = 2 * (y % 4)
m4 = 4 * (y % 7)
m19 = 19 * (y % 19)
v2 = (16 + m19) % 30
v1 = (6 * v2 + m4 + m2) % 7
p = v1 + v2
d = 3 + p
print ('Easter Sunday for the year', y, 'is',
datetime.date(2015, m, 1).strftime('%B'),
'{}.'.format(int(d)))
easter()
python calendar
What for February? It's 28 or 29...
– iGian
Nov 7 at 18:04
i need a way to change the moth generally
– Sun Voyager
Nov 7 at 18:08
1
traditional Easter is only in March or April.
– Prune
Nov 7 at 18:08
1
The2015
in the print operation seems a little unexpected. Shouldn't that bey
?
– Jonathan Leffler
Nov 7 at 18:13
1
Yes, Orthodox Easter is part of "traditional". However, I recall now that they can come in the first week of May, also.
– Prune
Nov 7 at 18:14
|
show 3 more comments
up vote
1
down vote
favorite
up vote
1
down vote
favorite
I need to print every Easter Sunday of 21st century. I need to determine the month: 4 (April) when the day d
is no more than 30; if it's greater, then I need to convert that to the proper day in May. For instance, d=32
would be m=5, d=2
or May 2.
import calendar
import datetime
def easter():
for y in range(2001, 2101):
m2 = 2 * (y % 4)
m4 = 4 * (y % 7)
m19 = 19 * (y % 19)
v2 = (16 + m19) % 30
v1 = (6 * v2 + m4 + m2) % 7
p = v1 + v2
d = 3 + p
print ('Easter Sunday for the year', y, 'is',
datetime.date(2015, m, 1).strftime('%B'),
'{}.'.format(int(d)))
easter()
python calendar
I need to print every Easter Sunday of 21st century. I need to determine the month: 4 (April) when the day d
is no more than 30; if it's greater, then I need to convert that to the proper day in May. For instance, d=32
would be m=5, d=2
or May 2.
import calendar
import datetime
def easter():
for y in range(2001, 2101):
m2 = 2 * (y % 4)
m4 = 4 * (y % 7)
m19 = 19 * (y % 19)
v2 = (16 + m19) % 30
v1 = (6 * v2 + m4 + m2) % 7
p = v1 + v2
d = 3 + p
print ('Easter Sunday for the year', y, 'is',
datetime.date(2015, m, 1).strftime('%B'),
'{}.'.format(int(d)))
easter()
python calendar
python calendar
edited Nov 7 at 18:33
grooveplex
531620
531620
asked Nov 7 at 18:02
Sun Voyager
5018
5018
What for February? It's 28 or 29...
– iGian
Nov 7 at 18:04
i need a way to change the moth generally
– Sun Voyager
Nov 7 at 18:08
1
traditional Easter is only in March or April.
– Prune
Nov 7 at 18:08
1
The2015
in the print operation seems a little unexpected. Shouldn't that bey
?
– Jonathan Leffler
Nov 7 at 18:13
1
Yes, Orthodox Easter is part of "traditional". However, I recall now that they can come in the first week of May, also.
– Prune
Nov 7 at 18:14
|
show 3 more comments
What for February? It's 28 or 29...
– iGian
Nov 7 at 18:04
i need a way to change the moth generally
– Sun Voyager
Nov 7 at 18:08
1
traditional Easter is only in March or April.
– Prune
Nov 7 at 18:08
1
The2015
in the print operation seems a little unexpected. Shouldn't that bey
?
– Jonathan Leffler
Nov 7 at 18:13
1
Yes, Orthodox Easter is part of "traditional". However, I recall now that they can come in the first week of May, also.
– Prune
Nov 7 at 18:14
What for February? It's 28 or 29...
– iGian
Nov 7 at 18:04
What for February? It's 28 or 29...
– iGian
Nov 7 at 18:04
i need a way to change the moth generally
– Sun Voyager
Nov 7 at 18:08
i need a way to change the moth generally
– Sun Voyager
Nov 7 at 18:08
1
1
traditional Easter is only in March or April.
– Prune
Nov 7 at 18:08
traditional Easter is only in March or April.
– Prune
Nov 7 at 18:08
1
1
The
2015
in the print operation seems a little unexpected. Shouldn't that be y
?– Jonathan Leffler
Nov 7 at 18:13
The
2015
in the print operation seems a little unexpected. Shouldn't that be y
?– Jonathan Leffler
Nov 7 at 18:13
1
1
Yes, Orthodox Easter is part of "traditional". However, I recall now that they can come in the first week of May, also.
– Prune
Nov 7 at 18:14
Yes, Orthodox Easter is part of "traditional". However, I recall now that they can come in the first week of May, also.
– Prune
Nov 7 at 18:14
|
show 3 more comments
1 Answer
1
active
oldest
votes
up vote
2
down vote
accepted
You have only one adjustment to make: if the day is more than 30, increment the month from April to May and reduce the day by 30:
if d <= 30:
m, d = 4, d
else:
m, d = 5, d-30
print("Easter Sunday for the year", y, "is",
datetime.date(y, m, d).
strftime('%B'), '{}.'.format(int(d)))
Partial output, including the borderline cases:
Easter Sunday for the year 2073 is April 30.
Easter Sunday for the year 2074 is April 22.
Easter Sunday for the year 2075 is April 7.
Easter Sunday for the year 2076 is April 26.
Easter Sunday for the year 2077 is April 18.
Easter Sunday for the year 2078 is May 8.
...
Easter Sunday for the year 2088 is April 18.
Easter Sunday for the year 2089 is May 1.
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
2
down vote
accepted
You have only one adjustment to make: if the day is more than 30, increment the month from April to May and reduce the day by 30:
if d <= 30:
m, d = 4, d
else:
m, d = 5, d-30
print("Easter Sunday for the year", y, "is",
datetime.date(y, m, d).
strftime('%B'), '{}.'.format(int(d)))
Partial output, including the borderline cases:
Easter Sunday for the year 2073 is April 30.
Easter Sunday for the year 2074 is April 22.
Easter Sunday for the year 2075 is April 7.
Easter Sunday for the year 2076 is April 26.
Easter Sunday for the year 2077 is April 18.
Easter Sunday for the year 2078 is May 8.
...
Easter Sunday for the year 2088 is April 18.
Easter Sunday for the year 2089 is May 1.
add a comment |
up vote
2
down vote
accepted
You have only one adjustment to make: if the day is more than 30, increment the month from April to May and reduce the day by 30:
if d <= 30:
m, d = 4, d
else:
m, d = 5, d-30
print("Easter Sunday for the year", y, "is",
datetime.date(y, m, d).
strftime('%B'), '{}.'.format(int(d)))
Partial output, including the borderline cases:
Easter Sunday for the year 2073 is April 30.
Easter Sunday for the year 2074 is April 22.
Easter Sunday for the year 2075 is April 7.
Easter Sunday for the year 2076 is April 26.
Easter Sunday for the year 2077 is April 18.
Easter Sunday for the year 2078 is May 8.
...
Easter Sunday for the year 2088 is April 18.
Easter Sunday for the year 2089 is May 1.
add a comment |
up vote
2
down vote
accepted
up vote
2
down vote
accepted
You have only one adjustment to make: if the day is more than 30, increment the month from April to May and reduce the day by 30:
if d <= 30:
m, d = 4, d
else:
m, d = 5, d-30
print("Easter Sunday for the year", y, "is",
datetime.date(y, m, d).
strftime('%B'), '{}.'.format(int(d)))
Partial output, including the borderline cases:
Easter Sunday for the year 2073 is April 30.
Easter Sunday for the year 2074 is April 22.
Easter Sunday for the year 2075 is April 7.
Easter Sunday for the year 2076 is April 26.
Easter Sunday for the year 2077 is April 18.
Easter Sunday for the year 2078 is May 8.
...
Easter Sunday for the year 2088 is April 18.
Easter Sunday for the year 2089 is May 1.
You have only one adjustment to make: if the day is more than 30, increment the month from April to May and reduce the day by 30:
if d <= 30:
m, d = 4, d
else:
m, d = 5, d-30
print("Easter Sunday for the year", y, "is",
datetime.date(y, m, d).
strftime('%B'), '{}.'.format(int(d)))
Partial output, including the borderline cases:
Easter Sunday for the year 2073 is April 30.
Easter Sunday for the year 2074 is April 22.
Easter Sunday for the year 2075 is April 7.
Easter Sunday for the year 2076 is April 26.
Easter Sunday for the year 2077 is April 18.
Easter Sunday for the year 2078 is May 8.
...
Easter Sunday for the year 2088 is April 18.
Easter Sunday for the year 2089 is May 1.
answered Nov 7 at 18:22
Prune
41.1k133454
41.1k133454
add a comment |
add a comment |
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53195190%2feaster-change-month%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
What for February? It's 28 or 29...
– iGian
Nov 7 at 18:04
i need a way to change the moth generally
– Sun Voyager
Nov 7 at 18:08
1
traditional Easter is only in March or April.
– Prune
Nov 7 at 18:08
1
The
2015
in the print operation seems a little unexpected. Shouldn't that bey
?– Jonathan Leffler
Nov 7 at 18:13
1
Yes, Orthodox Easter is part of "traditional". However, I recall now that they can come in the first week of May, also.
– Prune
Nov 7 at 18:14