datetime: fix parse and use of %s (epoch)#12146
Open
tmr-g wants to merge 1 commit intotarantool:masterfrom
Open
datetime: fix parse and use of %s (epoch)#12146tmr-g wants to merge 1 commit intotarantool:masterfrom
tmr-g wants to merge 1 commit intotarantool:masterfrom
Conversation
tmr-g
added a commit
to tmr-g/tarantool
that referenced
this pull request
Dec 16, 2025
Missing test suit for invalid strptime-format strings added to lua and c unit tests. Some invalid cases added also. The suit is need for this (tarantool#12060) and other existing PRs. For example, tarantool#12146 awaits it. Part of tarantool#12060 NO_CHANGELOG=test NO_DOC=test
tmr-g
added a commit
to tmr-g/tarantool
that referenced
this pull request
Dec 17, 2025
Missing test suit for invalid strptime-format strings added to lua and c unit tests. Some invalid cases added also. The suit is need for this (tarantool#12060) and other existing PRs. For example, tarantool#12146 awaits it. NO_CHANGELOG=test NO_DOC=test
35c7838 to
32b36d9
Compare
1da129e to
567160b
Compare
db9346d to
b180431
Compare
lenkis
approved these changes
Dec 30, 2025
| ## bugfix/datetime | ||
|
|
||
| * The epoch seconds value parsed with `'%s'` | ||
| by `datetime.parse()` isn't ignored and used |
Contributor
There was a problem hiding this comment.
Suggested change
| by `datetime.parse()` isn't ignored and used | |
| by `datetime.parse()` isn't ignored and is used |
ligurio
reviewed
Jan 16, 2026
test/app-tap/datetime.test.lua
Outdated
Comment on lines
37
to
40
| local MIN_EPOCH_SECS_VALUE = INT_MIN * -- MIN_DT_DAY_VALUE | ||
| SECS_PER_DAY - SECS_EPOCH_OFFSET | ||
| local MAX_EPOCH_SECS_VALUE = INT_MAX * -- MAX_DT_DAY_VALUE | ||
| SECS_PER_DAY - SECS_EPOCH_OFFSET |
Contributor
Author
There was a problem hiding this comment.
Replace comments by "constants".
test/app-tap/datetime.test.lua
Outdated
Comment on lines
2773
to
2788
| -- mix of timestamp with y/m/d | ||
| buf = '26-08-2024 1724630400', | ||
| fmt = '%d-%m-%Y %s', | ||
| }, | ||
| { | ||
| -- mix of timestamp with h/m/s | ||
| buf = '123 12:12:12', | ||
| fmt = '%d-%m-%Y %s', | ||
| }, | ||
| { | ||
| -- timestamp < MIN_EPOCH_SECS_VALUE | ||
| buf = string.format('%d', MIN_EPOCH_SECS_VALUE - 1), | ||
| fmt = '%s', | ||
| }, | ||
| { | ||
| -- timestamp > MAX_EPOCH_SECS_VALUE |
Member
There was a problem hiding this comment.
comment started uppercase and the dot at the end
| bool use_timestamp = (dt == 0) && | ||
| (tm->tm_hour | tm->tm_min | tm->tm_sec) == 0; | ||
| if (use_timestamp) { | ||
| local_secs = tm->tm_epoch; |
Member
There was a problem hiding this comment.
We can set it by default and leave a single branch
Contributor
Author
There was a problem hiding this comment.
It seems, that variant will be less clear for a reader. Using the timestamp is not a default case.
|
|
||
| const int ymd_flags = FLAG_YEAR | FLAG_MONTH | FLAG_MDAY; | ||
| if ((flags & FLAG_EPOCH) == 0) | ||
| ; |
test/app-tap/datetime.test.lua
Outdated
| test:test("Parse invalid string with a custom format", function(test) | ||
| local formats = { | ||
| { | ||
| -- mix of timestamp with y/m/d |
Member
There was a problem hiding this comment.
first letter in uppercase and dot at the end.
| -- %s is replaced by the number of seconds since the | ||
| -- Epoch, UTC (see mktime(3)). | ||
| { | ||
| buf = '26-08-2024 1724630400', |
Member
There was a problem hiding this comment.
Why it is removed?
before the patch:
tarantool> dt.parse('26-08-2024 1724630400', { format = '%d-%m-%Y %s' })
---
- 2024-08-26T00:00:00Z
- 21
...
after the patch:
tarantool> dt.parse('26-08-2024 1724630400', { format = '%d-%m-%Y %s' })
---
- error: 'builtin/datetime.lua:897: could not parse ''26-08-2024 1724630400'' using
''%d-%m-%Y %s'' format'
4202905 to
5693757
Compare
- The epoch seconds value parsed with `'%s'` by `datetime.parse()` isn't ignored and used now as a timestamp value by `datetime.new()`. - The zero value doesn't produce an error. Closes tarantool#12143 NO_DOC=bugfix
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
'%s'bydatetime.parse()isn't ignored and used now as a timestamp value bydatetime.new().Closes #12143
NO_DOC=bugfix