diff options
Diffstat (limited to 'src/date.c')
| -rw-r--r-- | src/date.c | 30 | 
1 files changed, 30 insertions, 0 deletions
| @@ -23,6 +23,36 @@ ph_date_t date_from_numbers(unsigned year, unsigned month, unsigned day)  	return year << 9 | month << 5 | day;  } +struct tm tm_from_date(ph_date_t date) +{ +	unsigned year = 0; +	unsigned month = 0; +	unsigned day = 0; +	date_split(date, &year, &month, &day); + +	struct tm time = {.tm_year = year - 1900, .tm_mon = month - 1, .tm_mday = day}; +	mktime(&time); +	return time; +} + +ph_date_t date_from_tm(struct tm time) +{ +	unsigned year = time.tm_year + 1900; +	unsigned month = time.tm_mon + 1; +	unsigned day = time.tm_mday; +	return date_from_numbers(year, month, day); +} + +ph_date_t current_date() +{ +	time_t t = time(NULL); +	struct tm *time = localtime(&t); +	unsigned year = time->tm_year + 1900; +	unsigned month = time->tm_mon + 1; +	unsigned day = time->tm_mday; +	return date_from_numbers(year, month, day); +} +  void date_split(ph_date_t date, unsigned *year, unsigned *month, unsigned *day)  {  	if (year) *year  = date >> 9; | 
