1

The datasheets ambiguously say...

A leap year is set whenever the year value is a multiple of four (such as 04, 08, 12, 88, 92, or 96).

enter image description here

Is zero a multiple of four? This is more of a philosophical question than a specification. The shown series starts at 4 and ends with 96, strongly hinting that the good folks at Seiko do not think that zero is a multiple of four.

Turns out to be a critical fact if you are trying to measure timespans - if you pick wrong then any date after Mar 1, 00 may be off by a day!

bigjosh
  • 10,088
  • 32
  • 52
  • Y2k bug anyone.... – Solar Mike Jul 15 '18 at 22:14
  • @SolarMike I was still rather young when people were freaking out about that problem but I remember when I was in college, I was thinking, "You'd think the year 2047 would pose more of a problem than 2000...." But I suppose if your only notation of the date were the last two digits, then I can see why people would freak out. –  Jul 15 '18 at 22:34

1 Answers1

6

Despite the misleading series in the datasheet, the RX8900 does consider the year "00" to be a leap year.

I tested this empirically by setting the date to Feb 28th, 00 and letting it roll to see what the next day was...

enter image description here

I also checked Feb 28th, 01 as a control... enter image description here

If you are looking at this question, then this code might be of use to you...

// This table of days per month came from the RX8900 datasheet page 9

static uint8_t daysInMonth( uint8_t m , uint8_t y) {

    switch ( m ) {

        case  1:
        case  3:
        case  5:
        case  7:
        case  8:
        case 10:
        case 12:    // Interestingly, we will never hit 12. See why?
                    return 31 ;

        case  4:
        case  6:
        case  9:
        case 11:
                    return 30 ;

        case  2:

                    if ( y % 4 == 0 ) {         // "A leap year is set whenever the year value is a multiple of four (such as 04, 08, 12, 88, 92, or 96)."
                                                // Empirical testing also shows that 00 is a leap year to the RX8900
                                                // https://electronics.stackexchange.com/questions/385952/does-the-epson-rx8900-real-time-clock-count-the-year-00-as-a-leap-year

                        return 29 ;             // "February in leap year 01, 02, 03 ... 28, 29, 01

                    } else {

                        return 28;              // February in normal year 01, 02, 03 ... 28, 01, 02
                    }

    }

    __builtin_unreachable();

}

static const uint32_t rx8900_days_per_century = ( 100UL * 365 ) + 25;       // 25 leap years in every RX8900 century

// Convert the y/m/d values from the RX8900 to a count of the number of days since 00/1/1
// rx8900_date_to_days( 0 , 1, 1 ) = 0
// rx8900_date_to_days( 0 , 1, 31) = 30
// rx8900_date_to_days( 0 , 2, 1 ) = 31
// rx8900_date_to_days( 1 , 1, 1 ) = 366 (00 is a leap year!)

static uint32_t rx8900_date_to_days( uint8_t c , uint8_t y , uint8_t m, uint8_t d ) {

    uint32_t dayCount=0;

    // Count days in centuries past

    dayCount += rx8900_days_per_century * c;

    // Count days in years past this century

    for( uint8_t y_scan = 0; y_scan < y ; y_scan++ ) {

        if ( y_scan % 4 == 0 ) {
            // leap year every 4 years on RX8900
            dayCount += 366UL;      // 366 days per year past in leap years

        } else {

            dayCount += 365UL;      // 365 days per year past in normal years
        }

    }


    // Now accumulate the days in months past so far this year

    for( uint8_t m_scan = 1; m_scan < m ; m_scan++ ) {      // Don't count current month

        dayCount += daysInMonth( m_scan , y );       // Year is needed to count leap day in feb in leap years.


    }

    // Now include the passed days so far this month

    dayCount += (uint32_t) d-1;     // 1st day of a month is 1, so if it is the 1st of the month then no days has elapsed this month yet.

    return dayCount;

}
bigjosh
  • 10,088
  • 32
  • 52