Skip to content
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

Parse() cannot parse a time string like this: 2022-5-18 #131

Closed
zmou opened this issue May 18, 2022 · 5 comments
Closed

Parse() cannot parse a time string like this: 2022-5-18 #131

zmou opened this issue May 18, 2022 · 5 comments
Labels
Optimization Streamline or optimize code

Comments

@zmou
Copy link

zmou commented May 18, 2022

The Parse() method cannot parse a time string when the month or date less than 10 is not preceded by 0, like this: 2022-5-18
Code sample:

carbon.Parse("2020-8-05").ToDateTimeString() // empty string

Do need to support this less formal time format string, thank you!

@zmou zmou added the Question Indicates that an issue, pull request, or discussion needs more information label May 18, 2022
@gouguoyin
Copy link
Member

"2020-8-05" is not a standard time format, you can use

carbon.ParseByLayout("2020-8-05", "2006-1-02")

or

carbon.ParseByFormat("2020-8-05", "Y-n-d")

@zmou
Copy link
Author

zmou commented May 19, 2022

"2020-8-05" is not a standard time format, you can use

carbon.ParseByLayout("2020-8-05", "2006-1-02")

or

carbon.ParseByFormat("2020-8-05", "Y-n-d")

However, such analysis is not feasible for data sources that are not uniform or standardized, such as:

2020-8-5, 2020-08-5, 2020-8-05, 2020-8-5 12:00:00

Is it possible to use string splitting to unify the non-standard input into the canonical one, so that we do not need to care too much about the format of the input, as long as it is a normal time format, not too canonical.

@gouguoyin gouguoyin reopened this May 23, 2022
@zmou
Copy link
Author

zmou commented May 25, 2022

If possible, consider these non-standard formats.

@gouguoyin
Copy link
Member

Already under development, the next version will be compatible

@gouguoyin gouguoyin reopened this Oct 26, 2022
@gouguoyin
Copy link
Member

gouguoyin commented Oct 27, 2022

It has been fixed in 1.7.0 or 2.2.0

@gouguoyin gouguoyin added Optimization Streamline or optimize code and removed Question Indicates that an issue, pull request, or discussion needs more information labels Oct 28, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Optimization Streamline or optimize code
Development

No branches or pull requests

2 participants