diff --git a/docs/functions/formatDateTime.md b/docs/functions/formatDateTime.md new file mode 100644 index 0000000000..2e9a646f81 --- /dev/null +++ b/docs/functions/formatDateTime.md @@ -0,0 +1,49 @@ + + +```ts static +import { formatDateTime } from '@nextcloud/vue/functions/formatDateTime' +``` + +Format a `Date` object or a timestamp as a humanized string, also called relative time. +Examples of such strings: *"last year"*, *"in one month"*, *"3 hours ago"*. + +## Definitions + +```ts static +/** + * Format a given time as "relative time" also called "humanizing". + * + * @param timestamp Timestamp or Date object + * @param options Options for the formatting + */ +declare function formatDateTime( + timestamp: Date|number = Date.now(), + options: FormatDateOptions = {}, +): string; + +interface FormatDateOptions { + /** + * Ignore seconds when displaying the relative time and just show `a few seconds ago`. + * + * @default false + */ + ignoreSeconds?: boolean + + /** + * The relative time formatting option to use. + * + * @default 'long + */ + relativeTime?: 'long' | 'short' | 'narrow' + + /** + * Language to use. + * + * @default 'current language' + */ + language?: string +} +``` diff --git a/src/components/NcDateTime/NcDateTime.vue b/src/components/NcDateTime/NcDateTime.vue index a73aeef80a..c7b1c12cf9 100644 --- a/src/components/NcDateTime/NcDateTime.vue +++ b/src/components/NcDateTime/NcDateTime.vue @@ -98,7 +98,7 @@ h4 {