Birthdays: Try to fix timezones

Signed-off-by: marcin mikołajczak <git@mkljczk.pl>
This commit is contained in:
marcin mikołajczak 2022-01-25 23:37:40 -08:00
parent ac42b43fab
commit 741e80d9ab
3 changed files with 11 additions and 5 deletions

View File

@ -39,8 +39,8 @@ class EditProfile extends ImmutablePureComponent {
if (!supportsBirthdays) return null; if (!supportsBirthdays) return null;
const maxDate = new Date(); let maxDate = new Date();
maxDate.setDate(maxDate.getDate() - minAge); maxDate = new Date(maxDate.getTime() - minAge * 1000 * 60 * 60 * 24 + maxDate.getTimezoneOffset() * 1000 * 60);
return ( return (
<div className='datepicker'> <div className='datepicker'>
@ -56,6 +56,7 @@ class EditProfile extends ImmutablePureComponent {
wrapperClassName='react-datepicker-wrapper' wrapperClassName='react-datepicker-wrapper'
onChange={onChange} onChange={onChange}
placeholderText={intl.formatMessage(messages.birthdayPlaceholder)} placeholderText={intl.formatMessage(messages.birthdayPlaceholder)}
minDate={new Date('1900-01-01')}
maxDate={maxDate} maxDate={maxDate}
required={required} required={required}
/> />

View File

@ -223,7 +223,7 @@ class RegistrationForm extends ImmutablePureComponent {
} }
if (birthday) { if (birthday) {
params.set('birthday', birthday.toISOString().slice(0, 10)); params.set('birthday', new Date(birthday.getTime() - (birthday.getTimezoneOffset() * 60000)).toISOString().slice(0, 10));
} }
}); });

View File

@ -125,7 +125,10 @@ class EditProfile extends ImmutablePureComponent {
map.set('hide_network', hidesNetwork(account)); map.set('hide_network', hidesNetwork(account));
map.set('discoverable', discoverable); map.set('discoverable', discoverable);
map.set('show_birthday', showBirthday); map.set('show_birthday', showBirthday);
if (birthday) map.set('birthday', new Date(birthday)); if (birthday) {
const date = new Date(birthday);
map.set('birthday', new Date(date.getTime() + (date.getTimezoneOffset() * 60000)));
}
unescapeParams(map, ['display_name', 'bio']); unescapeParams(map, ['display_name', 'bio']);
}); });
@ -166,7 +169,9 @@ class EditProfile extends ImmutablePureComponent {
hide_follows: state.hide_network, hide_follows: state.hide_network,
hide_followers_count: state.hide_network, hide_followers_count: state.hide_network,
hide_follows_count: state.hide_network, hide_follows_count: state.hide_network,
birthday: state.birthday?.toISOString().slice(0, 10), birthday: state.birthday
? new Date(state.birthday.getTime() - (state.birthday.getTimezoneOffset() * 60000)).toISOString().slice(0, 10)
: undefined,
show_birthday: state.show_birthday, show_birthday: state.show_birthday,
}, this.getFieldParams().toJS()); }, this.getFieldParams().toJS());
} }