@brightspace-ui/intl 3.5.2 → 3.8.0

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/README.md CHANGED
@@ -95,7 +95,7 @@ const date = formatDateTime(
95
95
  Options:
96
96
  - **format**: pattern to use when rendering the date-time; default is `'short'`.
97
97
  - **full**: long weekday, month names and timezone. e.g. `'Wednesday, September 23, 2015 1:25 PM EST'`
98
- - **medium**: long month names. e.g. `'September 23, 2015 1:25 PM'`
98
+ - **medium**: short month names. e.g. `'Sept 23, 2015 1:25 PM'`
99
99
  - **short**: abbreviated date format. e.g. `'9/23/2015 1:25 PM'`
100
100
 
101
101
  To format a **timestamp** as a date and time:
@@ -110,6 +110,30 @@ const dateString = formatDateTimeFromTimestamp(
110
110
  Options are the same as for `formatDateTime`; this method converts the timestamp to a `Date` in the user's
111
111
  configured time zone, then returns the results of passing this date to `formatDateTime`.
112
112
 
113
+ To format a **timestamp** as a date only:
114
+
115
+ ```javascript
116
+ const dateString = formatDateFromTimestamp(
117
+ 1607097863123,
118
+ [options]
119
+ );
120
+ ```
121
+
122
+ Options are the same as for `formatDate`; this method converts the timestamp to a `Date` in the user's
123
+ configured time zone, then returns the results of passing this date to `formatDate`.
124
+
125
+ To format a **timestamp** as a time only:
126
+
127
+ ```javascript
128
+ const timeString = formatTimeFromTimestamp(
129
+ 1607097863123,
130
+ [options]
131
+ );
132
+ ```
133
+
134
+ Options are the same as for `formatTime`; this method converts the timestamp to a `Date` in the user's
135
+ configured time zone, then returns the results of passing this date to `formatTime`.
136
+
113
137
  To format a **date only** (without the time portion), use `formatDate`:
114
138
 
115
139
  ```javascript
package/lib/common.js CHANGED
@@ -121,6 +121,7 @@ class DocumentLocaleSettings {
121
121
  }
122
122
  }
123
123
  this._overrides = val;
124
+ this._listeners.forEach((cb) => cb());
124
125
  }
125
126
 
126
127
  addChangeListener(cb) {
@@ -151,6 +152,7 @@ class DocumentLocaleSettings {
151
152
  }
152
153
 
153
154
  _handleObserverChange(mutations) {
155
+ let localeAttributeChange = false;
154
156
  for (let i = 0; i < mutations.length; i++) {
155
157
  const mutation = mutations[i];
156
158
  if (mutation.attributeName === 'lang') {
@@ -161,10 +163,13 @@ class DocumentLocaleSettings {
161
163
  this.overrides = this._tryParseHtmlElemAttr('data-intl-overrides', {});
162
164
  } else if (mutation.attributeName === 'data-timezone') {
163
165
  this.timezone = this._tryParseHtmlElemAttr('data-timezone', { name: '', identifier: '' });
166
+ localeAttributeChange = true;
164
167
  } else if (mutation.attributeName === 'data-oslo') {
165
168
  this.oslo = this._tryParseHtmlElemAttr('data-oslo', { batch: null, collection: null, version: null });
169
+ localeAttributeChange = true;
166
170
  }
167
171
  }
172
+ if (localeAttributeChange) this._listeners.forEach((cb) => cb());
168
173
  }
169
174
 
170
175
  _normalize(langTag) {
package/lib/dateTime.js CHANGED
@@ -788,7 +788,7 @@ export function getDateTimeDescriptor() {
788
788
  ];
789
789
  break;
790
790
  case 'fr':
791
- dateFormats = ['dddd\' le \'d MMMM yyyy', 'd MMM yyyy', 'dd/MM/yyyy', 'MMMM yyyy', 'd MMMM', 'd MMM'];
791
+ dateFormats = ['dddd d MMMM yyyy', 'd MMM yyyy', 'dd/MM/yyyy', 'MMMM yyyy', 'd MMMM', 'd MMM'];
792
792
  months = [
793
793
  ['janvier', 'février', 'mars', 'avril', 'mai', 'juin', 'juillet', 'août', 'septembre', 'octobre', 'novembre', 'décembre'],
794
794
  ['janv.', 'févr.', 'mars', 'avr.', 'mai', 'juin', 'juil.', 'août', 'sept.', 'oct.', 'nov.', 'déc.']
@@ -877,13 +877,18 @@ export function getDateTimeDescriptor() {
877
877
  dateFormats = ['dddd, d MMMM yyyy', 'dd MMMM yyyy', 'dd/MM/yyyy', 'MMMM yyyy', 'd MMMM', 'd MMM'];
878
878
  break;
879
879
  case 'fr-ca':
880
- case 'fr-on':
881
880
  dateFormats[1] = 'MMM d yyyy';
882
881
  dateFormats[2] = 'yyyy-MM-dd';
883
882
  dateFormats[4] = 'MMMM d';
884
883
  dateFormats[5] = 'MMM d';
885
884
  firstDayOfWeek = 0;
886
885
  break;
886
+ case 'fr-on':
887
+ dateFormats[0] = 'dddd\' le \'d MMMM yyyy';
888
+ dateFormats[1] = 'MMM d yyyy';
889
+ dateFormats[2] = 'yyyy-MM-dd';
890
+ firstDayOfWeek = 0;
891
+ break;
887
892
  case 'zh-tw':
888
893
  days[0] = ['星期日', '星期一', '星期二', '星期三', '星期四', '星期五', '星期六'];
889
894
  break;
@@ -1128,10 +1133,24 @@ export function formatDateTime(date, options) {
1128
1133
 
1129
1134
  }
1130
1135
 
1131
- export function formatDateTimeFromTimestamp(timestamp, options) {
1136
+ function parseLocalDateTimeFromTimestamp(timestamp) {
1132
1137
  const utcDate = new Date(timestamp);
1133
1138
  const local = convertJsDateToLocalDateTime(utcDate);
1134
- if (!local) return formatDateTime(utcDate, options);
1135
- const localDate = new Date(local.year, local.month - 1, local.date, local.hours, local.minutes, local.seconds);
1136
- return formatDateTime(localDate, options);
1139
+ if (!local) return utcDate;
1140
+ return new Date(local.year, local.month - 1, local.date, local.hours, local.minutes, local.seconds);
1141
+ }
1142
+
1143
+ export function formatDateTimeFromTimestamp(timestamp, options) {
1144
+ const date = parseLocalDateTimeFromTimestamp(timestamp);
1145
+ return formatDateTime(date, options);
1146
+ }
1147
+
1148
+ export function formatDateFromTimestamp(timestamp, options) {
1149
+ const date = parseLocalDateTimeFromTimestamp(timestamp);
1150
+ return formatDate(date, options);
1151
+ }
1152
+
1153
+ export function formatTimeFromTimestamp(timestamp, options) {
1154
+ const date = parseLocalDateTimeFromTimestamp(timestamp);
1155
+ return formatTime(date, options);
1137
1156
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@brightspace-ui/intl",
3
- "version": "3.5.2",
3
+ "version": "3.8.0",
4
4
  "description": "Internationalization APIs for number, date, time and file size formatting and parsing in D2L Brightspace.",
5
5
  "main": "lib/number.js",
6
6
  "scripts": {
@@ -40,10 +40,10 @@
40
40
  "chai": "^4",
41
41
  "concurrently": "^6",
42
42
  "eslint": "^7",
43
- "eslint-config-brightspace": "^0.14",
43
+ "eslint-config-brightspace": "^0.16",
44
44
  "eslint-plugin-html": "^6",
45
45
  "eslint-plugin-sort-class-members": "^1",
46
- "http-server": "^0.12",
46
+ "http-server": "^14.0",
47
47
  "mocha": "^9",
48
48
  "mocha-headless-chrome": "^3"
49
49
  }