Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
yamitzky committed Feb 14, 2025
1 parent dda760a commit b2e3bcd
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 30 deletions.
1 change: 1 addition & 0 deletions apps/web/app/components/UpcomingReminders.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ export function UpcomingReminders({ reminders, className }: Props) {
sortedReminders.map((reminder, index) => (
<div key={index} className="flex flex-col gap-1 p-4 border rounded">
<div className="text-sm text-default-500">
{reminder.sendAt}
{locale === 'ja'
? `${dateTimeFormatter.format(parseISO(reminder.sendAt))}に通知`
: `Notify at ${dateTimeFormatter.format(parseISO(reminder.sendAt))}`}
Expand Down
1 change: 1 addition & 0 deletions packages/usecase/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
"@synk-cal/core": "workspace:*",
"@synk-cal/repository": "workspace:*",
"date-fns": "^4.1.0",
"date-fns-tz": "^3.2.0",
"eta": "^3.5.0"
},
"devDependencies": {
Expand Down
6 changes: 3 additions & 3 deletions packages/usecase/src/get_remind_targets.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ describe('getRemindTargets', () => {

expect(targets).toEqual([
{
sendAt: parseISO('2023-06-01T10:00:00Z'),
sendAt: parseISO('2023-06-01T19:00:00Z'),
notificationType: 'console',
target: '[email protected]',
message: 'Custom reminder: Event 1 tomorrow at 01:00.',
Expand Down Expand Up @@ -211,13 +211,13 @@ describe('getRemindTargets', () => {

expect(targets).toEqual([
{
sendAt: parseISO('2023-06-01T10:00:00Z'),
sendAt: parseISO('2023-06-01T19:00:00Z'),
notificationType: 'console',
target: '[email protected]',
message: 'Custom reminder: Event 1 tomorrow at 01:00.',
},
{
sendAt: parseISO('2023-06-01T10:00:00Z'),
sendAt: parseISO('2023-06-01T19:00:00Z'),
notificationType: 'webhook',
target: '[email protected]',
message: 'Custom reminder: Event 1 tomorrow at 01:00.',
Expand Down
33 changes: 6 additions & 27 deletions packages/usecase/src/get_remind_targets.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import type { CalendarRepository, GroupRepository, ReminderSetting, ReminderSettingsRepository } from '@synk-cal/core'
import { config } from '@synk-cal/core'
import { parseISO, subDays, subMinutes } from 'date-fns'
import { parseISO, setHours, setMinutes, subDays, subMinutes } from 'date-fns'
import { fromZonedTime, toZonedTime } from 'date-fns-tz'
import { Eta } from 'eta'
import { getEvents } from './get_events'

Expand All @@ -14,32 +15,10 @@ export const getReminderTime = (eventStart: Date, setting: ReminderSetting) => {
if ('minutesBefore' in setting) {
return subMinutes(eventStart, setting.minutesBefore)
} else {
const formatter = new Intl.DateTimeFormat('en-US', {
timeZone: config.TIMEZONE,
year: 'numeric',
month: '2-digit',
day: '2-digit',
hour: '2-digit',
minute: '2-digit',
second: '2-digit',
hour12: false,
})

const parts = formatter.formatToParts(eventStart)
// @ts-expect-error
const dateValues: Record<Intl.DateTimeFormatPartTypes, number> = {}
parts.forEach((part) => {
if (part.type !== 'literal') {
dateValues[part.type] = parseInt(part.value, 10)
}
})

let localDate = new Date(
Date.UTC(dateValues.year, dateValues.month - 1, dateValues.day, setting.hour, setting.minute, dateValues.second),
)
localDate = subDays(localDate, 1)
const offset = -new Date(new Date().toLocaleString('en-US', { timeZone: config.TIMEZONE })).getTimezoneOffset()
return new Date(localDate.getTime() - offset * 60 * 1000)
const zonedDate = toZonedTime(eventStart, config.TIMEZONE)
const previousDay = subDays(zonedDate, 1)
const previousDayAt = setMinutes(setHours(previousDay, setting.hour), setting.minute)
return fromZonedTime(previousDayAt, config.TIMEZONE)
}
}

Expand Down
12 changes: 12 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit b2e3bcd

Please sign in to comment.