-
Notifications
You must be signed in to change notification settings - Fork 3.6k
Detect and format timestamp attributes #9074
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
Merged
spacegaier
merged 12 commits into
home-assistant:dev
from
spacegaier:attr-timestamp-formatting
May 25, 2021
Merged
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
dde40c1
Detect and format timestamp attributes
spacegaier 1a7e673
Move RegExp out of function
spacegaier 5932c97
RegExp optimizations
spacegaier 1fe7115
RegExp fix in case of multi-lines
spacegaier 870019b
Added date attribute formatting + streamline RegExp for timestamp
spacegaier 20cce7f
Merge branch 'dev' into attr-timestamp-formatting
spacegaier 6043dc0
Optimize RegExp handling + use formatting for entity rows + entity card
spacegaier 18be384
Update src/panels/lovelace/special-rows/hui-attribute-row.ts
spacegaier cb6b0f4
Merge branch 'dev' of https://github.com/home-assistant/frontend into…
spacegaier d039ba0
Update src/common/string/is_date.ts
spacegaier 5f357c5
Fix RegExp + add test
spacegaier efd344c
Change to trigger the prettier
spacegaier File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| // https://regex101.com/r/kc5C14/2 | ||
| const regExpString = "^\\d{4}-(0[1-9]|1[0-2])-([12]\\d|0[1-9]|3[01])"; | ||
|
|
||
| const regExp = new RegExp(regExpString + "$"); | ||
| // 2nd expression without the "end of string" enforced, so it can be used | ||
| // to just verify the start of a string and then based on that result e.g. | ||
| // check for a full timestamp string efficiently. | ||
| const regExpNoStringEnd = new RegExp(regExpString); | ||
|
|
||
| export const isDate = (input: string, allowCharsAfterDate = false): boolean => | ||
| allowCharsAfterDate ? regExpNoStringEnd.test(input) : regExp.test(input); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| // https://stackoverflow.com/a/14322189/1947205 | ||
| // Changes: | ||
| // 1. Do not allow a plus or minus at the start. | ||
| // 2. Enforce that we have a "T" or a blank after the date portion | ||
| // to ensure we have a timestamp and not only a date. | ||
| // 3. Disallow dates based on week number. | ||
| // 4. Disallow dates only consisting of a year. | ||
| // https://regex101.com/r/kc5C14/3 | ||
| const regexp = /^\d{4}-(0[1-9]|1[0-2])-([12]\d|0[1-9]|3[01])[T| ](((([01]\d|2[0-3])((:?)[0-5]\d)?|24:?00)([.,]\d+(?!:))?)(\8[0-5]\d([.,]\d+)?)?([zZ]|([+-])([01]\d|2[0-3]):?([0-5]\d)?)?)$/; | ||
|
|
||
| export const isTimestamp = (input: string): boolean => regexp.test(input); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| import { assert } from "chai"; | ||
| import { isDate } from "../../../src/common/string/is_date"; | ||
|
|
||
| describe("isDate", () => { | ||
| assert.strictEqual(isDate("ABC"), false); | ||
|
|
||
| assert.strictEqual(isDate("2021-02-03", false), true); | ||
| assert.strictEqual(isDate("2021-02-03", true), true); | ||
|
|
||
| assert.strictEqual(isDate("2021-05-25T19:23:52+00:00", true), true); | ||
| assert.strictEqual(isDate("2021-05-25T19:23:52+00:00", false), false); | ||
| }); |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.