Skip to content

Commit

Permalink
datetime_example
Browse files Browse the repository at this point in the history
  • Loading branch information
askalt committed Aug 26, 2023
1 parent 403f2c3 commit 47d39e9
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 0 deletions.
8 changes: 8 additions & 0 deletions datetime/config.lua
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,14 @@ box.cfg{
box.schema.user.create('test', { password = 'test' , if_not_exists = true })
box.schema.user.grant('test', 'execute', 'universe', nil, { if_not_exists = true })

function get_datetime_no_offset()
return datetime.new({ year = 2023, month = 9, day = 2, tzoffset = 0 })
end

function get_datetime_offset()
return datetime.new({ year = 2023, month = 9, day = 2, tzoffset = 240 })
end

box.once("init", function()
local s_1 = box.schema.space.create('testDatetime_1', {
id = 524,
Expand Down
31 changes: 31 additions & 0 deletions datetime/example_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -287,3 +287,34 @@ func ExampleInterval_Sub() {
// Output:
// {-9 2 3 0 0 -30 10 0 1}
}

func Example_wrongDatetime() {
opts := tarantool.Opts{
User: "test",
Pass: "test",
}
conn, err := tarantool.Connect("127.0.0.1:3013", opts)
if err != nil {
fmt.Printf("Error in connect is %v", err)
return
}
var res [][]Datetime
req := tarantool.NewCallRequest("get_datetime_no_offset")
if err := conn.Do(req).GetTyped(&res); err != nil {
fmt.Printf("can't do request: %v", err)
return
}
fmt.Println(res[0][0].ToTime())

var res2 [][]Datetime
req = tarantool.NewCallRequest("get_datetime_offset")
if err := conn.Do(req).GetTyped(&res2); err != nil {
fmt.Printf("can't do request: %v", err)
return
}

fmt.Println(res2[0][0].ToTime())
// Output:
// 2023-09-02 00:00:00 +0000 +0000
// 2023-09-02 00:00:00 +0400 +0400
}

0 comments on commit 47d39e9

Please sign in to comment.