amiro-os / core / src / aos_time.c @ adcbcf83
History | View | Annotate | Download (3.208 KB)
1 |
/*
|
---|---|
2 |
AMiRo-OS is an operating system designed for the Autonomous Mini Robot (AMiRo) platform.
|
3 |
Copyright (C) 2016..2019 Thomas Schöpping et al.
|
4 |
|
5 |
This program is free software: you can redistribute it and/or modify
|
6 |
it under the terms of the GNU General Public License as published by
|
7 |
the Free Software Foundation, either version 3 of the License, or
|
8 |
(at your option) any later version.
|
9 |
|
10 |
This program is distributed in the hope that it will be useful,
|
11 |
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
12 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
13 |
GNU General Public License for more details.
|
14 |
|
15 |
You should have received a copy of the GNU General Public License
|
16 |
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
17 |
*/
|
18 |
|
19 |
/**
|
20 |
* @file aos_time.c
|
21 |
* @brief Time related function implementations.
|
22 |
*
|
23 |
* @addtogroup aos_time
|
24 |
* @{
|
25 |
*/
|
26 |
|
27 |
#include <amiroos.h> |
28 |
|
29 |
/******************************************************************************/
|
30 |
/* LOCAL DEFINITIONS */
|
31 |
/******************************************************************************/
|
32 |
|
33 |
/******************************************************************************/
|
34 |
/* EXPORTED VARIABLES */
|
35 |
/******************************************************************************/
|
36 |
|
37 |
/******************************************************************************/
|
38 |
/* LOCAL TYPES */
|
39 |
/******************************************************************************/
|
40 |
|
41 |
/******************************************************************************/
|
42 |
/* LOCAL VARIABLES */
|
43 |
/******************************************************************************/
|
44 |
|
45 |
/******************************************************************************/
|
46 |
/* LOCAL FUNCTIONS */
|
47 |
/******************************************************************************/
|
48 |
|
49 |
/******************************************************************************/
|
50 |
/* EXPORTED FUNCTIONS */
|
51 |
/******************************************************************************/
|
52 |
|
53 |
/**
|
54 |
* @brief Calculates the day of week from a specified date.
|
55 |
*
|
56 |
* @param[in] day The day of the date.
|
57 |
* @param[in] month The month of the daste.
|
58 |
* @param[in] year The year of the date.
|
59 |
*
|
60 |
* @return The day of week depending on the date represented in ISO format (1 = Monday to 7 = Sunday).
|
61 |
*/
|
62 |
uint8_t aosTimeDayOfWeekFromDate(const uint16_t day, const uint8_t month, const uint16_t year) |
63 |
{ |
64 |
aosDbgCheck(day >= 1 && day <= 31); |
65 |
aosDbgCheck(month >= 1 && month <= 12); |
66 |
|
67 |
/*
|
68 |
* Implementation of Zeller's congruence for Gregorian calender.
|
69 |
* See https://en.wikipedia.org/wiki/Zeller%27s_congruence for details.
|
70 |
*/
|
71 |
const uint32_t q = day;
|
72 |
const uint32_t m = (month >= 3) ? month : month + 12; |
73 |
const uint32_t K = year % 100; |
74 |
const uint32_t J = year / 100; |
75 |
|
76 |
const uint32_t h = (q + ((13 * (m + 1)) / 5) + K + (K / 4) + (J / 4) - (2 * J)) % 7; |
77 |
|
78 |
return ((h + 5) % 7) + 1; |
79 |
} |
80 |
|
81 |
/** @} */
|