Skip to content

Commit

Permalink
feat: Increase visibility of first day of Gregorian week and month
Browse files Browse the repository at this point in the history
  • Loading branch information
artonge committed Sep 6, 2024
1 parent 9cb96f0 commit bf64971
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 7 deletions.
24 changes: 22 additions & 2 deletions src/components/RepublicanDay.vue
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<script setup lang="ts">
import { getGregorianDate } from "../utils";
import type { Day, Month, Calendar } from '../models'
import { format } from "date-fns";
const { day, month, calendar, republicanYear } = defineProps<{
day: Day
Expand All @@ -14,18 +15,24 @@ const gregorianDate = getGregorianDate(
calendar.findIndex(_month => _month.name === month.name) + 1,
republicanYear
)
const gregorianDateString = format(gregorianDate, 'E. dd/MM/yyyy')
const isStartOfMonth = gregorianDate.getDate() === 1
const isStartOfWeek = gregorianDate.getDay() === 1
</script>

<template>
<div class="day">
<div class="day" :class="{ 'start-of-month': isStartOfMonth, 'start-of-week': isStartOfWeek }">
<div class="day__day">
{{ day.day }}
</div>
<div class="day__name">
{{ day.name }}
</div>
<small class="day__gregorian">
({{ gregorianDate }})
({{ gregorianDateString }})
</small>
</div>
</template>
Expand Down Expand Up @@ -56,4 +63,17 @@ const gregorianDate = getGregorianDate(
text-align: right;
}
}
.start-of-month {
background-color: rgba($color: #919191, $alpha: 0.3);
.day__gregorian {
text-decoration: underline;
font-weight: bold;
}
}
.start-of-week {
background-color: rgba($color: #919191, $alpha: 0.1);
}
</style>
8 changes: 3 additions & 5 deletions src/utils.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { set, addDays, format } from "date-fns"
import { set, addDays } from "date-fns"

export function isSextile(republicanYear: number): boolean {
return Math.floor((republicanYear - 1) * 0.242222) - Math.floor((republicanYear) * 0.242222) !== 0
}

export function getGregorianDate(republicanDay: number, republicanMonth: number, republicanYear: number): string {
export function getGregorianDate(republicanDay: number, republicanMonth: number, republicanYear: number): Date {
const sept_21_1792 = set(new Date(), { date: 21, month: 9 - 1, year: 1792, hours: 0, minutes: 0, seconds: 0, milliseconds: 0 })

const dayCountInCompletedMonths = (republicanMonth - 1) * 30
Expand All @@ -13,9 +13,7 @@ export function getGregorianDate(republicanDay: number, republicanMonth: number,

const daysSince_sept_21_1792 = republicanDay + dayCountInCompletedMonths + dayCountInCompletedYears + nbOfSextileDays

const gregorianDate = addDays(sept_21_1792, daysSince_sept_21_1792)

return format(gregorianDate, 'E. dd/MM/yyyy')
return addDays(sept_21_1792, daysSince_sept_21_1792)
}

// 232 => MMXXIV
Expand Down

0 comments on commit bf64971

Please sign in to comment.