-
-
Notifications
You must be signed in to change notification settings - Fork 690
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
Allow escaping of characters in format() #35
Comments
Interesting. This will be a little more than a quick fix, as I'll have to move a little bit more formatting logic into the locale itself. Should be straightforward, though. |
This sounds like a useful feature. Is using a |
Hi Ben,
moment().format('[today] DDDD'); // 'today Sunday' I think it will be a better idea, it's safer and easy to remember. |
That definitely looks more convenient for escaping long strings (compare with If you guys are OK with this (stylistically), then I'll go ahead and add some documentation and tests and submit a pull request. NOTE: I've also removed an accidental duplicate line from the parser. |
This seems to be the right approach in general (using square brackets). The implementation in moment.js (https://github.com/moment/moment/blob/develop/moment.js#L29) is similar, and looks sane to me. I'll probably tweak / test the regex a bit on merge to make sure it's as efficient as possible. |
That's interesting. I hadn't thought to look at the moment.js implementation, but upon inspection it looks like their regex doesn't allow for literal brackets within an escaped sequence. The regex in the commit I've linked to does so, and without exponential backtracking. We may or may not want to refine it to make sure that it's not doing superfluous checks though. I don't really know what nesting and literal |
👍 |
Got the same problem today, and had to to d.datetime.strftime. Which sucked cause it doesn't handle unicode properly in 2.7. BTW, why do we have different operators to format with arrow and datetime ? It should be the same. %stuff works well, and identify easily what's marker and what's not. |
Same issue here - I'd like to format as "[date] at [time]", e.g. "Fri 01 May 2015 �at 16:32", but the 'a' gets translated into AM/PM. |
👍 for square bracket support. |
I like the bracket approach. I don't have time at the moment to make the PR for it though, does anyone else. I'd happily review and merge a PR with this. |
👍 |
1 similar comment
👍 |
I wouldn't mind throwing a |
👍 this would be amazing |
👍 |
1 similar comment
👍 |
Time to tackle this one 👍 |
Seems like #290 could be used to help with this process. |
This now basically works for parsing but not for formatting. Python 3.6.7 (default, Oct 25 2018, 09:16:13)
[GCC 5.4.0 20160609] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import arrow
>>> date_format = "YYYY-MM-DD h [h] m"
>>> my_date = "2018-03-09 8 h 40"
>>> arw=arrow.get(my_date, date_format)
<Arrow [2018-03-09T08:40:00+00:00]>
>>> arw.format(date_format)
'2018-03-09 8 [8] 40' But it's not documented anywhere on https://arrow.readthedocs.io/en/latest/ so that needs to be fixed. EDIT: updated that this does not working for formatting. |
In French, hours are formatted as "8 h 40" and not as "8:40". But in an arrow's format string, h displays directly the hours. Would it be possible to add a key (such as !) to force h to be displayed normally ("hh !h mm")?
The text was updated successfully, but these errors were encountered: