Fix timezone conversion.

master
Icedream 2017-08-20 11:51:14 +10:30
parent 57ada5e0ed
commit 3bebe84243
Signed by: icedream
GPG Key ID: 1573F6D8EFE4D0CF
2 changed files with 13 additions and 6 deletions

View File

@ -20,15 +20,19 @@ WebFont.load({
class App extends React.Component { class App extends React.Component {
static propTypes = { static propTypes = {
getNow: PropTypes.func, getNow: PropTypes.func,
weekdays: PropTypes.arrayOf(PropTypes.string), weekdays: PropTypes.arrayOf(
PropTypes.oneOfType([
PropTypes.string,
PropTypes.number,
])),
} }
static defaultProps = { static defaultProps = {
getNow: () => moment(), getNow: () => moment(),
weekdays: [ weekdays: [
'tuesday', 2,
'thursday', 4,
'saturday', 6,
], ],
} }

View File

@ -1,12 +1,15 @@
import moment from 'moment-timezone'; import moment from 'moment-timezone';
export default function getUpcomingDate(now, weekday: String) { const localTimeZone = moment.tz.guess();
export default function getUpcomingDate(now, weekday: String|Number) {
let wanted = moment() let wanted = moment()
.tz('CET') .tz('CET')
.isoWeekday(weekday) .isoWeekday(weekday)
.second(0) .second(0)
.minute(0) .minute(0)
.hour(0); .hour(0)
.tz(localTimeZone);
if (wanted.isBefore(now)) { if (wanted.isBefore(now)) {
// we want the date from the upcoming week // we want the date from the upcoming week