-
Notifications
You must be signed in to change notification settings - Fork 3.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
sql: fix century for strftime #45884
Comments
@chriscasano thanks for finding this issue. Can you provide some context? What was the use case? Why is this important? So you know:
I suppose we can look at it but it's going to be hard(er) than usual. There's a reason why the feature is still marked as "experimental" even though it was introduced back in 1.1 or 2.0. |
@otan maybe I got this wrong and the code uses Go for strftime and C for strptime. If that is the case, it may be interesting to look into using C for both. I'll let you look into it. |
Sure np - Customer's app utilizes these timestamps and can discuss outside of public forum. 1 - Wouldn't century be 00? The year is left padded, shouldn't the century as well? |
I personally love strftime/strptime and i wish we can make them more robust and production-ready. |
interesting... so in python, strftime is funny before 1900:
edit: in C, we do lpad 4 digits:
(but not for negatives)
|
oops, time_t is not an int, let me recheck! |
a bit hesitant to modifying strtime to use the C implementation, how do we feel about using https://github.com/lestrrat-go/strftime (MIT License) instead? if so, do we want to modify |
Last time I checked the alternate implementations 1) supported fewer features (in particular did not deal with DST properly) and 2) did not support strptime properly. I could see wisdom in extending |
We have a test suite (both inside crdb and in knz/strtime) to exercise any substitute we may find. |
@chriscasano in the meantime, you can use
@knz i'm not 100% buying into rewriting our own implementation again in C, given it may cause even more bugs but I think we can make this implementation C compatible for now and come back to that decision later. However, it appears as if C does padding so I will modify it to |
also, the POSIX standard specifies %Y can either be %d or %04d - see rationale in (https://pubs.opengroup.org/onlinepubs/9699919799/functions/strftime.html) |
Ah that makes more sense. Thanks @otan! |
my preference is to copy-paste the BSD code for strftime, like I already did for strptime. The advantages are that 1) it's going to guarantee consistent behavior between the two functions 2) that code is absolutely battle-tested 3) the folk who wrote it have a better respect for API standards than the Go developers. |
running into minor problems converting golang's time to c's time struct DST field, as you cannot determine in golang whether something is DST or not without some extreme hacks. pending WIP: https://github.com/otan-cockroach/strtime/pull/new/c_impl |
(since this is lower priority with a workaround, unassigning for now) |
makes sense. workaround is perfectly fine. |
We have marked this issue as stale because it has been inactive for |
issue is still relevant |
We have marked this issue as stale because it has been inactive for |
The year with century notation (%Y) doesn't always output the century:
root@:26257/defaultdb> select experimental_strftime('0001-01-01 00:00:00.000000'::TIMESTAMP, '%Y-%m-%d %H:%M:%S.%f');
experimental_strftime
+-----------------------------+
01-01-01 00:00:00.000000000
(1 row)
Jira issue: CRDB-5122
The text was updated successfully, but these errors were encountered: