@@ -1033,7 +1033,7 @@ class DuckDBNodeAddon : public Napi::Addon<DuckDBNodeAddon> {
1033
1033
int32_t year = date_parts_obj.Get (" year" ).As <Napi::Number>().Int32Value ();
1034
1034
int8_t month = date_parts_obj.Get (" month" ).As <Napi::Number>().Int32Value ();
1035
1035
int8_t day = date_parts_obj.Get (" day" ).As <Napi::Number>().Int32Value ();
1036
- duckdb_date_struct date_parts { year, month, day };
1036
+ duckdb_date_struct date_parts = { year, month, day };
1037
1037
auto date = duckdb_to_date (date_parts);
1038
1038
auto result = Napi::Object::New (env);
1039
1039
result.Set (" days" , Napi::Number::New (env, date.days ));
@@ -1055,28 +1055,67 @@ class DuckDBNodeAddon : public Napi::Addon<DuckDBNodeAddon> {
1055
1055
// function from_time(time: Time): TimeParts
1056
1056
Napi::Value from_time (const Napi::CallbackInfo& info) {
1057
1057
auto env = info.Env ();
1058
- throw Napi::Error::New (env, " Not implemented yet" );
1058
+ auto time_obj = info[0 ].As <Napi::Object>();
1059
+ auto micros = time_obj.Get (" micros" ).As <Napi::Number>().Int64Value ();
1060
+ duckdb_time time = { micros };
1061
+ auto time_parts = duckdb_from_time (time);
1062
+ auto result = Napi::Object::New (env);
1063
+ result.Set (" hour" , Napi::Number::New (env, time_parts.hour ));
1064
+ result.Set (" min" , Napi::Number::New (env, time_parts.min ));
1065
+ result.Set (" sec" , Napi::Number::New (env, time_parts.sec ));
1066
+ result.Set (" micros" , Napi::Number::New (env, time_parts.micros ));
1067
+ return result;
1059
1068
}
1060
1069
1061
1070
// DUCKDB_API duckdb_time_tz duckdb_create_time_tz(int64_t micros, int32_t offset);
1062
1071
// function create_time_tz(micros: number, offset: number): TimeTZ
1063
1072
Napi::Value create_time_tz (const Napi::CallbackInfo& info) {
1064
1073
auto env = info.Env ();
1065
- throw Napi::Error::New (env, " Not implemented yet" );
1074
+ auto micros = info[0 ].As <Napi::Number>().Int64Value ();
1075
+ auto offset = info[1 ].As <Napi::Number>().Int32Value ();
1076
+ auto time_tz = duckdb_create_time_tz (micros, offset);
1077
+ auto result = Napi::Object::New (env);
1078
+ result.Set (" bits" , Napi::BigInt::New (env, time_tz.bits ));
1079
+ return result;
1066
1080
}
1067
1081
1068
1082
// DUCKDB_API duckdb_time_tz_struct duckdb_from_time_tz(duckdb_time_tz micros);
1069
1083
// function from_time_tz(time_tz: TimeTZ): TimeTZParts
1070
1084
Napi::Value from_time_tz (const Napi::CallbackInfo& info) {
1071
1085
auto env = info.Env ();
1072
- throw Napi::Error::New (env, " Not implemented yet" );
1086
+ auto time_tz_obj = info[0 ].As <Napi::Object>();
1087
+ bool lossless;
1088
+ auto bits = time_tz_obj.Get (" bits" ).As <Napi::BigInt>().Uint64Value (&lossless);
1089
+ if (!lossless) {
1090
+ throw Napi::Error::New (env, " bits out of uint64 range" );
1091
+ }
1092
+ duckdb_time_tz time_tz = { bits };
1093
+ auto time_tz_parts = duckdb_from_time_tz (time_tz);
1094
+ auto result = Napi::Object::New (env);
1095
+ auto time = Napi::Object::New (env);
1096
+ time.Set (" hour" , Napi::Number::New (env, time_tz_parts.time .hour ));
1097
+ time.Set (" min" , Napi::Number::New (env, time_tz_parts.time .min ));
1098
+ time.Set (" sec" , Napi::Number::New (env, time_tz_parts.time .sec ));
1099
+ time.Set (" micros" , Napi::Number::New (env, time_tz_parts.time .micros ));
1100
+ result.Set (" time" , time);
1101
+ result.Set (" offset" , Napi::Number::New (env, time_tz_parts.offset ));
1102
+ return result;
1073
1103
}
1074
1104
1075
1105
// DUCKDB_API duckdb_time duckdb_to_time(duckdb_time_struct time);
1076
1106
// function to_time(parts: TimeParts): Time
1077
1107
Napi::Value to_time (const Napi::CallbackInfo& info) {
1078
1108
auto env = info.Env ();
1079
- throw Napi::Error::New (env, " Not implemented yet" );
1109
+ auto time_parts_obj = info[0 ].As <Napi::Object>();
1110
+ int8_t hour = time_parts_obj.Get (" hour" ).As <Napi::Number>().Int32Value ();
1111
+ int8_t min = time_parts_obj.Get (" min" ).As <Napi::Number>().Int32Value ();
1112
+ int8_t sec = time_parts_obj.Get (" sec" ).As <Napi::Number>().Int32Value ();
1113
+ int32_t micros = time_parts_obj.Get (" micros" ).As <Napi::Number>().Int32Value ();
1114
+ duckdb_time_struct time_parts = { hour, min, sec, micros };
1115
+ auto time = duckdb_to_time (time_parts);
1116
+ auto result = Napi::Object::New (env);
1117
+ result.Set (" micros" , Napi::Number::New (env, time.micros ));
1118
+ return result;
1080
1119
}
1081
1120
1082
1121
// DUCKDB_API duckdb_timestamp_struct duckdb_from_timestamp(duckdb_timestamp ts);
0 commit comments