Skip to content

Commit

Permalink
Cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
linuspahl committed Oct 19, 2023
1 parent 428f6ec commit c3227ce
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 32 deletions.
4 changes: 2 additions & 2 deletions graylog2-web-interface/src/contexts/UserDateTimeProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,9 @@ const getUserTimezone = (userTimezone: string, tzOverride?: string) => {
* Should be used when displaying times and the related components are not a suitable option.
*
* userTimezone - time zone of the current user.
* formatTime - method which takes a date and optionally a format and returns it as a string in the current user time zone.
* formatTime - method which takes a date and optionally a format and returns it as a string in the current user timezone.
* For example, it transforms `2010-07-30T16:03:25.000Z` to `2010-07-30 17:03:25` for a user with the timezone `Europe/Berlin`.
* toUserTimezone - method which takes a date and transforms it a date object, based on the user time zone.
* toUserTimezone - method which takes a date and transforms it a moment date object, based on the user timezone.
*/

const StaticTimezoneProvider = ({ children, tz }: Required<Props>) => {
Expand Down
24 changes: 0 additions & 24 deletions graylog2-web-interface/src/hooks/useUserDateTime.md

This file was deleted.

13 changes: 7 additions & 6 deletions graylog2-web-interface/src/util/DateTime.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ const getFormatStringsForDateTimeFormats = (dateTimeFormats: Array<DateTimeForma
});

/**
* Takes a date and returns is as a moment object. Optionally you can define a time zone, which will be considered when printing out the date.
* Takes a date and returns it as a moment object. Optionally you can define a time zone, which will be considered when displaying the date.
* You can also define `acceptedFormats` in case you want to throw an error if the provided date does not match an expected format.
*/
export const toDateObject = (dateTime: DateTime, acceptedFormats?: Array<DateTimeFormats>, tz = DEFAULT_OUTPUT_TZ) => {
Expand All @@ -75,7 +75,7 @@ export const toDateObject = (dateTime: DateTime, acceptedFormats?: Array<DateTim
};

/**
* Transforms an ISO 8601 date time to a moment date object. It throws an error is the provided date time is not expressed according to ISO 8601.
* Transforms an ISO 8601 date time to a moment date object. It throws an error if the provided date time is not expressed according to ISO 8601.
*/
export const parseFromIsoString = (dateTimeString: string, tz = DEFAULT_OUTPUT_TZ) => toDateObject(dateTimeString, ['internal'], tz);

Expand All @@ -95,8 +95,8 @@ export const adjustFormat = (dateTime: DateTime, format: DateTimeFormats = 'defa
export const formatAsBrowserTime = (time: DateTime, format: DateTimeFormats = 'default') => adjustFormat(time, format, getBrowserTimezone());

/**
* Returns the relative time in a human-readable format for the provided date time.
* If you just want to display output, you can use the `RelativeTime` component.
* Returns the time in a human-readable format, relative to the provided date time.
* If you just want to display the output, you can use the `RelativeTime` component.
*/
export const relativeDifference = (dateTime: DateTime) => {
const dateObject = toDateObject(dateTime);
Expand All @@ -110,8 +110,9 @@ export const relativeDifference = (dateTime: DateTime) => {
export const isValidDate = (dateTime: DateTime) => moment(dateTime, Object.values(DATE_TIME_FORMATS), true).isValid();

/**
* This function allows defining a timezone a date time, which does not contain a time zone like `2010-01-01 10:00:00`, to UTC.
* For this calculation it is necessary to define the time zone of the provided date time.
* This function transforms the provided date time to UTC, based on the defined time zone.
* This is useful for date times like `2010-01-01 10:00:00`, which do not include the timezone information.
* For this calculation it is necessary to define the timezone which the date time is currently based on.
*/
export const toUTCFromTz = (dateTime: string, sourceTimezone: string) => {
if (!sourceTimezone) {
Expand Down

0 comments on commit c3227ce

Please sign in to comment.