From 8849f6ce8cc8a14e55beddc2bc8eccef53e84511 Mon Sep 17 00:00:00 2001 From: Allen Webster Date: Wed, 11 Mar 2020 03:33:54 -0700 Subject: [PATCH] Date_Time type; formatting function for Date_Time; System API for getting Date_Time UTC, and converting UTC to local time; Implementation in Windows --- 4ed_system_api.cpp | 14 ++ custom/4coder_base_types.cpp | 42 +++- custom/4coder_base_types.h | 148 ++++++++++++ custom/4coder_default_hooks.cpp | 8 + custom/4coder_stringf.cpp | 254 +++++++++++++++++++- custom/generated/system_api.cpp | 6 + custom/generated/system_api.h | 15 ++ custom/generated/system_api_constructor.cpp | 12 + custom/generated/system_api_master_list.h | 3 + foo.h | 6 + platform_win32/win32_4ed.cpp | 65 ++++- 11 files changed, 560 insertions(+), 13 deletions(-) create mode 100644 foo.h diff --git a/4ed_system_api.cpp b/4ed_system_api.cpp index e55ef3bc..67be0759 100644 --- a/4ed_system_api.cpp +++ b/4ed_system_api.cpp @@ -92,6 +92,20 @@ define_api(Arena *arena){ api_call(arena, api, "now_time", "u64"); } + { + api_call(arena, api, "now_date_time_universal", "Date_Time"); + } + + { + API_Call *call = api_call(arena, api, "local_date_time_from_universal", "Date_Time"); + api_param(arena, call, "Date_Time*", "date_time"); + } + + { + API_Call *call = api_call(arena, api, "universal_date_time_from_local", "Date_Time"); + api_param(arena, call, "Date_Time*", "date_time"); + } + { api_call(arena, api, "wake_up_timer_create", "Plat_Handle"); } diff --git a/custom/4coder_base_types.cpp b/custom/4coder_base_types.cpp index 06d03341..4235eb5b 100644 --- a/custom/4coder_base_types.cpp +++ b/custom/4coder_base_types.cpp @@ -2968,9 +2968,7 @@ SCany(String_Const_u32 str){ } #define string_litexpr(s) SCchar((s), sizeof(s) - 1) -#define string_litinit(s) {(s), sizeof(s) - 1} #define string_u8_litexpr(s) SCu8((u8*)(s), (u64)(sizeof(s) - 1)) -#define string_u8_litinit(s) {(u8*)(s), sizeof(s) - 1} #define string_u16_litexpr(s) SCu16((u16*)(s), (u64)(sizeof(s)/2 - 1)) #define string_expand(s) (i32)(s).size, (char*)(s).str @@ -7230,6 +7228,46 @@ data_decode_from_base64(Arena *arena, u8 *str, u64 size){ return(data); } +//////////////////////////////// + +function u64 +time_stamp_from_date_time(Date_Time *date_time){ + u64 result = 0; + result += date_time->year; + result *= 12; + result += date_time->mon; + result *= 30; + result += date_time->day; + result *= 24; + result += date_time->hour; + result *= 60; + result += date_time->min; + result *= 61; + result += date_time->sec; + result *= 1000; + result += date_time->msec; + return(result); +} + +function Date_Time +date_time_from_time_stamp(u64 time_stamp){ + Date_Time result = {}; + result.msec = time_stamp%1000; + time_stamp /= 1000; + result.sec = time_stamp%61; + time_stamp /= 61; + result.min = time_stamp%60; + time_stamp /= 60; + result.hour = time_stamp%24; + time_stamp /= 24; + result.day = time_stamp%30; + time_stamp /= 30; + result.mon = time_stamp%12; + time_stamp /= 12; + result.year = (u32)time_stamp; + return(result); +} + #endif // BOTTOM diff --git a/custom/4coder_base_types.h b/custom/4coder_base_types.h index f8e550c8..f1a10a4b 100644 --- a/custom/4coder_base_types.h +++ b/custom/4coder_base_types.h @@ -933,6 +933,9 @@ struct String_Const_Any{ }; }; +#define string_litinit(s) {(s), sizeof(s) - 1} +#define string_u8_litinit(s) {(u8*)(s), sizeof(s) - 1} + struct Node_String_Const_char{ Node_String_Const_char *next; String_Const_char string; @@ -1103,6 +1106,151 @@ enum{ //////////////////////////////// +struct Date_Time{ + u32 year; // Real year, no adjustment + u8 mon; // [0,11] + u8 day; // [0,30] + u8 hour; // [0,23] + u8 min; // [0,59] + u8 sec; // [0,60] + u16 msec; // [0,999] +}; + +global String_Const_u8 month_full_name[] = { + string_u8_litinit("January"), + string_u8_litinit("February"), + string_u8_litinit("March"), + string_u8_litinit("April"), + string_u8_litinit("May"), + string_u8_litinit("June"), + string_u8_litinit("July"), + string_u8_litinit("August"), + string_u8_litinit("September"), + string_u8_litinit("October"), + string_u8_litinit("November"), + string_u8_litinit("December"), +}; + +global String_Const_u8 month_abrev_name[] = { + string_u8_litinit("Jan"), + string_u8_litinit("Feb"), + string_u8_litinit("Mar"), + string_u8_litinit("Apr"), + string_u8_litinit("May"), + string_u8_litinit("Jun"), + string_u8_litinit("Jul"), + string_u8_litinit("Aug"), + string_u8_litinit("Sep"), + string_u8_litinit("Oct"), + string_u8_litinit("Nov"), + string_u8_litinit("Dec"), +}; + +global String_Const_u8 ordinal_numeric_name[] = { + string_u8_litinit("1st"), + string_u8_litinit("2nd"), + string_u8_litinit("3rd"), + string_u8_litinit("4th"), + string_u8_litinit("5th"), + string_u8_litinit("6th"), + string_u8_litinit("7th"), + string_u8_litinit("8th"), + string_u8_litinit("9th"), + string_u8_litinit("10th"), + string_u8_litinit("11th"), + string_u8_litinit("12th"), + string_u8_litinit("13th"), + string_u8_litinit("14th"), + string_u8_litinit("15th"), + string_u8_litinit("16th"), + string_u8_litinit("17th"), + string_u8_litinit("18th"), + string_u8_litinit("19th"), + string_u8_litinit("20th"), + string_u8_litinit("21st"), + string_u8_litinit("22nd"), + string_u8_litinit("23rd"), + string_u8_litinit("24th"), + string_u8_litinit("25th"), + string_u8_litinit("26th"), + string_u8_litinit("27th"), + string_u8_litinit("28th"), + string_u8_litinit("29th"), + string_u8_litinit("30th"), + string_u8_litinit("31st"), + string_u8_litinit("32nd"), + string_u8_litinit("33rd"), + string_u8_litinit("34th"), + string_u8_litinit("35th"), + string_u8_litinit("36th"), + string_u8_litinit("37th"), + string_u8_litinit("38th"), + string_u8_litinit("39th"), + string_u8_litinit("40th"), + string_u8_litinit("41st"), + string_u8_litinit("42nd"), + string_u8_litinit("43rd"), + string_u8_litinit("44th"), + string_u8_litinit("45th"), + string_u8_litinit("46th"), + string_u8_litinit("47th"), + string_u8_litinit("48th"), + string_u8_litinit("49th"), + string_u8_litinit("50th"), + string_u8_litinit("51st"), + string_u8_litinit("52nd"), + string_u8_litinit("53rd"), + string_u8_litinit("54th"), + string_u8_litinit("55th"), + string_u8_litinit("56th"), + string_u8_litinit("57th"), + string_u8_litinit("58th"), + string_u8_litinit("59th"), + string_u8_litinit("60th"), + string_u8_litinit("61st"), + string_u8_litinit("62nd"), + string_u8_litinit("63rd"), + string_u8_litinit("64th"), + string_u8_litinit("65th"), + string_u8_litinit("66th"), + string_u8_litinit("67th"), + string_u8_litinit("68th"), + string_u8_litinit("69th"), + string_u8_litinit("70th"), + string_u8_litinit("71st"), + string_u8_litinit("72nd"), + string_u8_litinit("73rd"), + string_u8_litinit("74th"), + string_u8_litinit("75th"), + string_u8_litinit("76th"), + string_u8_litinit("77th"), + string_u8_litinit("78th"), + string_u8_litinit("79th"), + string_u8_litinit("80th"), + string_u8_litinit("81st"), + string_u8_litinit("82nd"), + string_u8_litinit("83rd"), + string_u8_litinit("84th"), + string_u8_litinit("85th"), + string_u8_litinit("86th"), + string_u8_litinit("87th"), + string_u8_litinit("88th"), + string_u8_litinit("89th"), + string_u8_litinit("90th"), + string_u8_litinit("91st"), + string_u8_litinit("92nd"), + string_u8_litinit("93rd"), + string_u8_litinit("94th"), + string_u8_litinit("95th"), + string_u8_litinit("96th"), + string_u8_litinit("97th"), + string_u8_litinit("98th"), + string_u8_litinit("99th"), + string_u8_litinit("100th"), +}; + +//////////////////////////////// + typedef void *Base_Allocator_Reserve_Signature(void *user_data, u64 size, u64 *size_out, String_Const_u8 location); typedef void Base_Allocator_Commit_Signature(void *user_data, void *ptr, u64 size); typedef void Base_Allocator_Uncommit_Signature(void *user_data, void *ptr, u64 size); diff --git a/custom/4coder_default_hooks.cpp b/custom/4coder_default_hooks.cpp index 4756c8e2..05864d97 100644 --- a/custom/4coder_default_hooks.cpp +++ b/custom/4coder_default_hooks.cpp @@ -864,7 +864,15 @@ BUFFER_HOOK_SIG(default_new_file){ } String_Const_u8 guard = string_list_flatten(scratch, guard_list); + Date_Time date_time = system_now_date_time_universal(); + date_time = system_local_date_time_from_universal(&date_time); + String_Const_u8 date_string = date_time_format(scratch, "month day yyyy h:mimi ampm", &date_time); + Buffer_Insertion insert = begin_buffer_insertion_at_buffered(app, buffer_id, 0, scratch, KB(16)); + insertf(&insert, + "/* date = %.*s */\n" + "\n", + string_expand(date_string)); insertf(&insert, "#ifndef %.*s\n" "#define %.*s\n" diff --git a/custom/4coder_stringf.cpp b/custom/4coder_stringf.cpp index e593fa8c..1b699be1 100644 --- a/custom/4coder_stringf.cpp +++ b/custom/4coder_stringf.cpp @@ -10,7 +10,7 @@ #include #include -static String_Const_u8 +function String_Const_u8 push_stringfv(Arena *arena, char *format, va_list args){ va_list args2; va_copy(args2, args); @@ -21,7 +21,7 @@ push_stringfv(Arena *arena, char *format, va_list args){ result.str[result.size] = 0; return(result); } -static String_Const_u8 +function String_Const_u8 push_stringf(Arena *arena, char *format, ...){ va_list args; va_start(args, format); @@ -29,11 +29,11 @@ push_stringf(Arena *arena, char *format, ...){ va_end(args); return(result); } -static String_Const_u8 +function String_Const_u8 push_u8_stringfv(Arena *arena, char *format, va_list args){ return(push_stringfv(arena, format, args)); } -static String_Const_u8 +function String_Const_u8 push_u8_stringf(Arena *arena, char *format, ...){ va_list args; va_start(args, format); @@ -42,7 +42,7 @@ push_u8_stringf(Arena *arena, char *format, ...){ return(result); } -static void +function void string_list_pushfv(Arena *arena, List_String_Const_char *list, char *format, va_list args){ String_Const_u8 string = push_stringfv(arena, format, args); if (arena->alignment < sizeof(u64)){ @@ -50,14 +50,14 @@ string_list_pushfv(Arena *arena, List_String_Const_char *list, char *format, va_ } string_list_push(arena, list, SCchar(string)); } -static void +function void string_list_pushf(Arena *arena, List_String_Const_char *list, char *format, ...){ va_list args; va_start(args, format); string_list_pushfv(arena, list, format, args); va_end(args); } -static void +function void string_list_pushfv(Arena *arena, List_String_Const_u8 *list, char *format, va_list args){ String_Const_u8 string = push_u8_stringfv(arena, format, args); if (arena->alignment < sizeof(u64)){ @@ -65,7 +65,7 @@ string_list_pushfv(Arena *arena, List_String_Const_u8 *list, char *format, va_li } string_list_push(arena, list, string); } -static void +function void string_list_pushf(Arena *arena, List_String_Const_u8 *list, char *format, ...){ va_list args; va_start(args, format); @@ -73,6 +73,244 @@ string_list_pushf(Arena *arena, List_String_Const_u8 *list, char *format, ...){ va_end(args); } +//////////////////////////////// + +// yyyy +function void +push_year_full(Arena *arena, List_String_Const_u8 *list, u32 year){ + string_list_pushf(arena, list, "%u", year); +} +// yy +function void +push_year_abrev(Arena *arena, List_String_Const_u8 *list, u32 year){ + string_list_pushf(arena, list, "%u", year % 100); +} + +// m +function void +push_month_num(Arena *arena, List_String_Const_u8 *list, u8 mon){ + string_list_pushf(arena, list, "%u", mon + 1); +} +// mm +function void +push_month_num_zeros(Arena *arena, List_String_Const_u8 *list, u8 mon){ + string_list_pushf(arena, list, "%02u", mon + 1); +} +// month +function void +push_month_name(Arena *arena, List_String_Const_u8 *list, u8 mon){ + string_list_push(arena, list, month_full_name[mon%12]); +} +// mon +function void +push_month_abrev(Arena *arena, List_String_Const_u8 *list, u8 mon){ + string_list_push(arena, list, month_abrev_name[mon%12]); +} + +// d +function void +push_day_num(Arena *arena, List_String_Const_u8 *list, u8 day){ + string_list_pushf(arena, list, "%u", day + 1); +} +// dd +function void +push_day_num_zeroes(Arena *arena, List_String_Const_u8 *list, u8 day){ + string_list_pushf(arena, list, "%02u", day + 1); +} +// day +function void +push_day_ord(Arena *arena, List_String_Const_u8 *list, u8 day){ + string_list_push(arena, list, ordinal_numeric_name[day%100]); +} + +// h24 +function void +push_hour_24(Arena *arena, List_String_Const_u8 *list, u8 hour){ + string_list_pushf(arena, list, "%u", hour); +} +// hh24 +function void +push_hour_24_zeroes(Arena *arena, List_String_Const_u8 *list, u8 hour){ + string_list_pushf(arena, list, "%02u", hour); +} +// h +function void +push_hour_12(Arena *arena, List_String_Const_u8 *list, u8 hour){ + string_list_pushf(arena, list, "%u", hour%12); +} +// hh +function void +push_hour_12_zeroes(Arena *arena, List_String_Const_u8 *list, u8 hour){ + string_list_pushf(arena, list, "%02u", hour%12); +} +// ampm +function void +push_hour_am_pm(Arena *arena, List_String_Const_u8 *list, u8 hour){ + if (hour >= 12){ + string_list_push(arena, list, string_u8_litexpr("pm")); + } + else{ + string_list_push(arena, list, string_u8_litexpr("am")); + } +} + +// mi +function void +push_minute(Arena *arena, List_String_Const_u8 *list, u8 min){ + string_list_pushf(arena, list, "%u", min); +} +// mimi +function void +push_minute_zeroes(Arena *arena, List_String_Const_u8 *list, u8 min){ + string_list_pushf(arena, list, "%02u", min); +} + +// s +function void +push_second(Arena *arena, List_String_Const_u8 *list, u8 sec){ + string_list_pushf(arena, list, "%u", sec); +} +// ss +function void +push_second_zeroes(Arena *arena, List_String_Const_u8 *list, u8 sec){ + string_list_pushf(arena, list, "%02u", sec); +} + +// ms +function void +push_millisecond_zeroes(Arena *arena, List_String_Const_u8 *list, u16 msec){ + string_list_pushf(arena, list, "%03u", msec); +} + +function void +date_time_format(Arena *arena, List_String_Const_u8 *list, String_Const_u8 format, Date_Time *date_time){ + u8 *ptr = format.str; + u8 *end = format.str + format.size; + for (;ptr < end;){ + if (character_is_alpha_numeric(*ptr)){ + u8 *start = ptr; + for (;ptr < end; ptr += 1){ + if (!character_is_alpha_numeric(*ptr)){ + break; + } + } + + String_Const_u8 field = SCu8(start, ptr); + for (; field.size > 0;){ + if (string_match(string_prefix(field, 5), string_u8_litexpr("month"))){ + field = string_skip(field, 5); + push_month_name(arena, list, date_time->mon); + } + + else if (string_match(string_prefix(field, 4), string_u8_litexpr("yyyy"))){ + field = string_skip(field, 4); + push_year_full(arena, list, date_time->year); + } + else if (string_match(string_prefix(field, 4), string_u8_litexpr("hh24"))){ + field = string_skip(field, 4); + push_hour_24_zeroes(arena, list, date_time->hour); + } + else if (string_match(string_prefix(field, 4), string_u8_litexpr("ampm"))){ + field = string_skip(field, 4); + push_hour_am_pm(arena, list, date_time->hour); + } + else if (string_match(string_prefix(field, 4), string_u8_litexpr("mimi"))){ + field = string_skip(field, 4); + push_minute_zeroes(arena, list, date_time->min); + } + + else if (string_match(string_prefix(field, 3), string_u8_litexpr("mon"))){ + field = string_skip(field, 3); + push_month_abrev(arena, list, date_time->mon); + } + else if (string_match(string_prefix(field, 3), string_u8_litexpr("day"))){ + field = string_skip(field, 3); + push_day_ord(arena, list, date_time->day); + } + else if (string_match(string_prefix(field, 3), string_u8_litexpr("h24"))){ + field = string_skip(field, 3); + push_hour_24(arena, list, date_time->hour); + } + + else if (string_match(string_prefix(field, 2), string_u8_litexpr("yy"))){ + field = string_skip(field, 2); + push_year_abrev(arena, list, date_time->year); + } + else if (string_match(string_prefix(field, 2), string_u8_litexpr("mm"))){ + field = string_skip(field, 2); + push_month_num_zeros(arena, list, date_time->mon); + } + else if (string_match(string_prefix(field, 2), string_u8_litexpr("dd"))){ + field = string_skip(field, 2); + push_day_num_zeroes(arena, list, date_time->day); + } + else if (string_match(string_prefix(field, 2), string_u8_litexpr("hh"))){ + field = string_skip(field, 2); + push_hour_12_zeroes(arena, list, date_time->hour); + } + else if (string_match(string_prefix(field, 2), string_u8_litexpr("mi"))){ + field = string_skip(field, 2); + push_minute(arena, list, date_time->min); + } + else if (string_match(string_prefix(field, 2), string_u8_litexpr("ss"))){ + field = string_skip(field, 2); + push_second_zeroes(arena, list, date_time->sec); + } + else if (string_match(string_prefix(field, 2), string_u8_litexpr("ms"))){ + field = string_skip(field, 2); + push_millisecond_zeroes(arena, list, date_time->msec); + } + + else if (string_match(string_prefix(field, 1), string_u8_litexpr("m"))){ + field = string_skip(field, 1); + push_month_num(arena, list, date_time->mon); + } + else if (string_match(string_prefix(field, 1), string_u8_litexpr("d"))){ + field = string_skip(field, 1); + push_day_num(arena, list, date_time->day); + } + else if (string_match(string_prefix(field, 1), string_u8_litexpr("h"))){ + field = string_skip(field, 1); + push_hour_12(arena, list, date_time->hour); + } + else if (string_match(string_prefix(field, 1), string_u8_litexpr("s"))){ + field = string_skip(field, 1); + push_second(arena, list, date_time->sec); + } + + else{ + string_list_push(arena, list, SCu8(start, ptr)); + break; + } + } + } + else{ + u8 *start = ptr; + for (;ptr < end; ptr += 1){ + if (character_is_alpha_numeric(*ptr)){ + break; + } + } + string_list_push(arena, list, SCu8(start, ptr)); + } + } +} +function void +date_time_format(Arena *arena, List_String_Const_u8 *list, char *format, Date_Time *date_time){ + date_time_format(arena, list, SCu8(format), date_time); +} + +function String_Const_u8 +date_time_format(Arena *arena, String_Const_u8 format, Date_Time *date_time){ + List_String_Const_u8 list = {}; + date_time_format(arena, &list, format, date_time); + return(string_list_flatten(arena, list)); +} +function String_Const_u8 +date_time_format(Arena *arena, char *format, Date_Time *date_time){ + return(date_time_format(arena, SCu8(format), date_time)); +} + #endif // BOTTOM diff --git a/custom/generated/system_api.cpp b/custom/generated/system_api.cpp index 990f8768..49339afc 100644 --- a/custom/generated/system_api.cpp +++ b/custom/generated/system_api.cpp @@ -13,6 +13,9 @@ vtable->load_library = system_load_library; vtable->release_library = system_release_library; vtable->get_proc = system_get_proc; vtable->now_time = system_now_time; +vtable->now_date_time_universal = system_now_date_time_universal; +vtable->local_date_time_from_universal = system_local_date_time_from_universal; +vtable->universal_date_time_from_local = system_universal_date_time_from_local; vtable->wake_up_timer_create = system_wake_up_timer_create; vtable->wake_up_timer_release = system_wake_up_timer_release; vtable->wake_up_timer_set = system_wake_up_timer_set; @@ -67,6 +70,9 @@ system_load_library = vtable->load_library; system_release_library = vtable->release_library; system_get_proc = vtable->get_proc; system_now_time = vtable->now_time; +system_now_date_time_universal = vtable->now_date_time_universal; +system_local_date_time_from_universal = vtable->local_date_time_from_universal; +system_universal_date_time_from_local = vtable->universal_date_time_from_local; system_wake_up_timer_create = vtable->wake_up_timer_create; system_wake_up_timer_release = vtable->wake_up_timer_release; system_wake_up_timer_set = vtable->wake_up_timer_set; diff --git a/custom/generated/system_api.h b/custom/generated/system_api.h index c01eabd1..69f21d5b 100644 --- a/custom/generated/system_api.h +++ b/custom/generated/system_api.h @@ -11,6 +11,9 @@ #define system_release_library_sig() b32 system_release_library(System_Library handle) #define system_get_proc_sig() Void_Func* system_get_proc(System_Library handle, char* proc_name) #define system_now_time_sig() u64 system_now_time(void) +#define system_now_date_time_universal_sig() Date_Time system_now_date_time_universal(void) +#define system_local_date_time_from_universal_sig() Date_Time system_local_date_time_from_universal(Date_Time* date_time) +#define system_universal_date_time_from_local_sig() Date_Time system_universal_date_time_from_local(Date_Time* date_time) #define system_wake_up_timer_create_sig() Plat_Handle system_wake_up_timer_create(void) #define system_wake_up_timer_release_sig() void system_wake_up_timer_release(Plat_Handle handle) #define system_wake_up_timer_set_sig() void system_wake_up_timer_set(Plat_Handle handle, u32 time_milliseconds) @@ -61,6 +64,9 @@ typedef b32 system_load_library_type(Arena* scratch, String_Const_u8 file_name, typedef b32 system_release_library_type(System_Library handle); typedef Void_Func* system_get_proc_type(System_Library handle, char* proc_name); typedef u64 system_now_time_type(void); +typedef Date_Time system_now_date_time_universal_type(void); +typedef Date_Time system_local_date_time_from_universal_type(Date_Time* date_time); +typedef Date_Time system_universal_date_time_from_local_type(Date_Time* date_time); typedef Plat_Handle system_wake_up_timer_create_type(void); typedef void system_wake_up_timer_release_type(Plat_Handle handle); typedef void system_wake_up_timer_set_type(Plat_Handle handle, u32 time_milliseconds); @@ -112,6 +118,9 @@ system_load_library_type *load_library; system_release_library_type *release_library; system_get_proc_type *get_proc; system_now_time_type *now_time; +system_now_date_time_universal_type *now_date_time_universal; +system_local_date_time_from_universal_type *local_date_time_from_universal; +system_universal_date_time_from_local_type *universal_date_time_from_local; system_wake_up_timer_create_type *wake_up_timer_create; system_wake_up_timer_release_type *wake_up_timer_release; system_wake_up_timer_set_type *wake_up_timer_set; @@ -164,6 +173,9 @@ internal b32 system_load_library(Arena* scratch, String_Const_u8 file_name, Syst internal b32 system_release_library(System_Library handle); internal Void_Func* system_get_proc(System_Library handle, char* proc_name); internal u64 system_now_time(void); +internal Date_Time system_now_date_time_universal(void); +internal Date_Time system_local_date_time_from_universal(Date_Time* date_time); +internal Date_Time system_universal_date_time_from_local(Date_Time* date_time); internal Plat_Handle system_wake_up_timer_create(void); internal void system_wake_up_timer_release(Plat_Handle handle); internal void system_wake_up_timer_set(Plat_Handle handle, u32 time_milliseconds); @@ -216,6 +228,9 @@ global system_load_library_type *system_load_library = 0; global system_release_library_type *system_release_library = 0; global system_get_proc_type *system_get_proc = 0; global system_now_time_type *system_now_time = 0; +global system_now_date_time_universal_type *system_now_date_time_universal = 0; +global system_local_date_time_from_universal_type *system_local_date_time_from_universal = 0; +global system_universal_date_time_from_local_type *system_universal_date_time_from_local = 0; global system_wake_up_timer_create_type *system_wake_up_timer_create = 0; global system_wake_up_timer_release_type *system_wake_up_timer_release = 0; global system_wake_up_timer_set_type *system_wake_up_timer_set = 0; diff --git a/custom/generated/system_api_constructor.cpp b/custom/generated/system_api_constructor.cpp index 9f6c558f..d9e1b3a2 100644 --- a/custom/generated/system_api_constructor.cpp +++ b/custom/generated/system_api_constructor.cpp @@ -67,6 +67,18 @@ API_Call *call = api_call_with_location(arena, result, string_u8_litexpr("now_ti (void)call; } { +API_Call *call = api_call_with_location(arena, result, string_u8_litexpr("now_date_time_universal"), string_u8_litexpr("Date_Time"), string_u8_litexpr("")); +(void)call; +} +{ +API_Call *call = api_call_with_location(arena, result, string_u8_litexpr("local_date_time_from_universal"), string_u8_litexpr("Date_Time"), string_u8_litexpr("")); +api_param(arena, call, "Date_Time*", "date_time"); +} +{ +API_Call *call = api_call_with_location(arena, result, string_u8_litexpr("universal_date_time_from_local"), string_u8_litexpr("Date_Time"), string_u8_litexpr("")); +api_param(arena, call, "Date_Time*", "date_time"); +} +{ API_Call *call = api_call_with_location(arena, result, string_u8_litexpr("wake_up_timer_create"), string_u8_litexpr("Plat_Handle"), string_u8_litexpr("")); (void)call; } diff --git a/custom/generated/system_api_master_list.h b/custom/generated/system_api_master_list.h index 997234f4..8aa0dffa 100644 --- a/custom/generated/system_api_master_list.h +++ b/custom/generated/system_api_master_list.h @@ -11,6 +11,9 @@ api(system) function b32 load_library(Arena* scratch, String_Const_u8 file_name, api(system) function b32 release_library(System_Library handle); api(system) function Void_Func* get_proc(System_Library handle, char* proc_name); api(system) function u64 now_time(void); +api(system) function Date_Time now_date_time_universal(void); +api(system) function Date_Time local_date_time_from_universal(Date_Time* date_time); +api(system) function Date_Time universal_date_time_from_local(Date_Time* date_time); api(system) function Plat_Handle wake_up_timer_create(void); api(system) function void wake_up_timer_release(Plat_Handle handle); api(system) function void wake_up_timer_set(Plat_Handle handle, u32 time_milliseconds); diff --git a/foo.h b/foo.h new file mode 100644 index 00000000..bcc82080 --- /dev/null +++ b/foo.h @@ -0,0 +1,6 @@ +/* date = March 11th 2020 3:30 am */ + +#ifndef FOO_H +#define FOO_H + +#endif //FOO_H diff --git a/platform_win32/win32_4ed.cpp b/platform_win32/win32_4ed.cpp index 34381474..24441d45 100644 --- a/platform_win32/win32_4ed.cpp +++ b/platform_win32/win32_4ed.cpp @@ -838,6 +838,65 @@ system_now_time_sig(){ return(result); } +internal void +date_time_from_win32_system_time(Date_Time *out, SYSTEMTIME *in){ + out->year = in->wYear; + out->mon = (u8)(in->wMonth - 1); + out->day = (u8)(in->wDay - 1); + out->hour = (u8)(in->wHour); + out->min = (u8)(in->wMinute); + out->sec = (u8)(in->wSecond); + out->msec = in->wMilliseconds; +} + +internal void +win32_system_time_from_date_time(SYSTEMTIME *out, Date_Time *in){ + out->wYear = (WORD)(in->year); + out->wMonth = in->mon + 1; + out->wDay = in->day + 1; + out->wHour = in->hour; + out->wMinute = in->min; + out->wSecond = in->sec; + out->wMilliseconds = in->msec; +} + +internal +system_now_date_time_universal_sig(){ + SYSTEMTIME systime = {}; + GetSystemTime(&systime); + Date_Time result = {}; + date_time_from_win32_system_time(&result, &systime); + return(result); +} + +internal +system_local_date_time_from_universal_sig(){ + SYSTEMTIME systime = {}; + win32_system_time_from_date_time(&systime, date_time); + FILETIME ftime = {}; + SystemTimeToFileTime(&systime, &ftime); + FILETIME ftime_local = {}; + FileTimeToLocalFileTime(&ftime, &ftime_local); + FileTimeToSystemTime(&ftime_local, &systime); + Date_Time result = {}; + date_time_from_win32_system_time(&result, &systime); + return(result); +} + +internal +system_universal_date_time_from_local_sig(){ + SYSTEMTIME systime = {}; + win32_system_time_from_date_time(&systime, date_time); + FILETIME ftime = {}; + SystemTimeToFileTime(&systime, &ftime); + FILETIME ftime_local = {}; + LocalFileTimeToFileTime(&ftime, &ftime_local); + FileTimeToSystemTime(&ftime_local, &systime); + Date_Time result = {}; + date_time_from_win32_system_time(&result, &systime); + return(result); +} + internal system_wake_up_timer_create_sig(){ Win32_Object *object = win32_alloc_object(Win32ObjectKind_Timer); @@ -1373,9 +1432,9 @@ win32_gl_create_window(HWND *wnd_out, HGLRC *context_out, DWORD style, RECT rect // NOTE(allen): Load wgl extensions #define LoadWGL(f,l) Stmnt((f) = (f##_Function*)wglGetProcAddress(#f); \ - (l) = (l) && win32_wgl_good((Void_Func*)(f));) - - b32 load_success = true; +(l) = (l) && win32_wgl_good((Void_Func*)(f));) + + b32 load_success = true; LoadWGL(wglCreateContextAttribsARB, load_success); LoadWGL(wglChoosePixelFormatARB, load_success); LoadWGL(wglGetExtensionsStringEXT, load_success);