Skip to content

msgpack_ext: added string() function for interval#527

Open
babyTsakhes wants to merge 1 commit intomasterfrom
babyTsakhes/gh-322-add-string-convertion-for-interval
Open

msgpack_ext: added string() function for interval#527
babyTsakhes wants to merge 1 commit intomasterfrom
babyTsakhes/gh-322-add-string-convertion-for-interval

Conversation

@babyTsakhes
Copy link
Collaborator

Added function for converting interval type to string, added tests for this function. Added test for decimal conversion.

Closes #322

@babyTsakhes babyTsakhes marked this pull request as draft February 8, 2026 19:49
@oleg-jukovec
Copy link
Collaborator

Please, rebase on the master branch too.

@babyTsakhes babyTsakhes force-pushed the babyTsakhes/gh-322-add-string-convertion-for-interval branch 3 times, most recently from 6cd04f5 to 82c0511 Compare February 10, 2026 15:57
Comment on lines +237 to +246
values := []int64{
ival.Year,
ival.Month,
ival.Week,
ival.Day,
ival.Hour,
ival.Min,
ival.Sec,
ival.Nsec,
}
Copy link
Collaborator

@oleg-jukovec oleg-jukovec Feb 10, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like a constant array too.

@oleg-jukovec
Copy link
Collaborator

@babyTsakhes any updates here?

@babyTsakhes babyTsakhes force-pushed the babyTsakhes/gh-322-add-string-convertion-for-interval branch 2 times, most recently from b39838b to c04a7f5 Compare March 11, 2026 21:04
@babyTsakhes babyTsakhes marked this pull request as ready for review March 12, 2026 10:29
@babyTsakhes babyTsakhes force-pushed the babyTsakhes/gh-322-add-string-convertion-for-interval branch from 9fecc56 to b4a5165 Compare March 12, 2026 10:32
@babyTsakhes
Copy link
Collaborator Author

babyTsakhes commented Mar 12, 2026

testing_mac_os (stable, macos-15)35040Z --- PASS: TestFdDialer_Dial/id_response_error (1.00s)
2026-03-12T10:36:34.6435370Z === RUN TestFdDialer_Dial_requirements
2026-03-12T10:36:34.6455500Z dial_test.go:723:
2026-03-12T10:36:34.6456680Z Error Trace: /Users/runner/work/go-tarantool/go-tarantool/tarantool/go-tarantool/dial_test.go:723
2026-03-12T10:36:34.6457930Z Error: "failed to read greeting: read tcp 127.0.0.1:50143->127.0.0.1:50141: read: bad file descriptor" does not contain "invalid server protocol"
2026-03-12T10:36:34.6458730Z Test: TestFdDialer_Dial_requirements
2026-03-12T10:36:34.6459140Z --- FAIL: TestFdDialer_Dial_requirements

@babyTsakhes
Copy link
Collaborator Author

2026-03-12T10:47:42.2373532Z === RUN TestGracefulShutdown
2026-03-12T10:47:42.2382870Z shutdown_test.go:135:
2026-03-12T10:47:42.2383885Z Error Trace: /home/runner/work/go-tarantool/go-tarantool/shutdown_test.go:135
2026-03-12T10:47:42.2385405Z Error: Expected nil, but got: &fs.PathError{Op:"fork/exec", Path:"/usr/bin/tarantool", Err:0x9}
2026-03-12T10:47:42.2386275Z Test: TestGracefulShutdown
2026-03-12T10:47:42.2386764Z --- FAIL: TestGracefulShutdown (0.00s)
run-tests (1.24, 3.4, false, false) / run-testsrun-tests (1.24, 3.4, false, false) / run-tests

@babyTsakhes
Copy link
Collaborator Author

babyTsakhes commented Mar 17, 2026

BenchmarkIntervalStringOld-2 2686132 450.5 ns/op 150 B/op 8 allocs/op
BenchmarkIntervalString-2 2716714 615.6 ns/op 150 B/op 8 allocs/op
PASS
ok github.com/tarantool/go-tarantool/v3/datetime 3.822s
Old version of string is faster.

@babyTsakhes
Copy link
Collaborator Author

