Easter change month











up vote
1
down vote

favorite
2












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()









share|improve this question
























  • 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 be y?
    – 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

















up vote
1
down vote

favorite
2












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()









share|improve this question
























  • 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 be y?
    – 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















up vote
1
down vote

favorite
2









up vote
1
down vote

favorite
2






2





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()









share|improve this question















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






share|improve this question















share|improve this question













share|improve this question




share|improve this question








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




    The 2015 in the print operation seems a little unexpected. Shouldn't that be y?
    – 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










  • 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 be y?
    – 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














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.





share|improve this answer





















    Your Answer






    StackExchange.ifUsing("editor", function () {
    StackExchange.using("externalEditor", function () {
    StackExchange.using("snippets", function () {
    StackExchange.snippets.init();
    });
    });
    }, "code-snippets");

    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "1"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














     

    draft saved


    draft discarded


















    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

























    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.





    share|improve this answer

























      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.





      share|improve this answer























        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.





        share|improve this answer












        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.






        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Nov 7 at 18:22









        Prune

        41.1k133454




        41.1k133454






























             

            draft saved


            draft discarded



















































             


            draft saved


            draft discarded














            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





















































            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







            這個網誌中的熱門文章

            Hercules Kyvelos

            Tangent Lines Diagram Along Smooth Curve

            Yusuf al-Mu'taman ibn Hud