bugAVR C Runtime Library - Bugs: bug #44327, eu_dst() is broken

 
 

bug #44327: eu_dst() is broken

Submitted by:  None
Submitted on:  Fri 20 Feb 2015 09:27:48 PM UTC  
 
Category: LibrarySeverity: 3 - Normal
Priority: 5 - NormalItem Group: Header files
Status: NonePercent Complete: 0%
Assigned to: NoneOriginator Email: -unavailable-
Open/Closed: OpenRelease: Any
Fixed Release: None

Add a New Comment(Rich Markup)
   

You are not logged in

Please log in, so followups can be emailed to you.

 

Fri 20 Feb 2015 09:27:48 PM UTC, original submission:

The function eu_dst(), defined in include/util/eu_dst.h, is intended to
implement the European daylight saving rules. There is an error at the
end of the function, where the comparison between the current day of the
month and the day of the last Sunday is reversed. The error is repeated
four times. This makes the function be almost always wrong in March and
October. There is also an off-by-one error earlier in the function:
whenever the last Sunday is the 25th, the function believes it's the
32nd.

I noticed those errors while trying to benchmark my own implementation
of eu_dst() against the one provided by avr-libc. Then, rather than
fixing the broken function, I suggest replacing it with my
implementation:

int eu_dst(const time_t * timer, int32_t * z)
{
uint32_t t = *timer;
if ((uint8_t)(t >> 24) >= 194) t -= 3029443200U;
t = (t + 655513200) / 604800 * 28;
if ((uint16_t)(t % 1461) < 856) return 3600;
else return 0;
}

This version is based on the fact that the European DST function is
almost periodic. Actually, it is as close to periodic as possible given
the constraint that the transitions are only allowed on Sundays at 01:00
UTC. Since this constraint is also periodic, this allows for a compact
arithmetic solution.

I tested my implementation for correctness on my PC against the system's
localtime(), for every full hour between the epoch (2000-01-01) and the
end of time (2136-02-07). I also tested it on an Arduino Uno
(ATmega328P) against a precomputed table of all the transition times,
both at the transition and the second right before.

In terms of size, this function compiles 52% smaller than the one
provided by eu_dst.h. If we account for the dependencies, it is 75%
smaller (204 vs. 826 bytes). It is also 3 times faster:
about 1250 — 1280 cycles versus 3300 – 4500.

Regards,

Edgar Bonet.

Anonymous

 

(Note: upload size limit is set to 16384 kB, after insertion of the required escape characters.)

Attach File(s):
   
   
Comment:
   

No files currently attached

 

Depends on the following items: None found

Items that depend on this one: None found

 

Carbon-Copy List
  • -unavailable- added by the2masters
  • -unavailable- added by None (Submitted the item)
  •  

    Please enter the title of George Orwell's famous dystopian book (it's a date):

     

     

    Follows 1 latest change.

    Date Changed By Updated Field Previous Value => Replaced By
    Wed 21 Sep 2016 09:40:50 AM UTCthe2mastersCarbon-Copy-=>Added -unavailable-

    Back to the top


    Powered by Savane 3.1-cleanup1