Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions app/libs/date-utils.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,23 @@
import dayjs from '~/app/libs/dayjs'

/**
* 組織タイムゾーン基準で N ヶ月前の日付境界を UTC ISO 文字列で返す。
* 'all' の場合はエポック相当の固定値を返す。
*/
export function calcSinceDate(
periodMonths: number | 'all',
timezone: string,
): string {
if (periodMonths === 'all') return '2000-01-01T00:00:00.000Z'
return dayjs
.utc()
.tz(timezone)
.subtract(periodMonths, 'month')
.startOf('day')
.utc()
.toISOString()
}

export const parseDate = (date: string | null, timeZone: string) => {
const dt = date ? dayjs(date, 'YYYY-MM-DD') : dayjs()
return dt.tz(timeZone).startOf('day')
Expand Down
10 changes: 4 additions & 6 deletions app/routes/$orgSlug/analysis/feedbacks/_index/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ import {
TableHeader,
TableRow,
} from '~/app/components/ui/table'
import dayjs from '~/app/libs/dayjs'
import { orgContext } from '~/app/middleware/context'
import { calcSinceDate } from '~/app/libs/date-utils'
import { orgContext, timezoneContext } from '~/app/middleware/context'
import { listTeams } from '~/app/routes/$orgSlug/settings/teams._index/queries.server'
import { DataTablePagination } from './+components/data-table-pagination'
import { feedbackColumns } from './+components/feedback-columns'
Expand Down Expand Up @@ -60,6 +60,7 @@ const VALID_PERIODS = [1, 3, 6, 12]

export const loader = async ({ request, context }: Route.LoaderArgs) => {
const { organization } = context.get(orgContext)
const timezone = context.get(timezoneContext)

const url = new URL(request.url)
const teamParam = url.searchParams.get('team') || undefined
Expand All @@ -71,10 +72,7 @@ export const loader = async ({ request, context }: Route.LoaderArgs) => {
? Number(periodParam)
: 1

const sinceDate =
periodMonths === 'all'
? '2000-01-01T00:00:00.000Z'
: dayjs.utc().subtract(periodMonths, 'month').startOf('day').toISOString()
const sinceDate = calcSinceDate(periodMonths, timezone)

const page = Number(url.searchParams.get('page') || '1')
const perPage = Number(url.searchParams.get('per_page') || '20')
Expand Down
9 changes: 2 additions & 7 deletions app/routes/$orgSlug/analysis/inventory/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import {
SelectValue,
} from '~/app/components/ui/select'
import { Switch } from '~/app/components/ui/switch'
import { calcSinceDate } from '~/app/libs/date-utils'
import dayjs from '~/app/libs/dayjs'
import { orgContext, timezoneContext } from '~/app/middleware/context'
import { listTeams } from '~/app/routes/$orgSlug/settings/teams._index/queries.server'
Expand Down Expand Up @@ -54,13 +55,7 @@ export const loader = async ({ request, context }: Route.LoaderArgs) => {
const excludeBots = url.searchParams.get('excludeBots') !== '0'
const unreviewedOnly = url.searchParams.get('unreviewedOnly') === '1'

const sinceDate = dayjs
.utc()
.tz(timezone)
.subtract(periodMonths, 'month')
.startOf('day')
.utc()
.toISOString()
const sinceDate = calcSinceDate(periodMonths, timezone)

const now = dayjs.utc().toISOString()

Expand Down
10 changes: 4 additions & 6 deletions app/routes/$orgSlug/analysis/reviews/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ import {
SelectValue,
} from '~/app/components/ui/select'
import { Stack } from '~/app/components/ui/stack'
import dayjs from '~/app/libs/dayjs'
import { orgContext } from '~/app/middleware/context'
import { calcSinceDate } from '~/app/libs/date-utils'
import { orgContext, timezoneContext } from '~/app/middleware/context'
import { listTeams } from '~/app/routes/$orgSlug/settings/teams._index/queries.server'
import { getOrgCachedData } from '~/app/services/cache.server'
import { PRSizeChart } from './+components/pr-size-chart'
Expand Down Expand Up @@ -50,6 +50,7 @@ const PERIOD_OPTIONS = [

export const loader = async ({ request, context }: Route.LoaderArgs) => {
const { organization } = context.get(orgContext)
const timezone = context.get(timezoneContext)

const url = new URL(request.url)
const teamParam = url.searchParams.get('team')
Expand All @@ -62,10 +63,7 @@ export const loader = async ({ request, context }: Route.LoaderArgs) => {
? Number(periodParam)
: 3

const sinceDate =
periodMonths === 'all'
? '2000-01-01T00:00:00.000Z'
: dayjs.utc().subtract(periodMonths, 'month').startOf('day').toISOString()
const sinceDate = calcSinceDate(periodMonths, timezone)

const teams = await listTeams(organization.id)

Expand Down
Loading