Date wih weekdays and leap year

A place for Ren'Py tutorials and reusable Ren'Py code.
Forum rules
Do not post questions here!

This forum is for example code you want to show other people. Ren'Py questions should be asked in the Ren'Py Questions and Announcements forum.
Post Reply
Message
Author
socradeath
Newbie
Posts: 7
Joined: Sat Feb 09, 2019 2:09 am
Contact:

Date wih weekdays and leap year

#1 Post by socradeath »

Code: Select all


init python:
    weekdays = ("mon","tue","wed","thu","fri","sat","sun")
    class Date:
        def __init__(self):
            self.year = 2019
            self.month = 2
            self.day = 28
            self.weekday = weekdays[3]

        def end_day(self):
            self.day += 1
            self.weekday = weekdays[weekdays.index(self.weekday)-6]
            if self.month in (1,3,5,7,8,10,12):
                if self.day > 31:
                    self.day = 1
                    self.month += 1
            elif self.month in (4,6,9,11):
                if self.day > 30:
                    self.day = 1
                    self.month += 1
           
	    #february in leap year
            else :
                # devide by 4
                if (self.year // 4) == 0 :
                    # devide by 100
                    if (self.year // 100) == 0 :
                        # devide by 400
                        if (self.year // 400) == 0 :
                            #leap year
                            __d = 29
                        else:
                            #normal year
                            __d = 28
                    else:
                        #devide by 4 - leap year
                        __d = 29
                else:
                    #normal year
                    __d = 28

                if self.day > __d:
                    self.day = 1
                    self.month += 1
            if self.month > 12:
                self.month = 1
                self.year += 1



        # get weekdays
        def get_weekdays(self):
            if self.month < 3 :
                __m = self.month + 12
                __y = self.year - 1
            else :
                __m = self.month
                __y = self.year
            __weekday = ((__y+__y/4-__y/100+__y/400+(13*__m+8)/5+self.day) % 7) - 1
            self.weekday = weekdays[__weekday]
            return weekdays[__weekday]
        
        def return_date(self):
            return unicode(self.year)+". "+unicode(self.month)+". "+unicode(self.day)




Last edited by socradeath on Thu Feb 28, 2019 10:31 am, edited 1 time in total.

socradeath
Newbie
Posts: 7
Joined: Sat Feb 09, 2019 2:09 am
Contact:

Re: Date wih weekdays

#2 Post by socradeath »

I started with monday, but it would be better that start with sunday in many case.

To start with sunday,
weekdays = ["sun","mon",....]

...and...

__weekday = ((__y+__y/4-__y/100+__y/400+(13*__m+8)/5+self.day) % 7)

norrissang
Newbie
Posts: 4
Joined: Tue Jul 03, 2018 9:17 am
Contact:

Re: Date wih weekdays and leap year

#3 Post by norrissang »

Thanks. Is there anyway to show it?

rayminator
Miko-Class Veteran
Posts: 793
Joined: Fri Feb 09, 2018 12:05 am
Location: Canada
Contact:

Re: Date wih weekdays and leap year

#4 Post by rayminator »

need more information how to use this

Post Reply

Who is online

Users browsing this forum: No registered users