Skip to content
This repository has been archived by the owner on Jan 7, 2022. It is now read-only.

Commit

Permalink
Refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
mariomka committed Jan 20, 2018
1 parent 296f2c0 commit 7d40f6f
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
10 changes: 3 additions & 7 deletions src/Datetime.vue
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
<script>
import { DateTime } from 'luxon'
import DatetimePopup from './DatetimePopup'
import { clearTime } from './util'
import { datetimeFromISO, clearTime } from './util'
export default {
components: {
Expand Down Expand Up @@ -93,19 +93,15 @@ export default {
},
data () {
const datetime = DateTime.fromISO(this.value).toUTC()
return {
isOpen: false,
datetime: datetime.isValid ? datetime : null
datetime: datetimeFromISO(this.value)
}
},
watch: {
value (newValue) {
const datetime = DateTime.fromISO(newValue).toUTC()
this.datetime = datetime.isValid ? datetime : null
this.datetime = datetimeFromISO(newValue)
}
},
Expand Down
6 changes: 6 additions & 0 deletions src/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@ export function capitalize (string) {
return string.charAt(0).toUpperCase() + string.slice(1)
}

export function datetimeFromISO (string) {
const datetime = DateTime.fromISO(string).toUTC()

return datetime.isValid ? datetime : null
}

export function monthDays (year, month) {
const monthDate = DateTime.local(year, month, 1)
const firstDay = monthDate.weekday - 1
Expand Down

0 comments on commit 7d40f6f

Please sign in to comment.