forked from Vhex-Kernel-Core/fxlibc
31 lines
597 B
C
31 lines
597 B
C
|
#ifndef __TIMEUTIL_H__
|
||
|
# define __TIMEUTIL_H__
|
||
|
|
||
|
#ifdef __cplusplus
|
||
|
extern "C" {
|
||
|
#endif
|
||
|
|
||
|
#include <time.h>
|
||
|
#include <stdbool.h>
|
||
|
|
||
|
/* Check whether a given year is a leap year. */
|
||
|
static inline bool isleap(int yr)
|
||
|
{
|
||
|
if(!(yr % 400)) return true;
|
||
|
if(!(yr % 100)) return false;
|
||
|
return !(yr & 3);
|
||
|
}
|
||
|
|
||
|
/* Number of days for the given month (0..11) and year. */
|
||
|
static inline int daysin(int month, int yr)
|
||
|
{
|
||
|
static char count[12] = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
|
||
|
return count[month] + (month == 1 && isleap(yr));
|
||
|
}
|
||
|
|
||
|
#ifdef __cplusplus
|
||
|
}
|
||
|
#endif
|
||
|
|
||
|
#endif /*__TIMEUTIL_H__*/
|