mirror of
https://github.com/ionic-team/ionic-framework.git
synced 2026-03-13 10:22:08 +08:00
chore(): sync vue branch with master
This commit is contained in:
@@ -220,7 +220,7 @@ describe('datetime-util', () => {
|
||||
"second": undefined,
|
||||
"tzOffset": 0,
|
||||
"year": 1000,
|
||||
"ampm": "am"
|
||||
"ampm": undefined
|
||||
});
|
||||
});
|
||||
|
||||
@@ -235,7 +235,7 @@ describe('datetime-util', () => {
|
||||
"second": undefined,
|
||||
"tzOffset": 0,
|
||||
"year": undefined,
|
||||
"ampm": "pm"
|
||||
"ampm": undefined
|
||||
});
|
||||
});
|
||||
|
||||
@@ -250,7 +250,7 @@ describe('datetime-util', () => {
|
||||
"second": 20,
|
||||
"tzOffset": 0,
|
||||
"year": 1994,
|
||||
"ampm": "pm"
|
||||
"ampm": undefined
|
||||
});
|
||||
});
|
||||
|
||||
@@ -265,7 +265,7 @@ describe('datetime-util', () => {
|
||||
"second": undefined,
|
||||
"tzOffset": 0,
|
||||
"year": 2018,
|
||||
"ampm": "am"
|
||||
"ampm": undefined
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
@@ -3,10 +3,16 @@
|
||||
* Defaults to the current date if
|
||||
* no date given
|
||||
*/
|
||||
export const getDateValue = (date: DatetimeData, format: string): number => {
|
||||
export const getDateValue = (date: DatetimeData, format: string): number | string => {
|
||||
const getValue = getValueFromFormat(date, format);
|
||||
|
||||
if (getValue !== undefined) { return getValue; }
|
||||
if (getValue !== undefined) {
|
||||
if (format === FORMAT_A || format === FORMAT_a) {
|
||||
date.ampm = getValue;
|
||||
}
|
||||
|
||||
return getValue;
|
||||
}
|
||||
|
||||
const defaultDate = parseDate(new Date().toISOString());
|
||||
return getValueFromFormat((defaultDate as DatetimeData), format);
|
||||
@@ -238,7 +244,6 @@ export const parseDate = (val: string | undefined | null): DatetimeData | undefi
|
||||
second: parse[6],
|
||||
millisecond: parse[7],
|
||||
tzOffset,
|
||||
ampm: parse[4] >= 12 ? 'pm' : 'am'
|
||||
};
|
||||
};
|
||||
|
||||
@@ -326,24 +331,6 @@ export const updateDate = (existingData: DatetimeData, newData: any, displayTime
|
||||
// newData is from the datetime picker's selected values
|
||||
// update the existing datetimeValue with the new values
|
||||
if (newData.ampm !== undefined && newData.hour !== undefined) {
|
||||
// If the date we came from exists, we need to change the meridiem value when
|
||||
// going to and from 12
|
||||
if (existingData.ampm !== undefined && existingData.hour !== undefined) {
|
||||
// If the existing meridiem is am, we want to switch to pm if it is either
|
||||
// A) coming from 0 (12 am)
|
||||
// B) going to 12 (12 pm)
|
||||
if (existingData.ampm === 'am' && (existingData.hour === 0 || newData.hour.value === 12)) {
|
||||
newData.ampm.value = 'pm';
|
||||
}
|
||||
|
||||
// If the existing meridiem is pm, we want to switch to am if it is either
|
||||
// A) coming from 12 (12 pm)
|
||||
// B) going to 12 (12 am)
|
||||
if (existingData.ampm === 'pm' && (existingData.hour === 12 || newData.hour.value === 12)) {
|
||||
newData.ampm.value = 'am';
|
||||
}
|
||||
}
|
||||
|
||||
// change the value of the hour based on whether or not it is am or pm
|
||||
// if the meridiem is pm and equal to 12, it remains 12
|
||||
// otherwise we add 12 to the hour value
|
||||
|
||||
@@ -7,14 +7,12 @@ const getActiveElementText = async (page) => {
|
||||
|
||||
test('datetime/picker: focus trap', async () => {
|
||||
const page = await newE2EPage({ url: '/src/components/datetime/test/basic?ionic:_testing=true' });
|
||||
|
||||
await page.click('#datetime-part');
|
||||
await page.waitForSelector('#datetime-part');
|
||||
|
||||
let datetime = await page.find('ion-datetime');
|
||||
|
||||
expect(datetime).not.toBe(null);
|
||||
await datetime.waitForVisible();
|
||||
|
||||
// TODO fix
|
||||
await page.waitFor(100);
|
||||
|
||||
@@ -113,8 +113,8 @@
|
||||
</ion-item>
|
||||
|
||||
<ion-item>
|
||||
<ion-label>HH:mm</ion-label>
|
||||
<ion-datetime display-format="HH:mm"></ion-datetime>
|
||||
<ion-label>HH:mm A</ion-label>
|
||||
<ion-datetime display-format="HH:mm A"></ion-datetime>
|
||||
</ion-item>
|
||||
|
||||
<ion-item>
|
||||
@@ -127,6 +127,11 @@
|
||||
<ion-datetime display-format="h:mm a" value="01:47"></ion-datetime>
|
||||
</ion-item>
|
||||
|
||||
<ion-item>
|
||||
<ion-label>h:mm A</ion-label>
|
||||
<ion-datetime display-format="h:mm A" value="14:23"></ion-datetime>
|
||||
</ion-item>
|
||||
|
||||
<ion-item>
|
||||
<ion-label>hh:mm A (15 min steps)</ion-label>
|
||||
<ion-datetime display-format="h:mm A" minute-values="0,15,30,45"></ion-datetime>
|
||||
|
||||
@@ -30,6 +30,38 @@ describe('Datetime', () => {
|
||||
expect(monthvalue).toEqual(date.getMonth() + 1);
|
||||
expect(yearValue).toEqual(date.getFullYear());
|
||||
});
|
||||
|
||||
it('it should return the date value for a given time', () => {
|
||||
const dateTimeData: DatetimeData = {
|
||||
hour: 2,
|
||||
minute: 23,
|
||||
tzOffset: 0
|
||||
};
|
||||
|
||||
const hourValue = getDateValue(dateTimeData, 'hh');
|
||||
const minuteValue = getDateValue(dateTimeData, 'mm');
|
||||
const ampmValue = getDateValue(dateTimeData, 'A');
|
||||
|
||||
expect(hourValue).toEqual(2);
|
||||
expect(minuteValue).toEqual(23);
|
||||
expect(ampmValue).toEqual("am");
|
||||
});
|
||||
|
||||
it('it should return the date value for a given time after 12', () => {
|
||||
const dateTimeData: DatetimeData = {
|
||||
hour: 16,
|
||||
minute: 47,
|
||||
tzOffset: 0
|
||||
};
|
||||
|
||||
const hourValue = getDateValue(dateTimeData, 'hh');
|
||||
const minuteValue = getDateValue(dateTimeData, 'mm');
|
||||
const ampmValue = getDateValue(dateTimeData, 'a');
|
||||
|
||||
expect(hourValue).toEqual(4);
|
||||
expect(minuteValue).toEqual(47);
|
||||
expect(ampmValue).toEqual("pm");
|
||||
});
|
||||
});
|
||||
|
||||
describe('getDateTime()', () => {
|
||||
|
||||
Reference in New Issue
Block a user