func (ival Interval) StringOld() string {
values := []int64{
ival.Year,
ival.Month,
ival.Week,
ival.Day,
ival.Hour,
ival.Min,
ival.Sec,
ival.Nsec,
}

parts := make([]string, 0, 8)
first := true
hasNonZero := false

for i, field := range intervalFields {
	value := values[i]
	if value == 0 {
		continue
	}

	hasNonZero = true
	var sign string
	var absValue int64

	if value < 0 {
		sign = "-"
		absValue = -value
	} else {
		if first {
			sign = "+"
		}
		absValue = value
	}

	unit := field.plur
	if absValue == 1 {
		unit = field.sing
	}

	parts = append(parts, fmt.Sprintf("%s%d %s", sign, absValue, unit))
	first = false
}

if !hasNonZero {
	return "0 seconds"
}

return strings.Join(parts, ", ")

}

func (ival Interval) String() string {
parts := make([]string, 0, 8)
first := true
hasNonZero := false

addPart := func(value int64, sing, plur string) {
	if value == 0 {
		return
	}
	hasNonZero = true
	var sign string
	var absValue int64
	if value < 0 {
		sign = "-"
		absValue = -value
	} else {
		if first {
			sign = "+"
		}
		absValue = value
	}
	unit := plur
	if absValue == 1 {
		unit = sing
	}
	parts = append(parts, fmt.Sprintf("%s%d %s", sign, absValue, unit))
	first = false
}

addPart(ival.Year, "year", "years")
addPart(ival.Month, "month", "months")
addPart(ival.Week, "week", "weeks")
addPart(ival.Day, "day", "days")
addPart(ival.Hour, "hour", "hours")
addPart(ival.Min, "minute", "minutes")
addPart(ival.Sec, "second", "seconds")
addPart(ival.Nsec, "nanosecond", "nanoseconds")

if !hasNonZero {
	return "0 seconds"
}
return strings.Join(parts, ", ")

}

Added function for converting interval type to string, added tests for this function. Added test for decimal conversion.

Closes #322
@babyTsakhes babyTsakhes force-pushed the babyTsakhes/gh-322-add-string-convertion-for-interval branch from 3b611e7 to 97ca153 Compare March 17, 2026 15:57
@babyTsakhes
Copy link
Collaborator Author

Please take a look.

@babyTsakhes
Copy link
Collaborator Author

RUN TestConnectionHandlerOpenError
2026-03-17T15:59:55.2847270Z 2026/03/17 15:59:55 tarantool: storing connection to 127.0.0.1:3013 canceled: any error
2026-03-17T15:59:55.2850390Z 2026/03/17 15:59:55 tarantool: connect to 127.0.0.1:3013 failed: storing connection canceled
2026-03-17T15:59:55.2871680Z 2026/03/17 15:59:55 tarantool: storing connection to 127.0.0.1:3014 canceled: any error
2026-03-17T15:59:55.2874940Z 2026/03/17 15:59:55 tarantool: connect to 127.0.0.1:3014 failed: storing connection canceled
2026-03-17T15:59:55.2877160Z --- PASS: TestConnectionHandlerOpenError (0.01s)
2026-03-17T15:59:55.2878680Z === RUN TestConnectionHandlerUpdateError
2026-03-17T15:59:55.3104700Z 2026/03/17 15:59:55 tarantool: connect to 127.0.0.1:3013 failed: failed to read greeting: context canceled
2026-03-17T15:59:55.3122250Z 2026/03/17 15:59:55 tarantool: storing connection to 127.0.0.1:3014 canceled: any error
2026-03-17T15:59:55.3122810Z connection_pool_test.go:1283:
2026-03-17T15:59:55.3123630Z Error Trace: /Users/runner/work/go-tarantool/go-tarantool/tarantool/go-tarantool/pool/connection_pool_test.go:1283
2026-03-17T15:59:55.3124620Z Error: Expected nil, but got: tarantool.ClientError{Code:0x4001, Msg:"connection closed by client"}
2026-03-17T15:59:55.3125170Z Test: TestConnectionHandlerUpdateError
2026-03-17T15:59:55.3125500Z Messages: failed to make ro
2026-03-17T15:59:55.3125820Z 2026/03/17 15:59:55 tarantool: reopen connection to 127.0.0.1:3014 failed: pool is closed
2026-03-17T15:59:55.3126240Z 2026/03/17 15:59:55 tarantool: reopen connection to 127.0.0.1:3013 failed: pool is closed
2026-03-17T15:59:55.3126600Z --- FAIL: TestConnectionHandlerUpdateError (0.03s)
macos

@babyTsakhes
Copy link
Collaborator Author

testing / testing_mac_os (1.24, macos-14) (push)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

messagepack extensions: add String() for Decimal, Datetime and Interval

2 participants