1
0

Fix setting dates in safari

Fixes #207
This commit is contained in:
kolaente
2021-02-03 23:06:06 +01:00
parent f4cc230e62
commit be92db49a9
5 changed files with 63 additions and 4 deletions

View File

@ -113,10 +113,11 @@
import flatPickr from 'vue-flatpickr-component'
import 'flatpickr/dist/flatpickr.css'
import {calculateDayInterval} from '@/helpers/time/calculateDayInterval'
import {format} from 'date-fns'
import {calculateDayInterval} from '@/helpers/time/calculateDayInterval'
import {calculateNearestHours} from '@/helpers/time/calculateNearestHours'
import {closeWhenClickedOutside} from '@/helpers/closeWhenClickedOutside'
import {createDateFromString} from '@/helpers/time/createDateFromString'
export default {
name: 'datepicker',
@ -168,10 +169,10 @@ export default {
this.date = null
return
}
this.date = new Date(newVal)
this.date = createDateFromString(newVal)
},
flatPickrDate(newVal) {
this.date = new Date(newVal)
this.date = createDateFromString(newVal)
this.updateData()
},
},

View File

@ -0,0 +1,15 @@
/**
* Returns a new date from any format in a way that all browsers, especially safari, can understand.
*
* @see https://kolaente.dev/vikunja/frontend/issues/207
*
* @param dateString
* @returns {Date}
*/
export const createDateFromString = dateString => {
if (dateString.includes('-')) {
dateString = dateString.replace(/-/g, "/")
}
return new Date(dateString)
}

View File

@ -0,0 +1,13 @@
import {createDateFromString} from './createDateFromString'
test('YYYY-MM-DD HH:MM', () => {
const dateString = '2021-02-06 12:00'
const date = createDateFromString(dateString)
expect(date).toBeInstanceOf(Date)
expect(date.getDate()).toBe(6)
expect(date.getMonth()).toBe(1)
expect(date.getFullYear()).toBe(2021)
expect(date.getHours()).toBe(12)
expect(date.getMinutes()).toBe(0)
expect(date.getSeconds()).toBe(0)
})

View File

@ -201,6 +201,7 @@ Vue.mixin({
return date ? format(date, 'PPPPpppp') : ''
},
formatDateShort: date => {
console.log('short date', date)
return formatDate(date, 'PPpp')
},
error: (e, context, actions = []) => message.error(e, context, actions),