@ltht-react/utils
Advanced tools
Comparing version 2.0.57 to 2.0.58
@@ -7,1 +7,2 @@ import { PartialDateTime } from '@ltht-react/types'; | ||
export declare const partialDateTimeText: (partialDateTime?: PartialDateTime | null) => string; | ||
export declare const formatPartialDateTimeAsDateOnly: (partialDateTime?: PartialDateTime | null) => string; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.partialDateTimeText = exports.formatDateTime = exports.formatTime = exports.formatDateExplicitMonth = exports.formatDate = void 0; | ||
exports.formatPartialDateTimeAsDateOnly = exports.partialDateTimeText = exports.formatDateTime = exports.formatTime = exports.formatDateExplicitMonth = exports.formatDate = void 0; | ||
var types_1 = require("@ltht-react/types"); | ||
var date_fns_1 = require("date-fns"); | ||
var locale = 'en-gb'; | ||
@@ -51,2 +52,9 @@ var dayFormat = '2-digit'; | ||
exports.partialDateTimeText = partialDateTimeText; | ||
var formatPartialDateTimeAsDateOnly = function (partialDateTime) { | ||
if (!(partialDateTime === null || partialDateTime === void 0 ? void 0 : partialDateTime.value)) | ||
return ''; | ||
var date = (0, date_fns_1.parseISO)(partialDateTime.value); | ||
return (0, date_fns_1.format)(date, 'dd-MMM-yyyy'); | ||
}; | ||
exports.formatPartialDateTimeAsDateOnly = formatPartialDateTimeAsDateOnly; | ||
//# sourceMappingURL=partial-date-time.js.map |
@@ -38,2 +38,6 @@ "use strict"; | ||
}); | ||
it('formats DateTimes to show date portion only in DD-MMM-YYYY format', function () { | ||
var date = partialDateTime(types_1.PartialDateTimeKindCode.DateTime); | ||
expect((0, partial_date_time_1.formatPartialDateTimeAsDateOnly)(date)).toEqual('03-Feb-2013'); | ||
}); | ||
}); | ||
@@ -40,0 +44,0 @@ var dateValue = '2013-02-03T13:15:16+00:00'; |
{ | ||
"name": "@ltht-react/utils", | ||
"version": "2.0.57", | ||
"version": "2.0.58", | ||
"description": "> TODO: description", | ||
@@ -26,6 +26,6 @@ "author": "Jonny Smith <jonny.asmith@gmail.com>", | ||
"dependencies": { | ||
"@ltht-react/types": "^2.0.57", | ||
"@ltht-react/types": "^2.0.58", | ||
"html-react-parser": "^5.0.6" | ||
}, | ||
"gitHead": "5d00f4b3bddb06fc2fbcaf5df1e1d240564db63b" | ||
"gitHead": "493e7178c2fece764ed0459a905fa86a1b23b54a" | ||
} |
import { PartialDateTime, PartialDateTimeKindCode } from '@ltht-react/types' | ||
import { formatDateTime, partialDateTimeText } from './partial-date-time' | ||
import { formatDateTime, partialDateTimeText, formatPartialDateTimeAsDateOnly } from './partial-date-time' | ||
@@ -40,2 +40,7 @@ describe('partialDateTimeText', () => { | ||
}) | ||
it('formats DateTimes to show date portion only in DD-MMM-YYYY format', () => { | ||
const date = partialDateTime(PartialDateTimeKindCode.DateTime) | ||
expect(formatPartialDateTimeAsDateOnly(date)).toEqual('03-Feb-2013') | ||
}) | ||
}) | ||
@@ -42,0 +47,0 @@ |
import { PartialDateTime, PartialDateTimeKindCode } from '@ltht-react/types' | ||
import { format, parseISO } from 'date-fns' | ||
@@ -46,1 +47,8 @@ const locale = 'en-gb' | ||
} | ||
export const formatPartialDateTimeAsDateOnly = (partialDateTime?: PartialDateTime | null): string => { | ||
if (!partialDateTime?.value) return '' | ||
const date = parseISO(partialDateTime.value) | ||
return format(date, 'dd-MMM-yyyy') | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
176886
2894
Updated@ltht-react/types@^2.0.58