зеркало из https://github.com/microsoft/globe.git
Add MEDIUM_DATE_SHORT_TIME format
This commit is contained in:
Родитель
5f89d94c2a
Коммит
3d0b3ed6a8
|
@ -142,6 +142,9 @@ NPM Releases are made manually by @TomasHubelbauer at the moment.
|
|||
|
||||
## Release Notes
|
||||
|
||||
### `4.1.4` 2024-02-14
|
||||
Add new format `MEDIUM_DATE_SHORT_TIME`
|
||||
|
||||
### `4.1.3` 2021-08-09
|
||||
Attempting to fix VDI issues on Electron
|
||||
### `4.1.2` 2021-03-31
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
<script>
|
||||
var exports = {};
|
||||
</script>
|
||||
<script src="https://unpkg.com/@microsoft/globe@4.1.3/dist/globe.cjs.development.js"></script>
|
||||
<script src="https://unpkg.com/@microsoft/globe@4.1.4/dist/globe.cjs.development.js"></script>
|
||||
<!-- <script src="./../dist/globe.cjs.development.js"></script> -->
|
||||
<style>
|
||||
.header {
|
||||
|
@ -164,6 +164,7 @@
|
|||
MEDIUM_DATE_WITH_YEAR: exports.MEDIUM_DATE_WITH_YEAR,
|
||||
MEDIUM_WITH_YEAR: exports.MEDIUM_WITH_YEAR,
|
||||
MEDIUM: exports.MEDIUM,
|
||||
MEDIUM_DATE_SHORT_TIME: exports.MEDIUM_DATE_SHORT_TIME,
|
||||
HOUR_ONLY: exports.HOUR_ONLY,
|
||||
LONG_WEEKDAY_SHORT_TIME: exports.LONG_WEEKDAY_SHORT_TIME,
|
||||
LONG_WEEKDAY_LONG_TIME: exports.LONG_WEEKDAY_LONG_TIME,
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "@microsoft/globe",
|
||||
"version": "4.1.3",
|
||||
"version": "4.1.4",
|
||||
"description": "Globalization Service",
|
||||
"author": "Microsoft",
|
||||
"license": "MIT",
|
||||
|
|
|
@ -80,6 +80,13 @@ type MediumDateWithYear = Readonly<{
|
|||
year: 'numeric'
|
||||
}>;
|
||||
|
||||
type MediumDateShortTime = Readonly<{
|
||||
day: 'numeric',
|
||||
month: 'short',
|
||||
hour: 'numeric',
|
||||
minute: 'numeric'
|
||||
}>;
|
||||
|
||||
type ShortTimeZoneName = Readonly<{ timeZoneName: 'short' }>;
|
||||
|
||||
type LongTimeZoneName = Readonly<{ timeZoneName: 'long' }>;
|
||||
|
@ -137,6 +144,7 @@ export type DateTimeFormatOptions =
|
|||
| MediumDateWithYear
|
||||
| MediumWithYear
|
||||
| Medium
|
||||
| MediumDateShortTime
|
||||
| LongWeekday
|
||||
| ShortWeekday
|
||||
| HourOnly
|
||||
|
@ -273,6 +281,13 @@ export const MEDIUM: Medium = {
|
|||
...MEDIUM_TIME
|
||||
};
|
||||
|
||||
export const MEDIUM_DATE_SHORT_TIME: MediumDateShortTime = {
|
||||
day: 'numeric',
|
||||
month: 'short',
|
||||
hour: 'numeric',
|
||||
minute: 'numeric'
|
||||
};
|
||||
|
||||
export const HOUR_ONLY: HourOnly = {
|
||||
hour: 'numeric'
|
||||
};
|
||||
|
|
|
@ -22,7 +22,8 @@ const {
|
|||
FULL,
|
||||
SHORT_WITH_YEAR,
|
||||
SHORT,
|
||||
SHORT_TIME
|
||||
SHORT_TIME,
|
||||
MEDIUM_DATE_SHORT_TIME
|
||||
} = require('../dist/globe.cjs.development');
|
||||
|
||||
describe('date-time-format-options', () => {
|
||||
|
@ -210,6 +211,12 @@ describe('date-time-format-options', () => {
|
|||
expect(dateTimeFormatter.formatDateTime(date, SHORT_WEEKDAY_LONG_TIME)).toBe('Sun, 3:40:25 PM');
|
||||
});
|
||||
|
||||
it('medium date with short time', () => {
|
||||
const dateTimeFormatter = new DateTimeFormatter(localeInfo);
|
||||
const date = new Date(2020, 5, 28, 15, 40, 25);
|
||||
expect(dateTimeFormatter.formatDateTime(date, MEDIUM_DATE_SHORT_TIME)).toBe('Jun 28, 3:40 PM');
|
||||
});
|
||||
|
||||
it('removes unsupported symbols', () => {
|
||||
const localeInfo = { platform: 'macos', regionalFormat: 'en-US', shortTime: 'llwwWWDDFFggUUqqQQh:mm a' };
|
||||
const dateTimeFormatter = new DateTimeFormatter(localeInfo);
|
||||
|
@ -353,6 +360,12 @@ describe('date-time-format-options', () => {
|
|||
expect(dateTimeFormatter.formatDateTime(date, SHORT_WEEKDAY_LONG_TIME)).toBe('Sun, 3:40:25 PM');
|
||||
});
|
||||
|
||||
it('medium date with short time', () => {
|
||||
const dateTimeFormatter = new DateTimeFormatter(localeInfo);
|
||||
const date = new Date(2020, 5, 28, 15, 40, 25);
|
||||
expect(dateTimeFormatter.formatDateTime(date, MEDIUM_DATE_SHORT_TIME)).toBe('Jun 28, 3:40 PM');
|
||||
});
|
||||
|
||||
it('combines short month and long month', () => {
|
||||
const localeInfo = {
|
||||
platform: 'windows',
|
||||
|
@ -444,7 +457,7 @@ describe('date-time-format-options', () => {
|
|||
}
|
||||
const end = performance.now();
|
||||
expect(result).toBe('6/28/2020 3:40 PM');
|
||||
expect(end - start).toBe(0);
|
||||
expect(end - start).toBe(0);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
|
@ -23,6 +23,7 @@ import {
|
|||
LONG_WITH_YEAR_TIMEZONE,
|
||||
MEDIUM,
|
||||
MEDIUM_DATE,
|
||||
MEDIUM_DATE_SHORT_TIME,
|
||||
MEDIUM_DATE_WITH_YEAR,
|
||||
MEDIUM_TIME,
|
||||
MEDIUM_WITH_YEAR,
|
||||
|
@ -160,6 +161,16 @@ export class DateTimeFormatter {
|
|||
const t = this.formatter.timeToString(date, localeInfo.longTime);
|
||||
return this.combineDateAndTime(d, t);
|
||||
}
|
||||
case MEDIUM_DATE_SHORT_TIME: {
|
||||
if (!localeInfo.shortTime) {
|
||||
throw new Error(`localeInfo.shortTime was not provided!`);
|
||||
}
|
||||
|
||||
const d = this.cachedDateTimeFormat.get(loc, MEDIUM_DATE).format(date);
|
||||
const t = this.formatter.timeToString(date, localeInfo.shortTime);
|
||||
|
||||
return `${d}, ${t}`;
|
||||
}
|
||||
case FULL:
|
||||
case FULL_WITH_YEAR: {
|
||||
|
||||
|
|
|
@ -30,6 +30,7 @@ export {
|
|||
MEDIUM_DATE_WITH_YEAR,
|
||||
MEDIUM_WITH_YEAR,
|
||||
MEDIUM,
|
||||
MEDIUM_DATE_SHORT_TIME,
|
||||
HOUR_ONLY,
|
||||
LONG_WEEKDAY_SHORT_TIME,
|
||||
LONG_WEEKDAY_LONG_TIME,
|
||||
|
|
Загрузка…
Ссылка в новой задаче