Skip to content

Commit

Permalink
Merge pull request #11 from goccy/fix-value-to-time
Browse files Browse the repository at this point in the history
Fix types.Value's ToTime API
  • Loading branch information
goccy authored Jul 8, 2022
2 parents 758df37 + be2f962 commit ddbc24c
Show file tree
Hide file tree
Showing 9 changed files with 86 additions and 17 deletions.
39 changes: 23 additions & 16 deletions internal/ccall/go-absl/time/go_internal/cctz/time_zone/bridge.inc
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,17 @@ void GO_EXPORT(cctz_FixedOffsetToAbbr)(void * arg0,void ** arg1)

void GO_EXPORT(cctz_detail_format)(void * arg0,void * arg1,void * arg2,void * arg3,void ** arg4)
{
fprintf(stderr, "unimplemented cctz_detail_format");
*arg4 = (void *)((new std::string(absl::time_internal::cctz::detail::format(
(char *)arg0,
*(absl::time_internal::cctz::time_point<absl::time_internal::cctz::seconds> *)arg1,
*(absl::time_internal::cctz::detail::femtoseconds *)arg2,
*(absl::time_internal::cctz::time_zone *)arg3
)))->c_str());
}

void GO_EXPORT(cctz_detail_parse)(void * arg0,void * arg1,void * arg2,void * arg3,void * arg4,void * arg5,int* arg6)
{
fprintf(stderr, "unimplemented cctz_detail_parse");
fprintf(stderr, "[WARN] unimplemented cctz_detail_parse\n");
}

void GO_EXPORT(TimeZoneIf_Load)(void * arg0,void ** arg1)
Expand Down Expand Up @@ -48,7 +53,7 @@ void GO_EXPORT(time_zone_Impl_ClearTimeZoneMapTestOnly)()

void GO_EXPORT(time_zone_Impl_UTCImpl)(void ** arg0)
{
fprintf(stderr, "unimplemented time_zone::Impl::UTCImpl");
fprintf(stderr, "[WARN] unimplemented time_zone::Impl::UTCImpl\n");
}

