@instructure/ui-i18n 8.11.2-snapshot.41 → 8.11.2-snapshot.44
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/es/DateTime.js +37 -2
- package/lib/DateTime.js +37 -2
- package/package.json +10 -10
- package/src/DateTime.ts +35 -3
- package/src/index.ts +1 -0
- package/types/DateTime.d.ts +21 -2
- package/types/DateTime.d.ts.map +1 -1
- package/types/index.d.ts +1 -0
- package/types/index.d.ts.map +1 -1
package/es/DateTime.js
CHANGED
|
@@ -27,7 +27,8 @@ import moment from 'moment-timezone';
|
|
|
27
27
|
* category: utilities/i18n
|
|
28
28
|
* ---
|
|
29
29
|
* @deprecated
|
|
30
|
-
*
|
|
30
|
+
* #### DEPRECATION WARNING: Will be removed in v9, which wil include a
|
|
31
|
+
* time library agnostic API.
|
|
31
32
|
* A wrapper for [moment](https://momentjs.com/) utils.
|
|
32
33
|
* @module DateTime
|
|
33
34
|
*/
|
|
@@ -79,6 +80,38 @@ function isValid(dateString) {
|
|
|
79
80
|
function browserTimeZone() {
|
|
80
81
|
return moment.tz.guess();
|
|
81
82
|
}
|
|
83
|
+
/**
|
|
84
|
+
* Returns the days of the week in the given locale,
|
|
85
|
+
* for example ["Monday", "Tuesday",..]. It always begins with Monday.
|
|
86
|
+
* @param locale A locale accepted by the browser, e.g. America/New_York
|
|
87
|
+
* @param format If set to 'short' it will be maximum 3 letters long,
|
|
88
|
+
* if set to 'long' it will be the full word.
|
|
89
|
+
*/
|
|
90
|
+
|
|
91
|
+
|
|
92
|
+
function getLocalDayNamesOfTheWeek(locale, format) {
|
|
93
|
+
const ret = [];
|
|
94
|
+
const toFormat = format === 'short' ? 'dd' : 'dddd';
|
|
95
|
+
let currentDay = getFirstDayOfWeek(now(locale, browserTimeZone()));
|
|
96
|
+
|
|
97
|
+
for (let i = 0; i < 7; i++) {
|
|
98
|
+
ret.push(currentDay.format(toFormat));
|
|
99
|
+
currentDay = currentDay.add(1, 'day'); // TODO this is mutable
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
return ret;
|
|
103
|
+
}
|
|
104
|
+
/**
|
|
105
|
+
* Returns the first day of the week in the given locale.
|
|
106
|
+
* The locale decides what is the first day, e.g. Sunday in the US, Monday in
|
|
107
|
+
* the EU.
|
|
108
|
+
* @param date A Moment Datetime object
|
|
109
|
+
*/
|
|
110
|
+
|
|
111
|
+
|
|
112
|
+
function getFirstDayOfWeek(date) {
|
|
113
|
+
return date.clone().weekday(0);
|
|
114
|
+
}
|
|
82
115
|
/**
|
|
83
116
|
* Return a localized date + time with timezone as a ISO 8601 string
|
|
84
117
|
* @param {String} dateString
|
|
@@ -105,7 +138,9 @@ const DateTime = {
|
|
|
105
138
|
parse,
|
|
106
139
|
browserTimeZone,
|
|
107
140
|
isValid,
|
|
108
|
-
toLocaleString
|
|
141
|
+
toLocaleString,
|
|
142
|
+
getFirstDayOfWeek,
|
|
143
|
+
getLocalDayNamesOfTheWeek
|
|
109
144
|
};
|
|
110
145
|
export default DateTime;
|
|
111
146
|
export { DateTime };
|
package/lib/DateTime.js
CHANGED
|
@@ -38,7 +38,8 @@ var _momentTimezone = _interopRequireDefault(require("moment-timezone"));
|
|
|
38
38
|
* category: utilities/i18n
|
|
39
39
|
* ---
|
|
40
40
|
* @deprecated
|
|
41
|
-
*
|
|
41
|
+
* #### DEPRECATION WARNING: Will be removed in v9, which wil include a
|
|
42
|
+
* time library agnostic API.
|
|
42
43
|
* A wrapper for [moment](https://momentjs.com/) utils.
|
|
43
44
|
* @module DateTime
|
|
44
45
|
*/
|
|
@@ -89,6 +90,38 @@ function isValid(dateString) {
|
|
|
89
90
|
function browserTimeZone() {
|
|
90
91
|
return _momentTimezone.default.tz.guess();
|
|
91
92
|
}
|
|
93
|
+
/**
|
|
94
|
+
* Returns the days of the week in the given locale,
|
|
95
|
+
* for example ["Monday", "Tuesday",..]. It always begins with Monday.
|
|
96
|
+
* @param locale A locale accepted by the browser, e.g. America/New_York
|
|
97
|
+
* @param format If set to 'short' it will be maximum 3 letters long,
|
|
98
|
+
* if set to 'long' it will be the full word.
|
|
99
|
+
*/
|
|
100
|
+
|
|
101
|
+
|
|
102
|
+
function getLocalDayNamesOfTheWeek(locale, format) {
|
|
103
|
+
const ret = [];
|
|
104
|
+
const toFormat = format === 'short' ? 'dd' : 'dddd';
|
|
105
|
+
let currentDay = getFirstDayOfWeek(now(locale, browserTimeZone()));
|
|
106
|
+
|
|
107
|
+
for (let i = 0; i < 7; i++) {
|
|
108
|
+
ret.push(currentDay.format(toFormat));
|
|
109
|
+
currentDay = currentDay.add(1, 'day'); // TODO this is mutable
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
return ret;
|
|
113
|
+
}
|
|
114
|
+
/**
|
|
115
|
+
* Returns the first day of the week in the given locale.
|
|
116
|
+
* The locale decides what is the first day, e.g. Sunday in the US, Monday in
|
|
117
|
+
* the EU.
|
|
118
|
+
* @param date A Moment Datetime object
|
|
119
|
+
*/
|
|
120
|
+
|
|
121
|
+
|
|
122
|
+
function getFirstDayOfWeek(date) {
|
|
123
|
+
return date.clone().weekday(0);
|
|
124
|
+
}
|
|
92
125
|
/**
|
|
93
126
|
* Return a localized date + time with timezone as a ISO 8601 string
|
|
94
127
|
* @param {String} dateString
|
|
@@ -115,7 +148,9 @@ const DateTime = {
|
|
|
115
148
|
parse,
|
|
116
149
|
browserTimeZone,
|
|
117
150
|
isValid,
|
|
118
|
-
toLocaleString
|
|
151
|
+
toLocaleString,
|
|
152
|
+
getFirstDayOfWeek,
|
|
153
|
+
getLocalDayNamesOfTheWeek
|
|
119
154
|
};
|
|
120
155
|
exports.DateTime = DateTime;
|
|
121
156
|
var _default = DateTime;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@instructure/ui-i18n",
|
|
3
|
-
"version": "8.11.2-snapshot.
|
|
3
|
+
"version": "8.11.2-snapshot.44+e7e40bd05",
|
|
4
4
|
"description": "Helper components and utilities for internationalization.",
|
|
5
5
|
"author": "Instructure, Inc. Engineering and Product Design",
|
|
6
6
|
"type": "commonjs",
|
|
@@ -24,18 +24,18 @@
|
|
|
24
24
|
},
|
|
25
25
|
"license": "MIT",
|
|
26
26
|
"devDependencies": {
|
|
27
|
-
"@instructure/ui-babel-preset": "8.11.2-snapshot.
|
|
28
|
-
"@instructure/ui-test-utils": "8.11.2-snapshot.
|
|
27
|
+
"@instructure/ui-babel-preset": "8.11.2-snapshot.44+e7e40bd05",
|
|
28
|
+
"@instructure/ui-test-utils": "8.11.2-snapshot.44+e7e40bd05",
|
|
29
29
|
"@types/hoist-non-react-statics": "^3.3.1"
|
|
30
30
|
},
|
|
31
31
|
"dependencies": {
|
|
32
32
|
"@babel/runtime": "^7.13.10",
|
|
33
|
-
"@instructure/shared-types": "8.11.2-snapshot.
|
|
34
|
-
"@instructure/ui-decorator": "8.11.2-snapshot.
|
|
35
|
-
"@instructure/ui-dom-utils": "8.11.2-snapshot.
|
|
36
|
-
"@instructure/ui-prop-types": "8.11.2-snapshot.
|
|
37
|
-
"@instructure/ui-react-utils": "8.11.2-snapshot.
|
|
38
|
-
"@instructure/ui-utils": "8.11.2-snapshot.
|
|
33
|
+
"@instructure/shared-types": "8.11.2-snapshot.44+e7e40bd05",
|
|
34
|
+
"@instructure/ui-decorator": "8.11.2-snapshot.44+e7e40bd05",
|
|
35
|
+
"@instructure/ui-dom-utils": "8.11.2-snapshot.44+e7e40bd05",
|
|
36
|
+
"@instructure/ui-prop-types": "8.11.2-snapshot.44+e7e40bd05",
|
|
37
|
+
"@instructure/ui-react-utils": "8.11.2-snapshot.44+e7e40bd05",
|
|
38
|
+
"@instructure/ui-utils": "8.11.2-snapshot.44+e7e40bd05",
|
|
39
39
|
"hoist-non-react-statics": "^3.3.2",
|
|
40
40
|
"moment-timezone": "^0.5",
|
|
41
41
|
"prop-types": "^15"
|
|
@@ -47,5 +47,5 @@
|
|
|
47
47
|
"access": "public"
|
|
48
48
|
},
|
|
49
49
|
"sideEffects": false,
|
|
50
|
-
"gitHead": "
|
|
50
|
+
"gitHead": "e7e40bd053ec965afb10ef5a85379aec0452ce37"
|
|
51
51
|
}
|
package/src/DateTime.ts
CHANGED
|
@@ -22,14 +22,15 @@
|
|
|
22
22
|
* SOFTWARE.
|
|
23
23
|
*/
|
|
24
24
|
|
|
25
|
-
import moment from 'moment-timezone'
|
|
25
|
+
import moment, { Moment } from 'moment-timezone'
|
|
26
26
|
|
|
27
27
|
/**
|
|
28
28
|
* ---
|
|
29
29
|
* category: utilities/i18n
|
|
30
30
|
* ---
|
|
31
31
|
* @deprecated
|
|
32
|
-
*
|
|
32
|
+
* #### DEPRECATION WARNING: Will be removed in v9, which wil include a
|
|
33
|
+
* time library agnostic API.
|
|
33
34
|
* A wrapper for [moment](https://momentjs.com/) utils.
|
|
34
35
|
* @module DateTime
|
|
35
36
|
*/
|
|
@@ -81,6 +82,34 @@ function browserTimeZone() {
|
|
|
81
82
|
return moment.tz.guess()
|
|
82
83
|
}
|
|
83
84
|
|
|
85
|
+
/**
|
|
86
|
+
* Returns the days of the week in the given locale,
|
|
87
|
+
* for example ["Monday", "Tuesday",..]. It always begins with Monday.
|
|
88
|
+
* @param locale A locale accepted by the browser, e.g. America/New_York
|
|
89
|
+
* @param format If set to 'short' it will be maximum 3 letters long,
|
|
90
|
+
* if set to 'long' it will be the full word.
|
|
91
|
+
*/
|
|
92
|
+
function getLocalDayNamesOfTheWeek(locale: string, format: 'short' | 'long') {
|
|
93
|
+
const ret: string[] = []
|
|
94
|
+
const toFormat = format === 'short' ? 'dd' : 'dddd'
|
|
95
|
+
let currentDay = getFirstDayOfWeek(now(locale, browserTimeZone()))
|
|
96
|
+
for (let i = 0; i < 7; i++) {
|
|
97
|
+
ret.push(currentDay.format(toFormat))
|
|
98
|
+
currentDay = currentDay.add(1, 'day') // TODO this is mutable
|
|
99
|
+
}
|
|
100
|
+
return ret
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
/**
|
|
104
|
+
* Returns the first day of the week in the given locale.
|
|
105
|
+
* The locale decides what is the first day, e.g. Sunday in the US, Monday in
|
|
106
|
+
* the EU.
|
|
107
|
+
* @param date A Moment Datetime object
|
|
108
|
+
*/
|
|
109
|
+
function getFirstDayOfWeek(date: Moment) {
|
|
110
|
+
return date.clone().weekday(0)
|
|
111
|
+
}
|
|
112
|
+
|
|
84
113
|
/**
|
|
85
114
|
* Return a localized date + time with timezone as a ISO 8601 string
|
|
86
115
|
* @param {String} dateString
|
|
@@ -110,8 +139,11 @@ const DateTime = {
|
|
|
110
139
|
parse,
|
|
111
140
|
browserTimeZone,
|
|
112
141
|
isValid,
|
|
113
|
-
toLocaleString
|
|
142
|
+
toLocaleString,
|
|
143
|
+
getFirstDayOfWeek,
|
|
144
|
+
getLocalDayNamesOfTheWeek
|
|
114
145
|
}
|
|
115
146
|
|
|
116
147
|
export default DateTime
|
|
117
148
|
export { DateTime }
|
|
149
|
+
export type { Moment }
|
package/src/index.ts
CHANGED
|
@@ -36,6 +36,7 @@ export {
|
|
|
36
36
|
ApplyTextDirection
|
|
37
37
|
} from './ApplyTextDirection'
|
|
38
38
|
|
|
39
|
+
export type { Moment } from './DateTime'
|
|
39
40
|
export type { BidirectionalProps } from './bidirectional'
|
|
40
41
|
export type { ApplyLocaleProps } from './ApplyLocale/props'
|
|
41
42
|
export type { ApplyTextDirectionProps } from './ApplyTextDirection/props'
|
package/types/DateTime.d.ts
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
|
-
import moment from 'moment-timezone';
|
|
1
|
+
import moment, { Moment } from 'moment-timezone';
|
|
2
2
|
/**
|
|
3
3
|
* ---
|
|
4
4
|
* category: utilities/i18n
|
|
5
5
|
* ---
|
|
6
6
|
* @deprecated
|
|
7
|
-
*
|
|
7
|
+
* #### DEPRECATION WARNING: Will be removed in v9, which wil include a
|
|
8
|
+
* time library agnostic API.
|
|
8
9
|
* A wrapper for [moment](https://momentjs.com/) utils.
|
|
9
10
|
* @module DateTime
|
|
10
11
|
*/
|
|
@@ -35,6 +36,21 @@ declare function isValid(dateString: string): boolean;
|
|
|
35
36
|
* @returns {String} a time zone identifier (see https://en.wikipedia.org/wiki/List_of_tz_database_time_zones)
|
|
36
37
|
*/
|
|
37
38
|
declare function browserTimeZone(): string;
|
|
39
|
+
/**
|
|
40
|
+
* Returns the days of the week in the given locale,
|
|
41
|
+
* for example ["Monday", "Tuesday",..]. It always begins with Monday.
|
|
42
|
+
* @param locale A locale accepted by the browser, e.g. America/New_York
|
|
43
|
+
* @param format If set to 'short' it will be maximum 3 letters long,
|
|
44
|
+
* if set to 'long' it will be the full word.
|
|
45
|
+
*/
|
|
46
|
+
declare function getLocalDayNamesOfTheWeek(locale: string, format: 'short' | 'long'): string[];
|
|
47
|
+
/**
|
|
48
|
+
* Returns the first day of the week in the given locale.
|
|
49
|
+
* The locale decides what is the first day, e.g. Sunday in the US, Monday in
|
|
50
|
+
* the EU.
|
|
51
|
+
* @param date A Moment Datetime object
|
|
52
|
+
*/
|
|
53
|
+
declare function getFirstDayOfWeek(date: Moment): moment.Moment;
|
|
38
54
|
/**
|
|
39
55
|
* Return a localized date + time with timezone as a ISO 8601 string
|
|
40
56
|
* @param {String} dateString
|
|
@@ -50,7 +66,10 @@ declare const DateTime: {
|
|
|
50
66
|
browserTimeZone: typeof browserTimeZone;
|
|
51
67
|
isValid: typeof isValid;
|
|
52
68
|
toLocaleString: typeof toLocaleString;
|
|
69
|
+
getFirstDayOfWeek: typeof getFirstDayOfWeek;
|
|
70
|
+
getLocalDayNamesOfTheWeek: typeof getLocalDayNamesOfTheWeek;
|
|
53
71
|
};
|
|
54
72
|
export default DateTime;
|
|
55
73
|
export { DateTime };
|
|
74
|
+
export type { Moment };
|
|
56
75
|
//# sourceMappingURL=DateTime.d.ts.map
|
package/types/DateTime.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"DateTime.d.ts","sourceRoot":"","sources":["../src/DateTime.ts"],"names":[],"mappings":"AAwBA,OAAO,MAAM,MAAM,iBAAiB,CAAA;
|
|
1
|
+
{"version":3,"file":"DateTime.d.ts","sourceRoot":"","sources":["../src/DateTime.ts"],"names":[],"mappings":"AAwBA,OAAO,MAAM,EAAE,EAAE,MAAM,EAAE,MAAM,iBAAiB,CAAA;AAEhD;;;;;;;;;GASG;AAEH;;;;;GAKG;AACH,iBAAS,GAAG,CAAC,MAAM,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,iBAG5C;AAED;;;;;;GAMG;AACH,iBAAS,KAAK,CAAC,UAAU,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,iBASlE;AAED;;;;GAIG;AACH,iBAAS,OAAO,CAAC,UAAU,EAAE,MAAM,WAElC;AAED;;;;GAIG;AACH,iBAAS,eAAe,WAEvB;AAED;;;;;;GAMG;AACH,iBAAS,yBAAyB,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,OAAO,GAAG,MAAM,YAS1E;AAED;;;;;GAKG;AACH,iBAAS,iBAAiB,CAAC,IAAI,EAAE,MAAM,iBAEtC;AAED;;;;;;;GAOG;AACH,iBAAS,cAAc,CACrB,UAAU,EAAE,MAAM,EAClB,MAAM,EAAE,MAAM,EACd,QAAQ,EAAE,MAAM,EAChB,MAAM,CAAC,EAAE,MAAM,UAKhB;AAOD,QAAA,MAAM,QAAQ;;;;;;;;CAQb,CAAA;AAED,eAAe,QAAQ,CAAA;AACvB,OAAO,EAAE,QAAQ,EAAE,CAAA;AACnB,YAAY,EAAE,MAAM,EAAE,CAAA"}
|
package/types/index.d.ts
CHANGED
|
@@ -7,6 +7,7 @@ export { I18nPropTypes } from './I18nPropTypes';
|
|
|
7
7
|
export { Locale } from './Locale';
|
|
8
8
|
export { DIRECTION, TextDirectionContext } from './TextDirectionContext';
|
|
9
9
|
export { useTextDirectionContext, ApplyTextDirection } from './ApplyTextDirection';
|
|
10
|
+
export type { Moment } from './DateTime';
|
|
10
11
|
export type { BidirectionalProps } from './bidirectional';
|
|
11
12
|
export type { ApplyLocaleProps } from './ApplyLocale/props';
|
|
12
13
|
export type { ApplyTextDirectionProps } from './ApplyTextDirection/props';
|
package/types/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAwBA,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAA;AAC3C,OAAO,EAAE,kBAAkB,EAAE,MAAM,kCAAkC,CAAA;AAErE,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAA;AAC/C,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAA;AACrC,OAAO,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAA;AACrD,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAA;AAC/C,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAA;AACjC,OAAO,EAAE,SAAS,EAAE,oBAAoB,EAAE,MAAM,wBAAwB,CAAA;AACxE,OAAO,EACL,uBAAuB,EACvB,kBAAkB,EACnB,MAAM,sBAAsB,CAAA;AAE7B,YAAY,EAAE,kBAAkB,EAAE,MAAM,iBAAiB,CAAA;AACzD,YAAY,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAA;AAC3D,YAAY,EAAE,uBAAuB,EAAE,MAAM,4BAA4B,CAAA"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAwBA,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAA;AAC3C,OAAO,EAAE,kBAAkB,EAAE,MAAM,kCAAkC,CAAA;AAErE,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAA;AAC/C,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAA;AACrC,OAAO,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAA;AACrD,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAA;AAC/C,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAA;AACjC,OAAO,EAAE,SAAS,EAAE,oBAAoB,EAAE,MAAM,wBAAwB,CAAA;AACxE,OAAO,EACL,uBAAuB,EACvB,kBAAkB,EACnB,MAAM,sBAAsB,CAAA;AAE7B,YAAY,EAAE,MAAM,EAAE,MAAM,YAAY,CAAA;AACxC,YAAY,EAAE,kBAAkB,EAAE,MAAM,iBAAiB,CAAA;AACzD,YAAY,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAA;AAC3D,YAAY,EAAE,uBAAuB,EAAE,MAAM,4BAA4B,CAAA"}
|