Revert "deprecate --format and --list in into datetime (#10017)"#10055
Conversation
|
I was going to revert this today too in order to play with it and test some things out. |
|
This is what I'm not getting. '20220604' | into datetime -f '%Y%m%d'See other comments in #10017 |
mm this command gives me Thu Jan 1 00:00:00 1970i'm confused now 😆 |
|
I get this, which is also wrong. ❯ '20220604' | into datetime -f '%Y%m%d'
Thu, 01 Jan 1970 00:00:00 +0000 (53 years ago)Oh, I just noticed that it's the same result we're getting. Just in a different format. |
|
mm 🤔 i meant, it does not have anything to do with this PR, but it means that |
|
i'm trying to debug now inside of 10055. i'm not sure what's going one yet. |
|
The problem is that it's never getting to this code. The logic is wrong, // If input is not a timestamp, try parsing it as a string
match input {
Value::String { val, span } => {
match dateformat {
Some(dt) => match DateTime::parse_from_str(val, &dt.0) {
Ok(d) => {
eprintln!("on ok arm");
Value::Date { val: d, span: head }
} |
|
I think we should land this revert and fix the problem. What's going on is that if you do something like I think PR #8337 broke it. |
|
I think this fix could be as simple as
if let Ok(ts) = timestamp {put this if dateformat.is_none() {
if let Ok(ts) = timestamp {
match input {
Value::String { val, span } => {
match dateformat {
Some(dt) => match DateTime::parse_from_str(val, &dt.0) {
Ok(d) => {
eprintln!("on ok arm");
Value::Date { val: d, span: head }
}
// Err(reason) => {
// Value::Error {
// error: Box::new(ShellError::CantConvert { to_type: format!("could not parse as datetime using format '{}'", dt.0), from_type: reason.to_string(), span: head, help: Some("you can use `into datetime` without a format string to enable flexible parsing".to_string()) }),
// }
// }
Err(_) => {
eprintln!("on err arm");
match parse_date_from_string(val, *span) {
Ok(date) => Value::Date {
val: date,
span: *span,
},
Err(err) => err,
}
}
}, |
|
reverting this because it would still be nice to have this functionality, we just need to fix it. |
|
@fncred now that this fix has been applied, is there any remaining issue? I think all will be clear and straightforward once 0.85 is released and the deprecated
|
@bobhy I took it upon myself to try and fix the problem, but it would be nice if you gave it a once over.
I don't think I disagree with your second paragraph. There is a switch that let's users specify the format of the input string. That's what https://docs.rs/chrono/0.4.26/chrono/struct.DateTime.html#method.parse_from_str is all about. However, it requires a timezone so we should document that in the parameter help text I think. |
|
You're right, So I see the problem mentioned above is still active: doesn't work, but (from the example) does. And I think the reason is that you have to use the NaiveDateTime flavor of So, for nu to handle both kinds of string input with Note that So I vote we not make |
That's what I meant above, when I said, "However, it requires a timezone so we should document that in the parameter help text, I think." I think we just need to say something like, "try adding a timezone in order to parse", or something like that. Or show people how to tack on |
|
Documenting the requirement to include a timezone token in the format
argument means you can't use it to parse a timestamp that doesn't have a
timezone. That sounds like a pretty significant restriction! Is it worth
Nu having such a hobbled feature? What's the use case (that `dtparse`
can't handle)?
…On Mon, Aug 21, 2023 at 6:03 AM Darren Schroeder ***@***.***> wrote:
And I think the reason is that you have to use the NaiveDateTime flavor of
parse_date_from_string() to parse an input that does not have a time zone.
That's what I meant above, when I said, "However, it requires a timezone
so we should document that in the parameter help text, I think."
I think we just need to say something like, "try adding a timezone in
order to parse", or something like that. Or show people how to tack on
_010203+0000 and _%H%M%S%z. I wonder if that's too much. I'd also feel
better if we just had a crate that worked better and parsed per provided
format.
—
Reply to this email directly, view it on GitHub
<#10055 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAPBIZH6ER6YXHYSAACAWN3XWNMCXANCNFSM6AAAAAA3WO6JOI>
.
You are receiving this because you were mentioned.Message ID:
***@***.***>
|
Having a custom format that you want to change into a datetime. Seems like that's the intention behind ---format anyway. |
|
In that case, you could parse the custom format via `parse` or `parse
--regex` worst case and build a standard format datetime string by hand.
You could reduce code complexity and maintenance effort by eliminating
`--format` and `--list`. We all were confused about `--format` when this
issue first came up...
…On Tue, Aug 22, 2023 at 4:46 AM Darren Schroeder ***@***.***> wrote:
What's the use case (that dtparse can't handle)?
Having a custom format that you want to change into a datetime. Seems like
that's the intention behind ---format anyway.
—
Reply to this email directly, view it on GitHub
<#10055 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAPBIZGV6I3YSOPXHI55KO3XWSLYLANCNFSM6AAAAAA3WO6JOI>
.
You are receiving this because you were mentioned.Message ID:
***@***.***>
|
related to
--formatand--listininto datetime#10017 (comment)Description
this PR undeprecates
into datetime --formatandinto datetime --list.this PR reverts commit f33b60c.
User-Facing Changes
Tests + Formatting
After Submitting