void GO_EXPORT(TimeZoneInfo_Load)(void * arg0,void * arg1,int* arg2)
Expand Down Expand Up @@ -100,62 +105,64 @@ void GO_EXPORT(TimeZoneInfo_PrevTransition)(void * arg0,void * arg1,void * arg2,

void GO_EXPORT(TimeZoneLibC_BreakTime)(void * arg0,void * arg1,void ** arg2)
{
fprintf(stderr, "unimplemented TimeZoneLibC_BreakTime");
fprintf(stderr, "[WARN] unimplemented TimeZoneLibC_BreakTime\n");
}

void GO_EXPORT(TimeZoneLibC_MakeTime)(void * arg0,void * arg1,void ** arg2)
{
fprintf(stderr, "unimplemented TimeZoneLibC_MakeTime");
fprintf(stderr, "[WARN] unimplemented TimeZoneLibC_MakeTime\n");
}

void GO_EXPORT(TimeZoneLibC_Version)(void * arg0,void ** arg1)
{
fprintf(stderr, "unimplemented TimeZoneLibC_Version");
fprintf(stderr, "[WARN] unimplemented TimeZoneLibC_Version\n");
}

void GO_EXPORT(TimeZoneLibC_NextTransition)(void * arg0,void * arg1,void * arg2,int* arg3)
{
fprintf(stderr, "unimplemented TimeZoneLibC_NextTransition");
fprintf(stderr, "[WARN] unimplemented TimeZoneLibC_NextTransition\n");
}

void GO_EXPORT(TimeZoneLibC_PrevTransition)(void * arg0,void * arg1,void * arg2,int* arg3)
{
fprintf(stderr, "unimplemented TimeZoneLibC_PrevTransition");
fprintf(stderr, "[WARN] unimplemented TimeZoneLibC_PrevTransition\n");
}

void GO_EXPORT(time_zone_name)(void ** arg0)
{
fprintf(stderr, "unimplemented time_zone_name");
fprintf(stderr, "[WARN] unimplemented time_zone_name\n");
}

void GO_EXPORT(time_zone_lookup)(void * arg0,void * arg1,void ** arg2)
{
fprintf(stderr, "unimplemented time_zone_lookup");
absl::time_internal::cctz::time_zone *zone = (absl::time_internal::cctz::time_zone *)arg0;
*arg2 = (void *)(new absl::time_internal::cctz::time_zone::absolute_lookup(zone->lookup(*(absl::time_internal::cctz::time_point<absl::time_internal::cctz::seconds> *)arg1)));
}

void GO_EXPORT(time_zone_lookup2)(void * arg0,void * arg1,void ** arg2)
{
fprintf(stderr, "unimplemented time_zone_lookup2");
absl::time_internal::cctz::time_zone *zone = (absl::time_internal::cctz::time_zone *)arg0;
*arg2 = (void *)(new absl::time_internal::cctz::time_zone::civil_lookup(zone->lookup(*(absl::time_internal::cctz::civil_second *)arg1)));
}

void GO_EXPORT(time_zone_next_transition)(void * arg0,void * arg1,int* arg2)
{
fprintf(stderr, "unimplemented time_zone_next_transition");
fprintf(stderr, "[WARN] unimplemented time_zone_next_transition\n");
}

void GO_EXPORT(time_zone_prev_transition)(void * arg0,void * arg1,int* arg2)
{
fprintf(stderr, "unimplemented time_zone_prev_transition");
fprintf(stderr, "[WARN] unimplemented time_zone_prev_transition\n");
}

void GO_EXPORT(time_zone_version)(void * arg0,void ** arg1)
{
fprintf(stderr, "unimplemented time_zone_version");
fprintf(stderr, "[WARN] unimplemented time_zone_version\n");
}

void GO_EXPORT(time_zone_description)(void * arg0,void ** arg1)
{
fprintf(stderr, "unimplemented time_zone_description");
fprintf(stderr, "[WARN] unimplemented time_zone_description\n");
}

void GO_EXPORT(cctz_load_time_zone)(void * arg0,void * arg1,int* arg2)
Expand Down Expand Up @@ -186,5 +193,5 @@ void GO_EXPORT(cctz_local_time_zone)(void ** arg0)

void GO_EXPORT(cctz_ParsePosixSpec)(void * arg0,void * arg1,int* arg2)
{
fprintf(stderr, "unimplemented cctz_ParsePosixSpec");
fprintf(stderr, "[WARN] unimplemented cctz_ParsePosixSpec\n");
}
11 changes: 11 additions & 0 deletions internal/ccall/go-zetasql/bind_darwin.go
Original file line number Diff line number Diff line change
Expand Up @@ -27422,6 +27422,17 @@ func zetasql_Value_enum_name(arg0 unsafe.Pointer, arg1 *unsafe.Pointer) {
C.export_zetasql_Value_enum_name(arg0, arg1)
}

func Value_ToTime(arg0 unsafe.Pointer, arg1 *int64) {
zetasql_Value_ToTime(
arg0,
(*C.int64_t)(unsafe.Pointer(arg1)),
)
}

func zetasql_Value_ToTime(arg0 unsafe.Pointer, arg1 *C.int64_t) {
C.export_zetasql_Value_ToTime(arg0, arg1)
}

func Value_ToUnixMicros(arg0 unsafe.Pointer, arg1 *int64) {
zetasql_Value_ToUnixMicros(
arg0,
Expand Down
11 changes: 11 additions & 0 deletions internal/ccall/go-zetasql/bind_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -27425,6 +27425,17 @@ func zetasql_Value_enum_name(arg0 unsafe.Pointer, arg1 *unsafe.Pointer) {
C.export_zetasql_Value_enum_name(arg0, arg1)
}

func Value_ToTime(arg0 unsafe.Pointer, arg1 *int64) {
zetasql_Value_ToTime(
arg0,
(*C.int64_t)(unsafe.Pointer(arg1)),
)
}

func zetasql_Value_ToTime(arg0 unsafe.Pointer, arg1 *C.int64_t) {
C.export_zetasql_Value_ToTime(arg0, arg1)
}

func Value_ToUnixMicros(arg0 unsafe.Pointer, arg1 *int64) {
zetasql_Value_ToUnixMicros(
arg0,
Expand Down
11 changes: 11 additions & 0 deletions internal/ccall/go-zetasql/public/simple_catalog/bind_darwin.go
Original file line number Diff line number Diff line change
Expand Up @@ -1391,6 +1391,17 @@ func simple_catalog_Value_enum_name(arg0 unsafe.Pointer, arg1 *unsafe.Pointer) {
C.export_zetasql_public_simple_catalog_Value_enum_name(arg0, arg1)
}

func Value_ToTime(arg0 unsafe.Pointer, arg1 *int64) {
simple_catalog_Value_ToTime(
arg0,
(*C.int64_t)(unsafe.Pointer(arg1)),
)
}

func simple_catalog_Value_ToTime(arg0 unsafe.Pointer, arg1 *C.int64_t) {
C.export_zetasql_public_simple_catalog_Value_ToTime(arg0, arg1)
}

func Value_ToUnixMicros(arg0 unsafe.Pointer, arg1 *int64) {
simple_catalog_Value_ToUnixMicros(
arg0,
Expand Down
11 changes: 11 additions & 0 deletions internal/ccall/go-zetasql/public/simple_catalog/bind_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -1394,6 +1394,17 @@ func simple_catalog_Value_enum_name(arg0 unsafe.Pointer, arg1 *unsafe.Pointer) {
C.export_zetasql_public_simple_catalog_Value_enum_name(arg0, arg1)
}

func Value_ToTime(arg0 unsafe.Pointer, arg1 *int64) {
simple_catalog_Value_ToTime(
arg0,
(*C.int64_t)(unsafe.Pointer(arg1)),
)
}

func simple_catalog_Value_ToTime(arg0 unsafe.Pointer, arg1 *C.int64_t) {
C.export_zetasql_public_simple_catalog_Value_ToTime(arg0, arg1)
}

func Value_ToUnixMicros(arg0 unsafe.Pointer, arg1 *int64) {
simple_catalog_Value_ToUnixMicros(
arg0,
Expand Down
7 changes: 7 additions & 0 deletions internal/ccall/go-zetasql/public/simple_catalog/bridge.inc
Original file line number Diff line number Diff line change
Expand Up @@ -759,6 +759,13 @@ void GO_EXPORT(Value_enum_name)(void * arg0,void ** arg1)
*arg1 = (void *)((new std::string(value->enum_name()))->c_str());
}

void GO_EXPORT(Value_ToTime)(void * arg0,int64_t* arg1)
{
zetasql::Value *value = (zetasql::Value *)arg0;
auto t = value->ToTime();
*arg1 = absl::ToInt64Nanoseconds(absl::time_internal::ToUnixDuration(t));
}

void GO_EXPORT(Value_ToUnixMicros)(void * arg0,int64_t* arg1)
{
zetasql::Value *value = (zetasql::Value *)arg0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ extern void GO_EXPORT(Value_bytes_value)(void * arg0,void ** arg1);
extern void GO_EXPORT(Value_date_value)(void * arg0,int* arg1);
extern void GO_EXPORT(Value_enum_value)(void * arg0,int* arg1);
extern void GO_EXPORT(Value_enum_name)(void * arg0,void ** arg1);
extern void GO_EXPORT(Value_ToTime)(void * arg0,int64_t* arg1);
extern void GO_EXPORT(Value_ToUnixMicros)(void * arg0,int64_t* arg1);
extern void GO_EXPORT(Value_ToUnixNanos)(void * arg0,int64_t* arg1,void ** arg2);
extern void GO_EXPORT(Value_ToPacked64TimeMicros)(void * arg0,int64_t* arg1);
Expand Down
5 changes: 5 additions & 0 deletions internal/cmd/generator/bridge.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5281,6 +5281,11 @@
- struct
ret:
- string
- name: Value_ToTime
args:
- struct
ret:
- int64
- name: Value_ToUnixMicros
args:
- struct
Expand Down
7 changes: 6 additions & 1 deletion types/value.go
Original file line number Diff line number Diff line change
Expand Up @@ -337,7 +337,12 @@ func (v *value) EnumName() string {
}

func (v *value) ToTime() time.Time {
return time.Time{}
var nanosec int64
internal.Value_ToTime(v.raw, &nanosec)
return time.Unix(
nanosec/int64(time.Second),
nanosec%int64(time.Nanosecond),
)
}

func (v *value) ToUnixMicros() int64 {
Expand Down

0 comments on commit ddbc24c

Please sign in to comment.