object: add a type for storing, parsing, and stringifying date/time values

This commit is contained in:
2025-09-22 10:44:56 +01:00
parent 2fcadf7f39
commit 16b68b6fba
4 changed files with 556 additions and 0 deletions

View File

@@ -0,0 +1,49 @@
#ifndef BLUELIB_DATETIME_H_
#define BLUELIB_DATETIME_H_
#include <blue/core/status.h>
#include <blue/object/object.h>
#include <blue/object/type.h>
#include <ctype.h>
struct b_string;
#define B_DATETIME(p) ((b_datetime *)(p))
typedef struct b_datetime b_datetime;
typedef enum b_datetime_format {
B_DATETIME_FORMAT_RFC3339 = 1,
} b_datetime_format;
BLUE_API b_datetime *b_datetime_create(void);
BLUE_API b_datetime *b_datetime_parse(b_datetime_format format, const char *s);
BLUE_API void b_datetime_to_string(
const b_datetime *dt, b_datetime_format format, struct b_string *dest);
static inline b_datetime *b_datetime_retain(b_datetime *dt)
{
return B_DATETIME(b_retain(B_OBJECT(dt)));
}
static inline void b_datetime_release(b_datetime *dt)
{
b_release(B_OBJECT(dt));
}
BLUE_API bool b_datetime_is_localtime(const b_datetime *dt);
BLUE_API bool b_datetime_has_date(const b_datetime *dt);
BLUE_API bool b_datetime_has_time(const b_datetime *dt);
BLUE_API long b_datetime_year(const b_datetime *dt);
BLUE_API long b_datetime_month(const b_datetime *dt);
BLUE_API long b_datetime_day(const b_datetime *dt);
BLUE_API long b_datetime_hour(const b_datetime *dt);
BLUE_API long b_datetime_minute(const b_datetime *dt);
BLUE_API long b_datetime_second(const b_datetime *dt);
BLUE_API long b_datetime_subsecond(const b_datetime *dt);
BLUE_API bool b_datetime_zone_offset_is_negative(const b_datetime *dt);
BLUE_API long b_datetime_zone_offset_hour(const b_datetime *dt);
BLUE_API long b_datetime_zone_offset_minute(const b_datetime *dt);
#endif

View File

@@ -30,6 +30,7 @@ typedef enum b_fundamental_type_id {
B_OBJECT_TYPE_PATH,
B_OBJECT_TYPE_FILE,
B_OBJECT_TYPE_DIRECTORY,
B_OBJECT_TYPE_DATETIME,
} b_fundamental_type_id;
typedef enum b_object_type_flags {