Skip to content

Commit

Permalink
Merge pull request #4233 from anko9801/fix/date_utc_bug
Browse files Browse the repository at this point in the history
検索の after before で日付のみを指定したときに JST となるようにパースする
  • Loading branch information
anko9801 authored Jul 14, 2024
2 parents 429b93b + a8bf74a commit a3e2391
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/lib/searchMessage/parserBase.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
// 実際のフィルタに依存しない関数群
import type { ChannelId, MessageId, UserId } from '/@/types/entity-ids'

const dateOnlyFormRegex = /^[0-9]{4}(-[0-9]{2}(-[0-9]{2})?)?$/

/*
* クエリは次のようにパースされる:
*
Expand Down Expand Up @@ -137,7 +139,11 @@ export type FilterParser<T extends string, V> = (
export const dateParser = <T extends string>(
extracted: ExtractedFilter<T>
): Date | undefined => {
const date = new Date(extracted.body)
// date-only form から date-time form に直して地方時を指定する
const dateQuery = dateOnlyFormRegex.test(extracted.body)
? extracted.body + 'T00:00:00.000'
: extracted.body
const date = new Date(dateQuery)
if (Number.isNaN(date.getTime())) {
return undefined
}
Expand Down

0 comments on commit a3e2391

Please sign in to comment.