Show announcement dates

This commit is contained in:
Tusooa Zhu 2022-03-17 16:51:32 -04:00 committed by tusooa
commit 04fbb6d93d
No known key found for this signature in database
GPG key ID: 7B467EDE43A08224
8 changed files with 156 additions and 58 deletions

View file

@ -1,6 +1,21 @@
import { mapState } from 'vuex'
import AnnouncementEditor from '../announcement_editor/announcement_editor.vue'
import localeService from '../../services/locale/locale.service.js'
const Announcement = {
components: {
AnnouncementEditor
},
data () {
return {
editing: false,
newAnnouncement: {
content: '',
startsAt: undefined,
endsAt: undefined
}
}
},
props: {
announcement: Object
},
@ -13,6 +28,22 @@ const Announcement = {
},
isRead () {
return this.announcement.read
},
startsAt () {
const time = this.announcement['starts_at']
if (!time) {
return
}
return this.formatTimeOrDate(time, localeService.internalToBrowserLocale(this.$i18n.locale))
},
endsAt () {
const time = this.announcement['ends_at']
if (!time) {
return
}
return this.formatTimeOrDate(time, localeService.internalToBrowserLocale(this.$i18n.locale))
}
},
methods: {
@ -23,6 +54,10 @@ const Announcement = {
},
deleteAnnouncement () {
return this.$store.dispatch('deleteAnnouncement', this.announcement.id)
},
formatTimeOrDate (time, locale) {
const d = new Date(time)
return this.announcement['all_day'] ? d.toLocaleDateString(locale) : d.toLocaleString(locale)
}
}
}