Date cleanup / refactoring
This commit is contained in:
1 parent
cb0ac1eaf0
commit
e78ced2383
8 files changed
+244
-497
No files matched your search
+21
-13
@@ -7,7 +7,11 @@
|
||||
<!-- Event spans will be rendered here -->
|
||||
</div>
|
||||
</div>
|
||||
<div v-if="monthLabel" class="month-name-label" :style="{ height: `${monthLabel.weeksSpan * 64}px` }">
|
||||
<div
|
||||
v-if="monthLabel"
|
||||
class="month-name-label"
|
||||
:style="{ height: `${monthLabel.weeksSpan * 64}px` }"
|
||||
>
|
||||
<span>{{ monthLabel.name }} '{{ monthLabel.year }}</span>
|
||||
</div>
|
||||
</div>
|
||||
@@ -16,19 +20,23 @@
|
||||
<script setup>
|
||||
import { computed } from 'vue'
|
||||
import DayCell from './DayCell.vue'
|
||||
import { isoWeekInfo, toLocalString, getLocalizedMonthName, monthAbbr, DEFAULT_TZ } from '@/utils/date'
|
||||
import {
|
||||
toLocalString,
|
||||
getLocalizedMonthName,
|
||||
monthAbbr,
|
||||
DEFAULT_TZ,
|
||||
getISOWeek,
|
||||
} from '@/utils/date'
|
||||
import { addDays } from 'date-fns'
|
||||
|
||||
const props = defineProps({
|
||||
week: {
|
||||
type: Object,
|
||||
required: true
|
||||
}
|
||||
required: true,
|
||||
},
|
||||
})
|
||||
|
||||
const weekNumber = computed(() => {
|
||||
return isoWeekInfo(props.week.monday).week
|
||||
})
|
||||
const weekNumber = computed(() => getISOWeek(props.week.monday))
|
||||
|
||||
const days = computed(() => {
|
||||
const d = new Date(props.week.monday)
|
||||
@@ -41,7 +49,7 @@ const days = computed(() => {
|
||||
dayOfMonth: d.getDate(),
|
||||
month: d.getMonth(),
|
||||
isFirstDayOfMonth: d.getDate() === 1,
|
||||
monthClass: monthAbbr[d.getMonth()]
|
||||
monthClass: monthAbbr[d.getMonth()],
|
||||
})
|
||||
d.setTime(addDays(d, 1).getTime())
|
||||
}
|
||||
@@ -49,19 +57,19 @@ const days = computed(() => {
|
||||
})
|
||||
|
||||
const monthLabel = computed(() => {
|
||||
const firstDayOfMonth = days.value.find(d => d.isFirstDayOfMonth)
|
||||
const firstDayOfMonth = days.value.find((d) => d.isFirstDayOfMonth)
|
||||
if (!firstDayOfMonth) return null
|
||||
|
||||
const month = firstDayOfMonth.month
|
||||
const year = firstDayOfMonth.date.getFullYear()
|
||||
|
||||
|
||||
// This is a simplified calculation for weeksSpan
|
||||
const weeksSpan = 4
|
||||
const weeksSpan = 4
|
||||
|
||||
return {
|
||||
name: getLocalizedMonthName(month),
|
||||
name: getLocalizedMonthName(month),
|
||||
year: String(year).slice(-2),
|
||||
weeksSpan
|
||||
weeksSpan,
|
||||
}
|
||||
})
|
||||
</script>
|
||||
Reference in new issue
Block a user