SdFat
Macros | Functions
DateAlgorithmsV2.h File Reference

Date utility functions. More...

Macros

#define EPOCH_YEAR   2000
 
#define USE_FULL_LEAP   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)
 
uint16_t daysSinceEpoch (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)
 
uint8_t monthLength (uint16_t Y, uint8_t M)
 

Detailed Description

Date utility functions.

Copyright (c) 2011-2020 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   2000

EPOCH starts on Jan 1 of EPOCH_YEAR.

◆ USE_FULL_LEAP

#define USE_FULL_LEAP   1

Set USE_FULL_LEAP zero if 1900 < year and year < 2100.

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 
)

Day of year to month

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 
)

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

◆ daysSinceEpoch()

uint16_t daysSinceEpoch ( 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

◆ monthLength()

uint8_t monthLength ( uint16_t  Y,
uint8_t  M 
)
inline

Number of days in a month.

Parameters
[in]Yyear
[in]Mmonth 0 < M < 13
Returns
Count of days in month [1, 31].