libcproject
C static library easier to use than libc (C standard library).
date.h
Go to the documentation of this file.
1 #ifndef __LIBCPROJECT_DATE__
2 #define __LIBCPROJECT_DATE__
3 
4 #include <errno.h>
5 #include <stdbool.h>
6 #include <stdint.h>
7 #include <stdio.h>
8 #include <stdlib.h>
9 #include <time.h>
10 
11 #include "convert.h"
12 #include "mathematics.h"
13 #include "string.h"
14 #include "types.h"
15 
16 #define SECONDS_PER_MINUTE 60
17 #define SECONDS_PER_HOUR (60 * SECONDS_PER_MINUTE)
18 #define SECONDS_PER_DAY (24 * SECONDS_PER_HOUR)
19 #define MILLISECONDS_PER_SECOND 1000
20 
25 struct date {
31  uint16_t year;
32 
37  uint8_t month;
38 
43  uint8_t day;
44 
49  uint8_t hours;
50 
55  uint8_t minutes;
56 
61  uint8_t seconds;
62 
67  uint16_t milliseconds;
68 
74 };
75 
83 struct date *date_copy(struct date *date_to_copy);
84 
93 
102 
111 
120 
129 
138 
147 
156 
165 
179 
193 
203 struct date *date_from_iso_string(string_t iso_string);
204 
212 uint8_t date_get_days_of_month(uint8_t month, uint16_t year);
213 
235 
244 
253 
261 uint64_t date_convert_days_to_seconds(uint64_t days);
262 
272 uint64_t date_convert_hms_to_seconds(uint8_t hours, uint8_t minutes, uint8_t seconds);
273 
281 uint64_t date_to_total_seconds(struct date *date);
282 
291 uint64_t date_duration_seconds_between_2_dates(struct date *date1, struct date *date2);
292 
302 void date_add_hours(struct date *date, int64_t hours);
303 
313 void date_add_days(struct date *date, int64_t days);
314 
323 void date_to_utc(struct date *date);
324 
332 
340 
348 uint16_t date_get_age(struct date *birth_date, struct date *current_date);
349 
350 #endif
void date_add_hours(struct date *date, int64_t hours)
Add hours to the date, managing the day, month, year changes if necessary.
uint64_t date_to_total_seconds(struct date *date)
Convert a date to total seconds.
uint64_t date_convert_hms_to_seconds(uint8_t hours, uint8_t minutes, uint8_t seconds)
Convert hours, minutes, and seconds to seconds.
uint64_t date_duration_seconds_between_2_dates(struct date *date1, struct date *date2)
Calculate the duration in seconds between 2 dates.
uint16_t milliseconds
Definition: date.h:67
struct date * date_copy(struct date *date_to_copy)
Return the copy of a date.
uint8_t hours
Definition: date.h:49
uint64_t date_convert_milliseconds_to_seconds(uint16_t milliseconds)
Convert milliseconds to seconds.
bool date_get_is_valid(struct date *date)
Check if the date is valid (all fields are possible).
uint16_t year
Definition: date.h:31
bool date_get_is_leap_year(uint16_t year)
Determine if a year is a leap year.
struct date * date_get_now_local()
Get the current date in local time.
string_t date_to_iso_string(struct date *date)
String representing the date in the date time string format, a simplified format based on ISO 8601,...
bool date_get_is_valid_year(uint16_t year)
Check if a year is valid, between [0, 9999] (inclusive).
bool date_get_is_valid_milliseconds(uint16_t milliseconds)
Check if milliseconds are valid, between [0, 999] (inclusive).
struct date * date_from_iso_string(string_t iso_string)
Create a date from an ISO 8601 string, with the format YYYY-MM-DDTHH:mm:ss.sssZ.
uint8_t seconds
Definition: date.h:61
uint8_t month
Definition: date.h:37
bool date_get_is_valid_month(uint8_t month)
Check if a month is valid, between [1, 12] (inclusive).
uint8_t minutes
Definition: date.h:55
bool date_get_is_valid_hours(uint8_t hours)
Check if hours are valid, between [0, 23] (inclusive).
bool date_get_is_valid_seconds(uint8_t seconds)
Check if seconds are valid, between [0, 59] (inclusive).
uint64_t date_convert_days_to_seconds(uint64_t days)
Convert days to seconds.
uint64_t date_convert_seconds_to_milliseconds(uint64_t seconds)
Convert seconds to milliseconds.
bool date_get_is_valid_timezone_utc_offset(int8_t timezone_utc_offset)
Check if the timezone UTC offset is valid, between [-12, 14] (inclusive).
bool date_get_is_valid_minutes(uint8_t minutes)
Check if minutes are valid, between [0, 59] (inclusive).
void date_add_days(struct date *date, int64_t days)
Adds days to the date, managing month and year changes as needed.
bool date_get_is_valid_day(uint8_t day)
Check if a day is valid, between [1, 31] (inclusive).
uint16_t date_get_age(struct date *birth_date, struct date *current_date)
Calculates the age of a person based on their birth date.
void date_to_utc(struct date *date)
Transform the date with a Timezone UTC Offset to UTC (timezone_utc_offset = 0).
string_t date_to_iso_string_without_time(struct date *date)
String representing the date in the ISO 8601 format, without time information (YYYY-MM-DD).
uint8_t date_get_days_of_month(uint8_t month, uint16_t year)
Get number of days in one month [1, 12].
struct date * date_get_now_utc()
Get the current date in UTC.
uint8_t day
Definition: date.h:43
int8_t timezone_utc_offset
Definition: date.h:73
Date object representing a single moment in time.
Definition: date.h:25
char * string_t
Definition: types.h:8