Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.

Date filter can't format date/time with newlines #15794

Closed
ashsearle opened this issue Mar 10, 2017 · 6 comments
Closed

Date filter can't format date/time with newlines #15794

ashsearle opened this issue Mar 10, 2017 · 6 comments

Comments

@ashsearle
Copy link
Contributor

Do you want to request a feature or report a bug?
Bug

What is the current behavior?
Using a date format containing a newline is treated as though the format ended at the newline.
i.e. | date: 'dd MMM\nyyyy' is treated as though it were | date: 'dd MMM'

Plunkers: Angular 1.5.10, Angular 1.6.3, Angular 2.unknown

What is the expected behavior?
The format string should be processed in its entirety.

What is the motivation / use case for changing the behavior?
A UI design required a timestamp to be formatted with date and time separated by a newline. This should be as simple as | date: 'yyyy-MM-dd\nHH:mm' (assuming an appropriate CSS white-space value.)

Which versions of AngularJS, and which browser / OS are affected by this issue? Did this work in previous versions of AngularJS? Please also test with the latest stable and snapshot (https://code.angularjs.org/snapshot/) versions.
Appears to affect all versions of since at least March 2012, including angular 2

Other information (e.g. stacktraces, related issues, suggestions how to fix)
Fix in pull request #15792

@Narretz
Copy link
Contributor

Narretz commented Mar 11, 2017

I see this more as a feature to be honest. And the workaround you posted is not that bad. But since the change is simple ... let's see what others say.

@ashsearle
Copy link
Contributor Author

I'd argue it's a bug as you can't even embed newlines using escapes. Documentation doesn't mention this limitation:

format string can contain literal values. These need to be escaped by surrounding with single quotes (e.g. "h 'in the morning'").

I don't see why "h 'in the\nmorning'" shouldn't be expected to work.

(Incidentally, while trying alternative escape sequences like \u000a, I found modern unicode escape syntax like \u{0a} breaks horribly... Angular does not like that at all...)

@frederikprijck
Copy link
Contributor

frederikprijck commented Mar 11, 2017

I'd say it's a feature and not a bug, as docs clearly state:

format string can be composed of the following elements:

followed by a list which does not include what you're talking about (no it doesn't mention a limitation, but it explicitly lists what you can use).

Leaving this aside, I wouldn't say it hurts adding this even though I'd think the use-cases for this are limited.

@ashsearle
Copy link
Contributor Author

ashsearle commented Mar 12, 2017

A little further investigation: newlines are handled in the first 'token' of the format string.

These work: | date: '\'Line 1\n\'yyyy' or even | date: '🤡\nyyyy'.
These don't: | date: 'yyyy\'\nLine 2\'' or even | date: 'yyyy\n🤡'.

Is that a feature, or is it a bug?

The docs are probably missing a description of how 'other characters' are handled (including characters actually used in the US-default date format strings: e.g. colons, commas, slashes, spaces etc.)

Perhaps the docs need to include this, as used in other libraries - for example:

PHP:

Unrecognized characters in the format string will be printed as-is

Or Java:

All other characters are not interpreted; they're simply copied into the output string during formatting...

@gkalpak
Copy link
Member

gkalpak commented Mar 12, 2017

I would say this is obviously a bug in the DATE_FORMATS_SPLIT RegExp (and #15792 looks like the correct fix).

Also, 👍 on updating the docs to mention that unrecognized characters are printed as-is (or something similar).

@Narretz
Copy link
Contributor

Narretz commented Mar 12, 2017

Ok, then let's go with the PR

ashsearle added a commit to ashsearle/angular.js that referenced this issue Mar 12, 2017
ashsearle added a commit to ashsearle/angular.js that referenced this issue Mar 12, 2017
ellimist pushed a commit to ellimist/angular.js that referenced this issue Mar 15, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

4 participants