Cross-platform C SDK logo
EspañolEnglish
Cross-platform C SDK

Dates

❮ Back
Next ❯

Date manipulation functions.


#Header

#include <core/date.h>


#Functions

Datedate_system (void)
Datedate_pack (...)
Datedate_add_seconds (...)
Datedate_add_minutes (...)
Datedate_add_hours (...)
Datedate_add_days (...)
int16_tdate_year (void)
intdate_cmp (...)
int64_tdate_ellapsed_seconds (...)
bool_tdate_between (...)
bool_tdate_is_null (...)
bool_tdate_is_valid (...)
week_day_tdate_weekday (...)
bool_tdate_is_leap (...)
uint8_tdate_month_days (...)
int32_tdate_to_days (...)
Datedate_from_days (...)
const String*date_format (...)

#Types and Constants

DatekDATE_NULL

A series of functions are included within core to work with dates.

❮ Back
Next ❯

#kDATE_NULL

Date kDATE_NULL;

Represents an invalid date.


#date_system ()

Get the system date.

Date
date_system(void);

Return

The current date.


#date_pack ()

Pack a date.

Date
date_pack(const int16_t year,
          const uint8_t month,
          const uint8_t mday,
          const uint8_t hour,
          const uint8_t minute,
          const uint8_t second);
year

Year.

month

Month number (1,12).

mday

Day of the month (1,31).

hour

Hour (0,23).

minute

Minute (0,59).

second

Second (0,59).

Return

The packaged date.


#date_add_seconds ()

Calculate the date resulting from adding an amount of seconds to another date.

Date
date_add_seconds(const Date *date,
                 int32_t seconds);
date

The base date.

seconds

The number of seconds. If it is positive we will obtain a future date. If negative, a past date.

Return

The result date.


#date_add_minutes ()

Calculate the date resulting from adding an amount of minutes to another date.

Date
date_add_minutes(const Date *date,
                 int32_t minutes);
date

The base date.

minutes

The number of minutes. If it is positive we will obtain a future date. If negative, a past date.

Return

The result date.


#date_add_hours ()

Calculate the date resulting from adding an amount of hours to another date.

Date
date_add_hours(const Date *date,
               int32_t hours);
date

The base date.

hours

The number of hours. If it is positive we will obtain a future date. If negative, a past date.

Return

The result date.


#date_add_days ()

Calculate the date resulting from adding an amount of days to another date.

Date
date_add_days(const Date *date,
              int32_t days);
date

The base date.

days

The number of days. If it is positive we will obtain a future date. If negative, a past date.

Return

The result date.


#date_year ()

Gets the current year.

int16_t
date_year(void);

Return

The current year.


#date_cmp ()

Compare two dates. The most recent date is considered greater.

int
date_cmp(const Date *date1,
         const Date *date2);
date1

First date to compare.

date2

Second date to compare.

Return

Comparison result.


#date_ellapsed_seconds ()

Calculates the number of seconds elapsed between two dates.

int64_t
date_ellapsed_seconds(const Date *from,
                      const Date *to);
from

Start date.

to

Final date.

Return

Number of seconds. It can be negative, if from is after to.


#date_between ()

Check if a date is within a range.

bool_t
date_between(const Date *date,
             const Date *from,
             const Date *to);
date

Date to check.

from

Start date.

to

Final date.

Return

TRUE if date is between from and to.


#date_is_null ()

Checks if a date is null.

bool_t
date_is_null(const Date *date);
date

Date to check.

Return

TRUE if date is null.


#date_is_valid ()

Checks if a date is valid.

bool_t
date_is_valid(const Date *date);
date

Date to check.

Return

TRUE if date is valid.

Remarks

Any year representable in int16_t (from -32768 to 32767) is accepted, following the proleptic Gregorian calendar with astronomical year numbering (year 0 is 1 BC).


#date_weekday ()

Calculates the day of the week of a date.

week_day_t
date_weekday(const Date *date);
date

Date.

Return

Weekday.


#date_is_leap ()

Checks if a year is a leap year, according to the Gregorian calendar.

bool_t
date_is_leap(const int16_t year);
year

Year.

Return

TRUE if year is a leap year.


#date_month_days ()

Gets the number of days in a month.

uint8_t
date_month_days(const int16_t year,
                const month_t month);
year

Year. Required to know the days of February.

month

Month.

Return

Number of days (28, 29, 30 or 31).


#date_to_days ()

Converts a date into the number of days elapsed since January 1, 1970.

int32_t
date_to_days(const Date *date);
date

Date. Hour, minutes and seconds are ignored.

Return

Number of days. January 1, 1970 is day 0, previous days are negative and later days are positive.

Remarks

It uses the proleptic Gregorian calendar with astronomical year numbering, so the result depends neither on the time zone nor on the operating system. This is the representation used by DateView when bound to int32_t fields (Control-specific behavior).


#date_from_days ()

Converts a number of days elapsed since January 1, 1970 into a date.

Date
date_from_days(const int32_t days);
days

Number of days. January 1, 1970 is day 0.

Return

The date, at 00:00:00 and with the weekday calculated.

Remarks

Values outside the Date range (years from -32768 to 32767) are clamped to the nearest limit.


#date_format ()

Returns a string with a formatted date.

const String*
date_format(const Date *date,
            const char_t *format);
date

Date.

format

The specified format, based on strftime().

Return

String with date.

Remarks

See Date conversion.

❮ Back
Next ❯