SdFat
Loading...
Searching...
No Matches
Macros | Functions
DateLib.h File Reference
#include <stdint.h>
Include dependency graph for DateLib.h:

Macros

#define EPOCH_YEAR   1970
 
#define USE_1901_2099   1
 

Functions

uint8_t dayOfWeek (uint16_t Y, uint8_t M, uint8_t D)
 
uint16_t dayOfYear (uint16_t Y, uint8_t M, uint8_t D)
 
uint8_t dayOfYearToDay (uint16_t doy, uint16_t Y, uint8_t M)
 
uint8_t dayOfYearToMonth (uint16_t doy, uint16_t Y)
 
uint16_t daysBeforeMonth (uint16_t Y, uint8_t M)
 
uint8_t daysInMonth (uint16_t Y, uint8_t M)
 
uint16_t epochDay (uint16_t Y, uint8_t M, uint8_t D)
 
uint8_t epochDayToDayOfWeek (uint16_t eday)
 
uint16_t epochDayToYear (uint16_t eday)
 
void epochDayToYMD (uint16_t eday, uint16_t *Y, uint8_t *M, uint8_t *D)
 
bool leap (uint16_t Y)
 

Detailed Description

Copyright (c) 2011-2022 Bill Greiman This file is part of the SdFat library for SD memory cards.

MIT License

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Macro Definition Documentation

◆ EPOCH_YEAR

#define EPOCH_YEAR   1970

EPOCH starts on Jan 1 of EPOCH_YEAR.

◆ USE_1901_2099

#define USE_1901_2099   1

Various calendar algorithms. Set USE_1901_2099 nonzero for year in [1901,2099].

Function Documentation

◆ dayOfWeek()

uint8_t dayOfWeek ( uint16_t Y,
uint8_t M,
uint8_t D )
inline

Day of week with Sunday == 0.

Parameters
[in]Yyear
[in]Mmonth 1 <= M <= 12
[in]Dday 1 <= D <= (last day of month)
Returns
Day of week [0,6].

◆ dayOfYear()

uint16_t dayOfYear ( uint16_t Y,
uint8_t M,
uint8_t D )
inline

Day of year with Jan1 == 0.

Parameters
[in]Yyear in range supported by leap().
[in]Mmonth 0 < M < 13
[in]Dday 0 < D <= length of month
Returns
Day of year [0, 365]

◆ dayOfYearToDay()

uint8_t dayOfYearToDay ( uint16_t doy,
uint16_t Y,
uint8_t M )
inline

Day of year to day

Parameters
[in]doyday of year 0 <= yday <= 365
[in]Yyear
[in]Mmonth 1 <= M <= 12
Returns
day of month Based on http://ss64.net/merlyn/daycount.htm#DYZ

◆ dayOfYearToMonth()

uint8_t dayOfYearToMonth ( uint16_t doy,
uint16_t Y )
inline

Day of year to month

Parameters
[in]doyday of year 0 <= yday <= 365
[in]Yyear
Returns
month [1,12] Based on http://ss64.net/merlyn/daycount.htm#DYZ

◆ daysBeforeMonth()

uint16_t daysBeforeMonth ( uint16_t Y,
uint8_t M )
inline

Number of days in the year before the current month

Parameters
[in]Yyear
[in]Mmonth 0 < M < 13
Returns
days in year before current month [0, 335] Probably from "Astronomical Algorithms" ISBN 0-943396-61-1

◆ daysInMonth()

uint8_t daysInMonth ( uint16_t Y,
uint8_t M )
inline

Number of days in a month.

Parameters
[in]Yyear in range supported by leap().
[in]Mmonth 0 < M < 13
Returns
Count of days in month [1, 31].

◆ epochDay()

uint16_t epochDay ( uint16_t Y,
uint8_t M,
uint8_t D )
inline

Count of days since Epoch. 1900 < EPOCH_YEAR, MAX_YEAR < 2100, (MAX_YEAR - EPOCH_YEAR) < 178.

Parameters
[in]Yyear (EPOCH_YEAR <= Y <= MAX_YEAR)
[in]Mmonth 1 <= M <= 12
[in]Dday 1 <= D <= 31
Returns
Count of days since epoch

Derived from Zeller's congruence

◆ epochDayToDayOfWeek()

uint8_t epochDayToDayOfWeek ( uint16_t eday)
inline

epoch day to day of week (Sunday == 0) 1900 < EPOCH_YEAR, MAX_YEAR < 2100, (MAX_YEAR - EPOCH_YEAR) < 178.

Parameters
[in]edaycount of days since epoch.
Returns
day of week (Sunday == 0)

◆ epochDayToYear()

uint16_t epochDayToYear ( uint16_t eday)
inline

Day of epoch to year 1900 < EPOCH_YEAR, MAX_YEAR < 2100, (MAX_YEAR - EPOCH_YEAR) < 178.

Parameters
[in]edaycount of days since epoch
Returns
year for count of days since epoch

◆ epochDayToYMD()

void epochDayToYMD ( uint16_t eday,
uint16_t * Y,
uint8_t * M,
uint8_t * D )
inline

epoch day to year, month, day 1900 < EPOCH_YEAR, MAX_YEAR < 2100, (MAX_YEAR - EPOCH_YEAR) < 178. Based on "Software, Practice and Experience", Vol. 23 (1993) page 384.

Parameters
[in]edaycount of days since epoch
[out]Yyear
[out]Mmonth
[out]Dday

◆ leap()

bool leap ( uint16_t Y)
inline

Determine leap year.

Parameters
[in]Yyear
Returns
true if Y is a leap year