refactor(luxon): Plugin CircleCI - Swapped over from using DayJS to Luxon (+ humanize-duration)
Signed-off-by: Harry Hogg <hhogg@spotify.com>
This commit is contained in:
@@ -0,0 +1,5 @@
|
||||
---
|
||||
'@backstage/plugin-circleci': patch
|
||||
---
|
||||
|
||||
Swapped over to using Luxon as opposed to DayJS in the CircleCI plugin as part of the single Date library improvements.
|
||||
@@ -41,8 +41,9 @@
|
||||
"@material-ui/icons": "^4.9.1",
|
||||
"@material-ui/lab": "4.0.0-alpha.57",
|
||||
"circleci-api": "^4.0.0",
|
||||
"dayjs": "^1.9.4",
|
||||
"humanize-duration": "^3.27.0",
|
||||
"lodash": "^4.17.15",
|
||||
"luxon": "^2.0.2",
|
||||
"react": "^16.13.1",
|
||||
"react-dom": "^16.13.1",
|
||||
"react-lazylog": "^4.5.2",
|
||||
@@ -58,6 +59,7 @@
|
||||
"@testing-library/jest-dom": "^5.10.1",
|
||||
"@testing-library/react": "^11.2.5",
|
||||
"@testing-library/user-event": "^13.1.8",
|
||||
"@types/humanize-duration": "^3.25.1",
|
||||
"@types/jest": "^26.0.7",
|
||||
"@types/node": "^14.14.32",
|
||||
"@types/react-lazylog": "^4.5.0",
|
||||
|
||||
@@ -13,25 +13,31 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
import { DateTime, Interval } from 'luxon';
|
||||
import humanizeDuration from 'humanize-duration';
|
||||
|
||||
import dayjs from 'dayjs';
|
||||
import durationPlugin from 'dayjs/plugin/duration';
|
||||
import relativeTimePlugin from 'dayjs/plugin/relativeTime';
|
||||
|
||||
dayjs.extend(durationPlugin);
|
||||
dayjs.extend(relativeTimePlugin);
|
||||
|
||||
type DateTimeObject = Date | string | number | undefined;
|
||||
|
||||
export function relativeTimeTo(time: DateTimeObject, withoutSuffix = false) {
|
||||
return dayjs().to(dayjs(time), withoutSuffix);
|
||||
export function relativeTimeTo(dateTimeISOString?: string) {
|
||||
return dateTimeISOString
|
||||
? DateTime.fromISO(dateTimeISOString).toRelative()
|
||||
: '';
|
||||
}
|
||||
|
||||
export function durationHumanized(
|
||||
startTime: DateTimeObject,
|
||||
endTime: DateTimeObject,
|
||||
) {
|
||||
return dayjs
|
||||
.duration(dayjs(startTime).diff(dayjs(endTime || new Date())))
|
||||
.humanize();
|
||||
startDateTimeISOString?: string,
|
||||
endDateTimeISOString?: string,
|
||||
): string {
|
||||
if (!startDateTimeISOString || !endDateTimeISOString) {
|
||||
return '';
|
||||
}
|
||||
|
||||
const startDateTime = DateTime.fromISO(startDateTimeISOString);
|
||||
const endDateTime = DateTime.fromISO(endDateTimeISOString);
|
||||
const duration = Interval.fromDateTimes(
|
||||
startDateTime,
|
||||
endDateTime,
|
||||
).toDuration();
|
||||
|
||||
return humanizeDuration(duration.as('milliseconds'), {
|
||||
largest: 1,
|
||||
});
|
||||
}
|
||||
|
||||
@@ -6709,6 +6709,11 @@
|
||||
resolved "https://registry.npmjs.org/@types/humanize-duration/-/humanize-duration-3.18.1.tgz#10090d596053703e7de0ac43a37b96cd9fc78309"
|
||||
integrity sha512-MUgbY3CF7hg/a/jogixmAufLjJBQT7WEf8Q+kYJkOc47ytngg1IuZobCngdTjAgY83JWEogippge5O5fplaQlw==
|
||||
|
||||
"@types/humanize-duration@^3.25.1":
|
||||
version "3.25.1"
|
||||
resolved "https://registry.npmjs.org/@types/humanize-duration/-/humanize-duration-3.25.1.tgz#b6140d5fc00ff3917b3f521784abef4bc0387ccc"
|
||||
integrity sha512-WZU/4bb+lvzyDmZzjJtp++9mfKy6B3lH6gGISgkcz6SU8hMILKRM0vi08TxIsb0dQB4Gzo68MWLmctu6xqUi9g==
|
||||
|
||||
"@types/inquirer@^7.3.1":
|
||||
version "7.3.1"
|
||||
resolved "https://registry.npmjs.org/@types/inquirer/-/inquirer-7.3.1.tgz#1f231224e7df11ccfaf4cf9acbcc3b935fea292d"
|
||||
@@ -11856,7 +11861,7 @@ dateformat@^3.0.0, dateformat@^3.0.3:
|
||||
resolved "https://registry.npmjs.org/dateformat/-/dateformat-3.0.3.tgz#a6e37499a4d9a9cf85ef5872044d62901c9889ae"
|
||||
integrity sha512-jyCETtSl3VMZMWeRo7iY1FL19ges1t55hMo5yaam4Jrsm5EPL89UQkoQRyiI+Yf4k8r2ZpdngkV8hr1lIdjb3Q==
|
||||
|
||||
dayjs@^1.10.4, dayjs@^1.9.4:
|
||||
dayjs@^1.10.4:
|
||||
version "1.10.4"
|
||||
resolved "https://registry.npmjs.org/dayjs/-/dayjs-1.10.4.tgz#8e544a9b8683f61783f570980a8a80eaf54ab1e2"
|
||||
integrity sha512-RI/Hh4kqRc1UKLOAf/T5zdMMX5DQIlDxwUe3wSyMMnEbGunnpENCdbUgM+dW7kXidZqCttBrmw7BhN4TMddkCw==
|
||||
@@ -15567,7 +15572,7 @@ human-signals@^2.1.0:
|
||||
resolved "https://registry.npmjs.org/human-signals/-/human-signals-2.1.0.tgz#dc91fcba42e4d06e4abaed33b3e7a3c02f514ea0"
|
||||
integrity sha512-B4FFZ6q/T2jhhksgkbEW3HBvWIfDW85snkQgawt07S7J5QXTk6BkNV+0yAeZrM5QpMAdYlocGoljn0sJ/WQkFw==
|
||||
|
||||
humanize-duration@^3.25.1, humanize-duration@^3.26.0:
|
||||
humanize-duration@^3.25.1, humanize-duration@^3.26.0, humanize-duration@^3.27.0:
|
||||
version "3.27.0"
|
||||
resolved "https://registry.npmjs.org/humanize-duration/-/humanize-duration-3.27.0.tgz#3f781b7cf8022ad587f76b9839b60bc2b29636b2"
|
||||
integrity sha512-qLo/08cNc3Tb0uD7jK0jAcU5cnqCM0n568918E7R2XhMr/+7F37p4EY062W/stg7tmzvknNn9b/1+UhVRzsYrQ==
|
||||
|
||||
Reference in New Issue
Block a user