elpaso / Rtc_Pcf8563

Arduino Pcf8563 RTC library. A fixed/expanded version of the original Rtc_Pcf8563
29 stars 29 forks source link

How about adding weekday calculation and other functions? #3

Open southwolf opened 10 years ago

southwolf commented 10 years ago

Hello Alessandro, I‘m thinking of weekday calculation and other functions, but more code means more space, and not all people would use weekday in their project, I'm not sure whether it is suitable to add them into the library.

int calculateWeekday()
{
    int c = 0, y = 0, m = 0;
    c = (century == 0) ? 20 : 19;
    y = (month < 3) ? (year - 1) : year;
    m = (month < 3) ? (month + 12) : month;
    return (c/4 - c*2 + y + y / 4 + (13 * (m+1) / 5) + day - 1) % 7;
}

char* getStrWeekday()
{

    switch(calculateWeekday())
    {
    case 0:
        return "Sunday";
    case 1:
        return "Monday";
    case 2:
        return "Tuesday";
    case 3:
        return "Thursday";
    case 4:
        return "Wednesday";
    case 5:
        return "Friday";
    case 6:
        return "Saturday";
    }
}

boolean isLeapYear() {
    return((year != 0 && year % 4 == 0) || (year == 0 && century == 0));
}

P.S. I'm using this library on Microduino-RTC.

elpaso commented 10 years ago

Hi,

thank you for your contribution. I think that you can make those additions, the compiler and linker will not include code if it's not used.

Also, take a look to this library:

https://github.com/jcw/rtclib

it's more complete and supports more chips.

cevich commented 9 years ago

This is resolved by #10 (and bugfix in #11)