add offset to time zones

This commit is contained in:
Asim Aslam
2022-03-01 09:10:12 +00:00
parent 3be782ebce
commit b859145337
3 changed files with 26 additions and 13 deletions

View File

@@ -137,12 +137,12 @@ func (t *Time) Zone(ctx context.Context, req *pb.ZoneRequest, rsp *pb.ZoneRespon
rsp.Longitude = location["lon"].(float64)
rsp.Timezone = location["tz_id"].(string)
rsp.Localtime = location["localtime"].(string)
loc, _ := time.LoadLocation(rsp.Timezone)
ti := time.Now().In(loc)
isDST := t.TZ.IsDST(ti)
rsp.Abbreviation, _ = t.TZ.GetTimezoneAbbreviation(rsp.Timezone, isDST)
rsp.Dst = isDST
_, offset := ti.Zone()
rsp.Offset = int32(offset / 60 / 60)
return nil
}

View File

@@ -1,6 +1,6 @@
// Code generated by protoc-gen-go. DO NOT EDIT.
// versions:
// protoc-gen-go v1.26.0
// protoc-gen-go v1.27.1
// protoc v3.15.6
// source: proto/time.proto
@@ -225,6 +225,8 @@ type ZoneResponse struct {
Localtime string `protobuf:"bytes,8,opt,name=localtime,proto3" json:"localtime,omitempty"`
// is daylight savings
Dst bool `protobuf:"varint,9,opt,name=dst,proto3" json:"dst,omitempty"`
// UTC offset in hours
Offset int32 `protobuf:"varint,10,opt,name=offset,proto3" json:"offset,omitempty"`
}
func (x *ZoneResponse) Reset() {
@@ -322,6 +324,13 @@ func (x *ZoneResponse) GetDst() bool {
return false
}
func (x *ZoneResponse) GetOffset() int32 {
if x != nil {
return x.Offset
}
return 0
}
var File_proto_time_proto protoreflect.FileDescriptor
var file_proto_time_proto_rawDesc = []byte{
@@ -341,7 +350,7 @@ var file_proto_time_proto_rawDesc = []byte{
0x20, 0x01, 0x28, 0x03, 0x52, 0x04, 0x75, 0x6e, 0x69, 0x78, 0x22, 0x29, 0x0a, 0x0b, 0x5a, 0x6f,
0x6e, 0x65, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x1a, 0x0a, 0x08, 0x6c, 0x6f, 0x63,
0x61, 0x74, 0x69, 0x6f, 0x6e, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x08, 0x6c, 0x6f, 0x63,
0x61, 0x74, 0x69, 0x6f, 0x6e, 0x22, 0x86, 0x02, 0x0a, 0x0c, 0x5a, 0x6f, 0x6e, 0x65, 0x52, 0x65,
0x61, 0x74, 0x69, 0x6f, 0x6e, 0x22, 0x9e, 0x02, 0x0a, 0x0c, 0x5a, 0x6f, 0x6e, 0x65, 0x52, 0x65,
0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x1a, 0x0a, 0x08, 0x6c, 0x6f, 0x63, 0x61, 0x74, 0x69,
0x6f, 0x6e, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x08, 0x6c, 0x6f, 0x63, 0x61, 0x74, 0x69,
0x6f, 0x6e, 0x12, 0x16, 0x0a, 0x06, 0x72, 0x65, 0x67, 0x69, 0x6f, 0x6e, 0x18, 0x02, 0x20, 0x01,
@@ -357,15 +366,17 @@ var file_proto_time_proto_rawDesc = []byte{
0x52, 0x0c, 0x61, 0x62, 0x62, 0x72, 0x65, 0x76, 0x69, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x12, 0x1c,
0x0a, 0x09, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x74, 0x69, 0x6d, 0x65, 0x18, 0x08, 0x20, 0x01, 0x28,
0x09, 0x52, 0x09, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x74, 0x69, 0x6d, 0x65, 0x12, 0x10, 0x0a, 0x03,
0x64, 0x73, 0x74, 0x18, 0x09, 0x20, 0x01, 0x28, 0x08, 0x52, 0x03, 0x64, 0x73, 0x74, 0x32, 0x65,
0x0a, 0x04, 0x54, 0x69, 0x6d, 0x65, 0x12, 0x2c, 0x0a, 0x03, 0x4e, 0x6f, 0x77, 0x12, 0x10, 0x2e,
0x74, 0x69, 0x6d, 0x65, 0x2e, 0x4e, 0x6f, 0x77, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a,
0x11, 0x2e, 0x74, 0x69, 0x6d, 0x65, 0x2e, 0x4e, 0x6f, 0x77, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e,
0x73, 0x65, 0x22, 0x00, 0x12, 0x2f, 0x0a, 0x04, 0x5a, 0x6f, 0x6e, 0x65, 0x12, 0x11, 0x2e, 0x74,
0x69, 0x6d, 0x65, 0x2e, 0x5a, 0x6f, 0x6e, 0x65, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a,
0x12, 0x2e, 0x74, 0x69, 0x6d, 0x65, 0x2e, 0x5a, 0x6f, 0x6e, 0x65, 0x52, 0x65, 0x73, 0x70, 0x6f,
0x6e, 0x73, 0x65, 0x22, 0x00, 0x42, 0x0e, 0x5a, 0x0c, 0x2e, 0x2f, 0x70, 0x72, 0x6f, 0x74, 0x6f,
0x3b, 0x74, 0x69, 0x6d, 0x65, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33,
0x64, 0x73, 0x74, 0x18, 0x09, 0x20, 0x01, 0x28, 0x08, 0x52, 0x03, 0x64, 0x73, 0x74, 0x12, 0x16,
0x0a, 0x06, 0x6f, 0x66, 0x66, 0x73, 0x65, 0x74, 0x18, 0x0a, 0x20, 0x01, 0x28, 0x05, 0x52, 0x06,
0x6f, 0x66, 0x66, 0x73, 0x65, 0x74, 0x32, 0x65, 0x0a, 0x04, 0x54, 0x69, 0x6d, 0x65, 0x12, 0x2c,
0x0a, 0x03, 0x4e, 0x6f, 0x77, 0x12, 0x10, 0x2e, 0x74, 0x69, 0x6d, 0x65, 0x2e, 0x4e, 0x6f, 0x77,
0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x11, 0x2e, 0x74, 0x69, 0x6d, 0x65, 0x2e, 0x4e,
0x6f, 0x77, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x00, 0x12, 0x2f, 0x0a, 0x04,
0x5a, 0x6f, 0x6e, 0x65, 0x12, 0x11, 0x2e, 0x74, 0x69, 0x6d, 0x65, 0x2e, 0x5a, 0x6f, 0x6e, 0x65,
0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x12, 0x2e, 0x74, 0x69, 0x6d, 0x65, 0x2e, 0x5a,
0x6f, 0x6e, 0x65, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x00, 0x42, 0x0e, 0x5a,
0x0c, 0x2e, 0x2f, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x3b, 0x74, 0x69, 0x6d, 0x65, 0x62, 0x06, 0x70,
0x72, 0x6f, 0x74, 0x6f, 0x33,
}
var (

View File

@@ -54,5 +54,7 @@ message ZoneResponse {
string localtime = 8;
// is daylight savings
bool dst = 9;
// UTC offset in hours
int32 offset = 10;
}