@brightspace-ui/intl 3.5.1 → 3.7.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
@@ -226,7 +250,7 @@ Contributions are welcome, please submit a pull request!
226
250
 
227
251
  ## Versioning & Releasing
228
252
 
229
- > TL;DR: Commits prefixed with `fix:` and `feat:` will trigger patch and minor releases when merged to `master`. Read on for more details...
253
+ > TL;DR: Commits prefixed with `fix:` and `feat:` will trigger patch and minor releases when merged to `main`. Read on for more details...
230
254
 
231
255
  The [sematic-release GitHub Action](https://github.com/BrightspaceUI/actions/tree/master/semantic-release) is called from the `release.yml` GitHub Action workflow to handle version changes and releasing.
232
256
 
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
@@ -1128,10 +1128,24 @@ export function formatDateTime(date, options) {
1128
1128
 
1129
1129
  }
1130
1130
 
1131
- export function formatDateTimeFromTimestamp(timestamp, options) {
1131
+ function parseLocalDateTimeFromTimestamp(timestamp) {
1132
1132
  const utcDate = new Date(timestamp);
1133
1133
  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);
1134
+ if (!local) return utcDate;
1135
+ return new Date(local.year, local.month - 1, local.date, local.hours, local.minutes, local.seconds);
1136
+ }
1137
+
1138
+ export function formatDateTimeFromTimestamp(timestamp, options) {
1139
+ const date = parseLocalDateTimeFromTimestamp(timestamp);
1140
+ return formatDateTime(date, options);
1141
+ }
1142
+
1143
+ export function formatDateFromTimestamp(timestamp, options) {
1144
+ const date = parseLocalDateTimeFromTimestamp(timestamp);
1145
+ return formatDate(date, options);
1146
+ }
1147
+
1148
+ export function formatTimeFromTimestamp(timestamp, options) {
1149
+ const date = parseLocalDateTimeFromTimestamp(timestamp);
1150
+ return formatTime(date, options);
1137
1151
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@brightspace-ui/intl",
3
- "version": "3.5.1",
3
+ "version": "3.7.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
  }