mirror of
https://github.com/kingomarnajjar/flex-template-web.git
synced 2026-07-28 03:43:28 +10:00
Merge pull request #191 from sharetribe/fix-birthdayinput-utc-handling
Fix BirthdayInput UTC Date handling
This commit is contained in:
commit
c1e6fe01ee
2 changed files with 15 additions and 10 deletions
|
|
@ -33,8 +33,8 @@ const Form = reduxForm({
|
|||
export const Empty = {
|
||||
component: Form,
|
||||
props: {
|
||||
onChange: values => {
|
||||
console.log('birthday changed to:', values.birthday);
|
||||
onChange: ({ birthday }) => {
|
||||
console.log('birthday changed to:', birthday ? birthday.toUTCString() : birthday);
|
||||
},
|
||||
},
|
||||
};
|
||||
|
|
|
|||
|
|
@ -29,15 +29,18 @@ const parseNum = str => {
|
|||
// Validate that the given date has the same info as the selected
|
||||
// value, i.e. it has not e.g. rolled over to the next month if the
|
||||
// selected month doesn't have as many days as selected.
|
||||
//
|
||||
// Note the UTC handling, we want to deal with UTC date info even
|
||||
// though the date object itself is in the user's local timezone.
|
||||
const isValidDate = (date, year, month, day) => {
|
||||
const yearsMatch = date.getFullYear() === year;
|
||||
const monthsMatch = date.getMonth() + 1 === month;
|
||||
const daysMatch = date.getDate() === day;
|
||||
const yearsMatch = date.getUTCFullYear() === year;
|
||||
const monthsMatch = date.getUTCMonth() + 1 === month;
|
||||
const daysMatch = date.getUTCDate() === day;
|
||||
return yearsMatch && monthsMatch && daysMatch;
|
||||
};
|
||||
|
||||
// Create a Date from the selected values. Return null if the date is
|
||||
// invalid.
|
||||
// Create a UTC Date from the selected values. Return null if the date
|
||||
// is invalid.
|
||||
const dateFromSelected = ({ day, month, year }) => {
|
||||
const dayNum = parseNum(day);
|
||||
const monthNum = parseNum(month);
|
||||
|
|
@ -49,10 +52,12 @@ const dateFromSelected = ({ day, month, year }) => {
|
|||
return null;
|
||||
};
|
||||
|
||||
// Get the UTC year/month/day info from the date object in local
|
||||
// timezone.
|
||||
const selectedFromDate = date => ({
|
||||
day: date.getDate(),
|
||||
month: date.getMonth() + 1,
|
||||
year: date.getFullYear(),
|
||||
day: date.getUTCDate(),
|
||||
month: date.getUTCMonth() + 1,
|
||||
year: date.getUTCFullYear(),
|
||||
});
|
||||
|
||||
// Always show 31 days per month
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue