Calcule le décalage horaire en France (+1 en été, +2 en hiver) à partir d'une heure UTC et d'une date.
Fork of FrenchTime by
FrenchTime.cpp@6:803a1cf4eb73, 2016-11-23 (annotated)
- Committer:
- Marcus_2B
- Date:
- Wed Nov 23 14:46:23 2016 +0000
- Revision:
- 6:803a1cf4eb73
- Parent:
- 5:cf036371055d
Publish 1
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Marcus_2B | 0:2ef6fb83757c | 1 | #include "FrenchTime.h" |
Marcus_2B | 0:2ef6fb83757c | 2 | |
Marcus_2B | 0:2ef6fb83757c | 3 | |
Marcus_2B | 0:2ef6fb83757c | 4 | |
Marcus_2B | 0:2ef6fb83757c | 5 | |
Marcus_2B | 0:2ef6fb83757c | 6 | uint8_t FrenchTime::frenchTimeOffset(uint8_t day, uint8_t month, int year) |
Marcus_2B | 0:2ef6fb83757c | 7 | { |
Marcus_2B | 0:2ef6fb83757c | 8 | //Avril, Mai, Juin, Juillet, Aout, Septembre |
Marcus_2B | 0:2ef6fb83757c | 9 | if (month > MARS && month < OCTOBRE) { |
Marcus_2B | 0:2ef6fb83757c | 10 | return UTC_TIME_OFFSET + 1; |
Marcus_2B | 0:2ef6fb83757c | 11 | } |
Marcus_2B | 0:2ef6fb83757c | 12 | // Janvier, Février, Novembre, Décembre |
Marcus_2B | 0:2ef6fb83757c | 13 | else if (month < MARS || month > OCTOBRE) { |
Marcus_2B | 0:2ef6fb83757c | 14 | return UTC_TIME_OFFSET; |
Marcus_2B | 0:2ef6fb83757c | 15 | } |
Marcus_2B | 0:2ef6fb83757c | 16 | //Mars ou Octobre |
Marcus_2B | 0:2ef6fb83757c | 17 | else { |
Marcus_2B | 0:2ef6fb83757c | 18 | if (MARS == month) { |
Marcus_2B | 0:2ef6fb83757c | 19 | if (day >= lastSundayOfMonth(month, year)) { |
Marcus_2B | 0:2ef6fb83757c | 20 | return UTC_TIME_OFFSET + 1; |
Marcus_2B | 0:2ef6fb83757c | 21 | } |
Marcus_2B | 0:2ef6fb83757c | 22 | } |
Marcus_2B | 0:2ef6fb83757c | 23 | //OCTOBRE |
Marcus_2B | 0:2ef6fb83757c | 24 | else { |
Marcus_2B | 0:2ef6fb83757c | 25 | if (day < lastSundayOfMonth(month, year)) { |
Marcus_2B | 0:2ef6fb83757c | 26 | return UTC_TIME_OFFSET + 1; |
Marcus_2B | 0:2ef6fb83757c | 27 | } |
Marcus_2B | 0:2ef6fb83757c | 28 | } |
Marcus_2B | 0:2ef6fb83757c | 29 | return UTC_TIME_OFFSET; |
Marcus_2B | 0:2ef6fb83757c | 30 | } |
Marcus_2B | 0:2ef6fb83757c | 31 | } |
Marcus_2B | 0:2ef6fb83757c | 32 | |
Marcus_2B | 0:2ef6fb83757c | 33 | |
Marcus_2B | 0:2ef6fb83757c | 34 | |
Marcus_2B | 0:2ef6fb83757c | 35 | uint8_t FrenchTime::lastSundayOfMonth(uint8_t m, int y) |
Marcus_2B | 0:2ef6fb83757c | 36 | { |
Marcus_2B | 0:2ef6fb83757c | 37 | for (uint8_t d = DAYS_IN_MARS; d >= 1; d--) { |
Marcus_2B | 0:2ef6fb83757c | 38 | |
Marcus_2B | 0:2ef6fb83757c | 39 | if (FrenchTime::dayOfWeek(d, m, y) == 0) { |
Marcus_2B | 0:2ef6fb83757c | 40 | return d; |
Marcus_2B | 0:2ef6fb83757c | 41 | } |
Marcus_2B | 0:2ef6fb83757c | 42 | } |
Marcus_2B | 0:2ef6fb83757c | 43 | return 0; |
Marcus_2B | 0:2ef6fb83757c | 44 | } |
Marcus_2B | 0:2ef6fb83757c | 45 | |
Marcus_2B | 0:2ef6fb83757c | 46 | |
Marcus_2B | 0:2ef6fb83757c | 47 | |
Marcus_2B | 0:2ef6fb83757c | 48 | uint8_t FrenchTime::dayOfWeek(uint8_t d, uint8_t m, int y) |
Marcus_2B | 0:2ef6fb83757c | 49 | { |
Marcus_2B | 5:cf036371055d | 50 | //Algorithme de Mike Keith |
Marcus_2B | 5:cf036371055d | 51 | int weekDay = 0, z = 0; |
Marcus_2B | 0:2ef6fb83757c | 52 | |
Marcus_2B | 0:2ef6fb83757c | 53 | if (m >= 3) { |
Marcus_2B | 5:cf036371055d | 54 | z = y; |
Marcus_2B | 5:cf036371055d | 55 | weekDay = (((23 * m) / 9) + d + 4 + y + (z / 4) - (z / 100) + (z / 400) - 2) % 7; |
Marcus_2B | 0:2ef6fb83757c | 56 | } else { |
Marcus_2B | 5:cf036371055d | 57 | z = y - 1; |
Marcus_2B | 5:cf036371055d | 58 | weekDay = (((23 * m) / 9) + d + 4 + y + (z / 4) - (z / 100) + (z / 400)) % 7; |
Marcus_2B | 0:2ef6fb83757c | 59 | } |
Marcus_2B | 0:2ef6fb83757c | 60 | return (uint8_t)weekDay; |
Marcus_2B | 0:2ef6fb83757c | 61 | } |
Marcus_2B | 0:2ef6fb83757c | 62 | |
Marcus_2B | 0:2ef6fb83757c | 63 |