From cbf2a43f07e97e7bfbb2854a25a56935f3efca7b Mon Sep 17 00:00:00 2001 From: Kevin Day Date: Mon, 7 Dec 2020 21:57:24 -0600 Subject: [PATCH] Feature: add date and time related types. --- level_0/f_type/c/type.h | 71 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 71 insertions(+) diff --git a/level_0/f_type/c/type.h b/level_0/f_type/c/type.h index 482d209..b77aa7e 100644 --- a/level_0/f_type/c/type.h +++ b/level_0/f_type/c/type.h @@ -303,6 +303,77 @@ extern "C" { mode.unknown = value_unknown; #endif // _di_f_directory_mode_ +/** + * A non-kernel dependent version of "struct timespec". + * + * seconds: The total number of seconds. + * nanoseconds: The total number of nanoseconds. + */ +#ifndef _di_f_time_spec_t_ + typedef struct { + uint64_t seconds; + uint64_t nanoseconds; + } f_time_spec_t; + + #define f_time_spec_t_initialize { 0, 0 } + + #define f_macro_time_spec_t_clear(spec) \ + spec.seconds = 0; \ + spec.nanoseconds = 0; +#endif // _di_f_time_spec_t_ + +/** + * Hold a unit of Time. + * + * This utilizes the unit of measurement called a "Time", represented with uppercase "T". + * For comparison, a unit of Time is equivalent to a nanosecond, or 10^-9 seconds. + * + * A unit of Time is intended to represent some unit of Time such that a single 64-bit integer may hold all units of Time for a single calendar year. + * This unit of Time does not and must not include Years (unlike Unixtime). + * + * A MegaTime (MT) is therefore equivalent to a millisecond such that a millisecond is 10^-3 seconds. + * + * To convert from Time to Unixtime, one must have a year (which could be assumed to be the current year) and then calculate all of those calendar od + * + * A unit of Time by default is assumed to be in UTC. + * 1 (Earth) year ~= 31536000000000000 Time or 31536000 GT (GigaTime). + * 1 (Earth) day = 86400000000000 Time or 86400 GT (GigaTime). + * 1 (Earth) hour = 3600000000000 Time or 3600 GT (GigaTime). + * 1 (Earth) minute = 60000000000 Time or 60 GT (GigaTime). + * 1 (Earth) second = 1000000000 Time or 1 GT (GigaTime). + * + * Consequentially, 1 day in units of Time is easily represented as 86.4 TT (TeraTime). + */ +#ifndef _di_f_time_t_ + typedef uint64_t f_time_t; +#endif // _di_f_time_t_ + +/** + * Hold a unit of Time along with a year to represent a date. + * + * This implementation of a date using the unit of Time is limited on the size of the year. + * The value for year is expected to be a signed number. + * For anything that needs a larger (or smaller) year, create a new type or use the "year string format" of Time. + * + * In "year string format" of Time, a Year may be prepended to the Time followed by a single colon ':' to associate a year with the Time. + * This Year has no minimum or maximum but may not have decimals. + * + * For example, "2020:86400000000000" would represent: January 02, 2020 0:00 UTC. + * For example, "2020:86.4 TT" would represent: January 02, 2020 0:00 UTC. + */ +#ifndef _di_f_date_t_ + typedef struct { + f_number_signed_t year; + f_time_t time; + } f_date_t; + + #define f_date_t_initialize { 0, 0 } + + #define f_macro_date_t_clear(date) \ + date.year = 0; \ + date.time = 0; +#endif // _di_f_date_t_ + #ifdef __cplusplus } // extern "C" #endif -- 1.8.3.1