-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improve documentation how to handle date times in the graylog fronten…
…d. (#17007) * Extend documentation for date time handling. * Use h2 instead of h3 for ux patterns headlines. * Move documentation into UserDateTimeProvider. * Add documentation for Timestamp component. * Extend documentation for date tiem utils and RelativeTime component. * Improve documentation for toUTCFromTz date time util. * Cleanup * Fix toUTCFromTz test.
- Loading branch information
Showing
11 changed files
with
106 additions
and
14 deletions.
There are no files selected for viewing
This file contains 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 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 |
---|---|---|
@@ -1,5 +1,20 @@ | ||
### Setting up keyboard shortcuts | ||
## Setting up keyboard shortcuts | ||
|
||
If you want to add a keyboard shortcut, you need to: | ||
- extend the `hotkeysCollections` in the `hotkeysProvider`. | ||
- call `useHotkey` hook in the place which provides the functionality you want to execute on keypress. | ||
|
||
## Handling date times | ||
|
||
When receiving or sending dates to the backend they are always in UTC and expressed according to ISO 8601, for example `2010-07-30T16:03:25.000Z`. | ||
This is also the preferred format to store date times in the state of, for example, UI components. | ||
|
||
When displaying date times in the UI they are always displayed in the user timezone. | ||
The [UserDateTimeProvider](https://github.com/Graylog2/graylog2-server/blob/master/graylog2-web-interface/src/contexts/UserDateTimeProvider.tsx) contains the related functionality | ||
and provides further information. It can be access using the [useUserDateTime](https://github.com/Graylog2/graylog2-server/blob/master/graylog2-web-interface/src/hooks/useUserDateTime.ts) hook. | ||
|
||
If you just want to display a date time, you can render the [Timestamp](#timestamp) component, which implements methods provided by the `useUserDateTime` hook. | ||
If you want to display the relative time in a human-readable format you can render the [RelativeTime](#relativetime) component. | ||
|
||
For all other cases where you need to transform a date time you can use the [DateTime](https://github.com/Graylog2/graylog2-server/blob/master/graylog2-web-interface/src/util/DateTime.ts) utils. | ||
Instead of using `moment` directly, use or (if necessary) extend the `DateTime` utils. It makes it easier to replace moment with an alternative. |
This file contains 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 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,5 @@ | ||
Relative time since `2010-07-30T16:03:25.000Z`. | ||
|
||
```tsx | ||
<RelativeTime dateTime="2010-07-30T16:03:25.000Z" /> | ||
``` |
This file contains 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 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,38 @@ | ||
For the following examples we are using the date time `2010-07-30T16:03:25.000Z`. | ||
By default, the output will be based on the user time zone defined for the style guide. | ||
|
||
#### Default | ||
|
||
The component displays the date time in the default format for date times in the graylog UI, when no format is specified. | ||
|
||
```tsx | ||
<Timestamp dateTime="2010-07-30T16:03:25.000Z" /> | ||
``` | ||
|
||
#### Specific timezone | ||
|
||
In this example we are displaying the provided time as UTC. | ||
|
||
```tsx | ||
<Timestamp dateTime="2010-07-30T16:03:25.000Z" tz="UTC" /> | ||
``` | ||
|
||
#### Different formats | ||
|
||
```tsx | ||
import { DATE_TIME_FORMATS } from 'util/DateTime'; | ||
|
||
|
||
<table cellPadding="10"> | ||
<tr> | ||
<th style={{ width: '150px' }}>Format</th> | ||
<th>Output</th> | ||
</tr> | ||
{Object.keys(DATE_TIME_FORMATS).map((format) => ( | ||
<tr> | ||
<td>{format}</td> | ||
<td><Timestamp dateTime="2010-07-30T16:03:25.000Z" format={format}/></td> | ||
</tr> | ||
))} | ||
</table> | ||
``` |
This file contains 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 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 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 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 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