@box/readable-time 1.39.52
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +379 -0
- package/README.md +129 -0
- package/dist/esm/index.js +3 -0
- package/dist/esm/lib/__tests__/testfiles/i18n/ja-JP.js +9 -0
- package/dist/esm/lib/__tests__/testfiles/i18n/ru-RU.js +9 -0
- package/dist/esm/lib/constants.js +2 -0
- package/dist/esm/lib/get-readable-time.js +33 -0
- package/dist/esm/lib/messages.js +28 -0
- package/dist/esm/lib/readable-time.js +21 -0
- package/dist/esm/lib/utils.js +24 -0
- package/dist/i18n/bn-IN.js +8 -0
- package/dist/i18n/bn-IN.properties +12 -0
- package/dist/i18n/da-DK.js +8 -0
- package/dist/i18n/da-DK.properties +12 -0
- package/dist/i18n/de-DE.js +8 -0
- package/dist/i18n/de-DE.properties +12 -0
- package/dist/i18n/en-AU.js +8 -0
- package/dist/i18n/en-AU.properties +12 -0
- package/dist/i18n/en-CA.js +8 -0
- package/dist/i18n/en-CA.properties +12 -0
- package/dist/i18n/en-GB.js +8 -0
- package/dist/i18n/en-GB.properties +12 -0
- package/dist/i18n/en-US.js +8 -0
- package/dist/i18n/en-US.properties +12 -0
- package/dist/i18n/en-x-pseudo.js +8 -0
- package/dist/i18n/en-x-pseudo.properties +12 -0
- package/dist/i18n/es-419.js +8 -0
- package/dist/i18n/es-419.properties +12 -0
- package/dist/i18n/es-ES.js +8 -0
- package/dist/i18n/es-ES.properties +12 -0
- package/dist/i18n/fi-FI.js +8 -0
- package/dist/i18n/fi-FI.properties +12 -0
- package/dist/i18n/fr-CA.js +8 -0
- package/dist/i18n/fr-CA.properties +12 -0
- package/dist/i18n/fr-FR.js +8 -0
- package/dist/i18n/fr-FR.properties +12 -0
- package/dist/i18n/hi-IN.js +8 -0
- package/dist/i18n/hi-IN.properties +12 -0
- package/dist/i18n/it-IT.js +8 -0
- package/dist/i18n/it-IT.properties +12 -0
- package/dist/i18n/ja-JP.js +8 -0
- package/dist/i18n/ja-JP.properties +12 -0
- package/dist/i18n/json/src/lib/messages.json +1 -0
- package/dist/i18n/ko-KR.js +8 -0
- package/dist/i18n/ko-KR.properties +12 -0
- package/dist/i18n/nb-NO.js +8 -0
- package/dist/i18n/nb-NO.properties +12 -0
- package/dist/i18n/nl-NL.js +8 -0
- package/dist/i18n/nl-NL.properties +12 -0
- package/dist/i18n/pl-PL.js +8 -0
- package/dist/i18n/pl-PL.properties +12 -0
- package/dist/i18n/pt-BR.js +8 -0
- package/dist/i18n/pt-BR.properties +12 -0
- package/dist/i18n/ru-RU.js +8 -0
- package/dist/i18n/ru-RU.properties +12 -0
- package/dist/i18n/sv-SE.js +8 -0
- package/dist/i18n/sv-SE.properties +12 -0
- package/dist/i18n/tr-TR.js +8 -0
- package/dist/i18n/tr-TR.properties +12 -0
- package/dist/i18n/zh-CN.js +8 -0
- package/dist/i18n/zh-CN.properties +12 -0
- package/dist/i18n/zh-TW.js +8 -0
- package/dist/i18n/zh-TW.properties +12 -0
- package/dist/types/index.d.ts +2 -0
- package/dist/types/lib/__tests__/testfiles/i18n/ja-JP.d.ts +9 -0
- package/dist/types/lib/__tests__/testfiles/i18n/ru-RU.d.ts +9 -0
- package/dist/types/lib/constants.d.ts +9 -0
- package/dist/types/lib/get-readable-time.d.ts +15 -0
- package/dist/types/lib/messages.d.ts +33 -0
- package/dist/types/lib/readable-time.d.ts +39 -0
- package/dist/types/lib/stories/tests/story-grid.d.ts +23 -0
- package/dist/types/lib/utils.d.ts +10 -0
- package/package.json +47 -0
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
# The time that an event occurred
|
|
2
|
+
groupSharedFeatures.readableTime.eventTime = {time, date, medium}
|
|
3
|
+
# The time that an event occurred at a given date with the year included
|
|
4
|
+
groupSharedFeatures.readableTime.eventTimeDate = {time, date, medium} {time, time, short}
|
|
5
|
+
# The time that an event occurred at a given date without the year included
|
|
6
|
+
groupSharedFeatures.readableTime.eventTimeDateShort = {date} {time, time, short}
|
|
7
|
+
# The time that an event occurred today
|
|
8
|
+
groupSharedFeatures.readableTime.eventTimeToday = 今天 {time, time, short}
|
|
9
|
+
# The time that an event occurred at a given date with the weekday included
|
|
10
|
+
groupSharedFeatures.readableTime.eventTimeWeekdayLong = {weekday} {time, date, medium}
|
|
11
|
+
# The time that an event occurred yesterday
|
|
12
|
+
groupSharedFeatures.readableTime.eventTimeYesterday = 昨天 {time, time, short}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
declare const _default: {
|
|
2
|
+
'groupSharedFeatures.readableTime.eventTime': string;
|
|
3
|
+
'groupSharedFeatures.readableTime.eventTimeDate': string;
|
|
4
|
+
'groupSharedFeatures.readableTime.eventTimeDateShort': string;
|
|
5
|
+
'groupSharedFeatures.readableTime.eventTimeToday': string;
|
|
6
|
+
'groupSharedFeatures.readableTime.eventTimeWeekdayLong': string;
|
|
7
|
+
'groupSharedFeatures.readableTime.eventTimeYesterday': string;
|
|
8
|
+
};
|
|
9
|
+
export default _default;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
declare const _default: {
|
|
2
|
+
'groupSharedFeatures.readableTime.eventTime': string;
|
|
3
|
+
'groupSharedFeatures.readableTime.eventTimeDate': string;
|
|
4
|
+
'groupSharedFeatures.readableTime.eventTimeDateShort': string;
|
|
5
|
+
'groupSharedFeatures.readableTime.eventTimeToday': string;
|
|
6
|
+
'groupSharedFeatures.readableTime.eventTimeWeekdayLong': string;
|
|
7
|
+
'groupSharedFeatures.readableTime.eventTimeYesterday': string;
|
|
8
|
+
};
|
|
9
|
+
export default _default;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Represents the number of milliseconds in one hour.
|
|
3
|
+
* 60 * 60 * 1000
|
|
4
|
+
*/
|
|
5
|
+
export declare const ONE_HOUR_MS = 3600000;
|
|
6
|
+
/**
|
|
7
|
+
* A list of languages that do not have a grammar for uppercase (e.g., Russian)
|
|
8
|
+
*/
|
|
9
|
+
export declare const nonUppercaseLocales: string[];
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { useIntl } from 'react-intl';
|
|
2
|
+
import { ReadableTimeProps } from './readable-time';
|
|
3
|
+
/**
|
|
4
|
+
* Extending ReadableTimeProps with intl object.
|
|
5
|
+
*/
|
|
6
|
+
export interface GetReadableTimeArgs extends ReadableTimeProps {
|
|
7
|
+
/**
|
|
8
|
+
* Internationalization (intl) object for locale-based formatting.
|
|
9
|
+
*/
|
|
10
|
+
intl: ReturnType<typeof useIntl>;
|
|
11
|
+
}
|
|
12
|
+
export interface GetReadableTime {
|
|
13
|
+
(args: GetReadableTimeArgs): string;
|
|
14
|
+
}
|
|
15
|
+
export declare function getReadableTime({ intl, timestamp, allowFutureTimestamps, alwaysShowTime, showWeekday, relativeThreshold, uppercase, }: GetReadableTimeArgs): string;
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
declare const messages: {
|
|
2
|
+
eventTime: {
|
|
3
|
+
defaultMessage: string;
|
|
4
|
+
description: string;
|
|
5
|
+
id: string;
|
|
6
|
+
};
|
|
7
|
+
eventTimeToday: {
|
|
8
|
+
defaultMessage: string;
|
|
9
|
+
description: string;
|
|
10
|
+
id: string;
|
|
11
|
+
};
|
|
12
|
+
eventTimeYesterday: {
|
|
13
|
+
defaultMessage: string;
|
|
14
|
+
description: string;
|
|
15
|
+
id: string;
|
|
16
|
+
};
|
|
17
|
+
eventTimeDate: {
|
|
18
|
+
defaultMessage: string;
|
|
19
|
+
description: string;
|
|
20
|
+
id: string;
|
|
21
|
+
};
|
|
22
|
+
eventTimeDateShort: {
|
|
23
|
+
defaultMessage: string;
|
|
24
|
+
description: string;
|
|
25
|
+
id: string;
|
|
26
|
+
};
|
|
27
|
+
eventTimeWeekdayLong: {
|
|
28
|
+
defaultMessage: string;
|
|
29
|
+
description: string;
|
|
30
|
+
id: string;
|
|
31
|
+
};
|
|
32
|
+
};
|
|
33
|
+
export default messages;
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { TextProps } from '@box/blueprint-web';
|
|
2
|
+
export interface ReadableTimeProps {
|
|
3
|
+
/**
|
|
4
|
+
* The timestamp to be used for displaying the date.
|
|
5
|
+
*/
|
|
6
|
+
timestamp: number;
|
|
7
|
+
/**
|
|
8
|
+
* If true, future timestamps (typically caused by incorrect operating system time) will be corrected to show the 'isToday' message.
|
|
9
|
+
* @default true
|
|
10
|
+
*/
|
|
11
|
+
allowFutureTimestamps?: boolean;
|
|
12
|
+
/**
|
|
13
|
+
* If true, the time will be displayed alongside the date (if the date is shown).
|
|
14
|
+
* @default false
|
|
15
|
+
*/
|
|
16
|
+
alwaysShowTime?: boolean;
|
|
17
|
+
/**
|
|
18
|
+
* If true, the weekday will be displayed alongside the date (if the date is shown).
|
|
19
|
+
* @default false
|
|
20
|
+
*/
|
|
21
|
+
showWeekday?: boolean;
|
|
22
|
+
/**
|
|
23
|
+
* The threshold (in milliseconds) before which a relative time (rather than an absolute time) will be shown.
|
|
24
|
+
* Default is 1 hour.
|
|
25
|
+
* @default ONE_HOUR_MS
|
|
26
|
+
*/
|
|
27
|
+
relativeThreshold?: number;
|
|
28
|
+
/**
|
|
29
|
+
* If true, the generated string will be uppercase and locale-aware.
|
|
30
|
+
* @default false
|
|
31
|
+
*/
|
|
32
|
+
uppercase?: boolean;
|
|
33
|
+
/**
|
|
34
|
+
* Props for the underlying Text component.
|
|
35
|
+
* @default {}
|
|
36
|
+
*/
|
|
37
|
+
textProps?: TextProps;
|
|
38
|
+
}
|
|
39
|
+
export declare function ReadableTime({ timestamp, allowFutureTimestamps, alwaysShowTime, showWeekday, relativeThreshold, uppercase, textProps, }: ReadableTimeProps): import("react/jsx-runtime").JSX.Element;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { ReadableTimeProps } from '../../readable-time';
|
|
2
|
+
interface StoryGridProps {
|
|
3
|
+
children: React.ReactNode;
|
|
4
|
+
rows: number;
|
|
5
|
+
columns: number;
|
|
6
|
+
}
|
|
7
|
+
export declare function StoryGrid({ children, rows, columns }: StoryGridProps): import("react/jsx-runtime").JSX.Element;
|
|
8
|
+
interface Column {
|
|
9
|
+
name: string;
|
|
10
|
+
props?: Partial<ReadableTimeProps>;
|
|
11
|
+
}
|
|
12
|
+
interface HeaderProps {
|
|
13
|
+
columns: Column[];
|
|
14
|
+
}
|
|
15
|
+
export declare function Header({ columns }: HeaderProps): import("react/jsx-runtime").JSX.Element;
|
|
16
|
+
interface RowProps {
|
|
17
|
+
now: number;
|
|
18
|
+
title: string;
|
|
19
|
+
offset: number;
|
|
20
|
+
columns: Column[];
|
|
21
|
+
}
|
|
22
|
+
export declare function Row({ now, title, offset, columns }: RowProps): import("react/jsx-runtime").JSX.Element;
|
|
23
|
+
export {};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
interface TimeFromNowResult {
|
|
2
|
+
value: number;
|
|
3
|
+
unit: 'year' | 'week' | 'day' | 'hour' | 'minute' | 'second';
|
|
4
|
+
}
|
|
5
|
+
type DateValue = Date | number | string;
|
|
6
|
+
export declare const isCurrentYear: (dateValue: DateValue) => boolean;
|
|
7
|
+
export declare const isToday: (dateValue: DateValue) => boolean;
|
|
8
|
+
export declare const isYesterday: (dateValue: DateValue) => boolean;
|
|
9
|
+
export declare function timeFromNow(ms: number): TimeFromNowResult;
|
|
10
|
+
export {};
|
package/package.json
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@box/readable-time",
|
|
3
|
+
"version": "1.39.52",
|
|
4
|
+
"license": "SEE LICENSE IN LICENSE",
|
|
5
|
+
"peerDependencies": {
|
|
6
|
+
"@box/blueprint-web": "^14.12.2",
|
|
7
|
+
"@box/blueprint-web-assets": "^4.114.3",
|
|
8
|
+
"react": "^18.0.0",
|
|
9
|
+
"react-dom": "^18.0.0",
|
|
10
|
+
"react-intl": "^6.4.2"
|
|
11
|
+
},
|
|
12
|
+
"publishConfig": {
|
|
13
|
+
"access": "public"
|
|
14
|
+
},
|
|
15
|
+
"devDependencies": {
|
|
16
|
+
"@box/blueprint-web": "^14.12.2",
|
|
17
|
+
"@box/blueprint-web-assets": "^4.114.3",
|
|
18
|
+
"@box/eslint-plugin-blueprint": "1.1.17",
|
|
19
|
+
"@box/storybook-utils": "0.17.45",
|
|
20
|
+
"react-intl": "^6.4.2"
|
|
21
|
+
},
|
|
22
|
+
"files": [
|
|
23
|
+
"dist"
|
|
24
|
+
],
|
|
25
|
+
"main": "./dist/esm/index.js",
|
|
26
|
+
"module": "./dist/esm/index.js",
|
|
27
|
+
"types": "./dist/types/index.d.ts",
|
|
28
|
+
"exports": {
|
|
29
|
+
".": {
|
|
30
|
+
"require": "./dist/esm/index.js",
|
|
31
|
+
"import": "./dist/esm/index.js",
|
|
32
|
+
"types": "./dist/types/index.d.ts"
|
|
33
|
+
},
|
|
34
|
+
"./*": {
|
|
35
|
+
"require": "./dist/esm/*",
|
|
36
|
+
"import": "./dist/esm/*",
|
|
37
|
+
"types": "./dist/types/*"
|
|
38
|
+
},
|
|
39
|
+
"./i18n/*": {
|
|
40
|
+
"require": "./dist/i18n/*",
|
|
41
|
+
"import": "./dist/i18n/*"
|
|
42
|
+
}
|
|
43
|
+
},
|
|
44
|
+
"sideEffects": [
|
|
45
|
+
"**/*.css"
|
|
46
|
+
]
|
|
47
|
+
}
|