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

"toString" format not working properly with 12 hour clock #155

Closed
TadeasKriz opened this issue Feb 3, 2016 · 11 comments
Closed

"toString" format not working properly with 12 hour clock #155

TadeasKriz opened this issue Feb 3, 2016 · 11 comments
Labels

Comments

@TadeasKriz
Copy link

I have a date 2016-02-06 18:39:00 UTC (in variable date). When I do date.inRegion().toISO8601String(), I get the correct output: 2016-02-06T18:39:00.000Z. But when I do simply: date.toString(.ISO8601), what I get is something unexpected and possibly a wrong value: 2016-02-06T7:39:00+0100. Am I using it wrongly or is it a bug? Thanks.

@Hout Hout added the bug label Feb 4, 2016
@Hout
Copy link
Contributor

Hout commented Feb 4, 2016

Good find!
NSDate and DateInRegion should behave the same in the default region. Hence this is a bug.

@netgfx
Copy link

netgfx commented Feb 5, 2016

let d = data.toDate(DateFormat.Custom("MM/dd/yyyy")) // "2016-02-02 18:00:29" 

this syntax returns nil

Is this the same bug or related?

@malcommac
Copy link
Owner

You have provided the wrong format according to your date string in the comment.

@netgfx
Copy link

netgfx commented Feb 5, 2016

So to get this straight, the DateFormat should match the date string provided?

I thought it was the format based on which the Date is returned.
So how can I know which dateformat to use?

@Hout
Copy link
Contributor

Hout commented Feb 6, 2016

The toDate function needs a lead to know which characters in the string represent which data. Different countries and different programmers use different date formats. E.g. "11-12-13" could mean 11 December 2013, 13 December 2011 or 12 November 2013...

@Hout
Copy link
Contributor

Hout commented Feb 6, 2016

@netgfx coming back to your question: you must know the date format of the string you provide before passing it on. How you obtain that is your challenge.

@netgfx
Copy link

netgfx commented Feb 6, 2016

Yes I understand now and I was able to convert the given date to a custom formatted one.
Thanks for clarifying things.

@Hout Hout closed this as completed Feb 6, 2016
@Hout
Copy link
Contributor

Hout commented Feb 6, 2016

Woops reopened since the original bug with ISO8601 date formatting in the default region is still prevailing.

@Hout Hout reopened this Feb 6, 2016
@malcommac
Copy link
Owner

I think we should reuse same function to express same features. In this way toISO8601String() is simply a shortcut for toString(.ISO8601).
So this commit (now in a separate feature) will accomplish this task: 165309f.
Any cons?

@Hout
Copy link
Contributor

Hout commented Feb 15, 2016

I think we should consolidate to a minimum number of functions that describe the function of the function. In this case I would vote for the toString(style) format and deprecate the toStyleString() format. The former is more flexible.

@malcommac
Copy link
Owner

Totally agree. It now uses toString(.ISO8601) format but it's marked as deprecated. 9451ed3

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants