Skip to content

Commit

Permalink
Merge pull request #1062 from lpsinger/parseDate
Browse files Browse the repository at this point in the history
Refactor date parsing for circulars search
  • Loading branch information
dakota002 authored Jun 26, 2023
2 parents b07ec23 + 7d82b34 commit 165b380
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 8 deletions.
5 changes: 0 additions & 5 deletions app/routes/circulars/circulars.lib.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,11 +76,6 @@ export function formatDateISO(date: number) {
return new Date(date).toISOString().replace(/\.\d+Z$/, 'Z')
}

/** convert a date in format mm-dd-yyyy (or YYYY-MM_DD) to ms since 01/01/1970 */
export function formatDateEpoch(date: string) {
return new Date(date).getTime()
}

/** Return true if the subject is valid, false if it is invalid, or undefined if it is an empty string */
export function subjectIsValid(subject: string) {
if (subject.length) {
Expand Down
10 changes: 7 additions & 3 deletions app/routes/circulars/circulars.server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import memoizee from 'memoizee'
import { getUser } from '../__auth/user.server'
import { bodyIsValid, formatAuthor, subjectIsValid } from './circulars.lib'
import type { Circular, CircularMetadata } from './circulars.lib'
import { formatDateEpoch } from './circulars.lib'
import { search as getSearch } from '~/lib/search.server'

export const group = 'gcn.nasa.gov/circular-submitter'
Expand Down Expand Up @@ -45,6 +44,11 @@ export const getDynamoDBAutoIncrement = memoizee(
{ promise: true }
)

/** convert a date in format mm-dd-yyyy (or YYYY-MM_DD) to ms since 01/01/1970 */
function parseDate(date?: string) {
return date ? new Date(date).getTime() : NaN
}

export async function search({
query,
page,
Expand All @@ -64,8 +68,8 @@ export async function search({
}> {
const client = await getSearch()

const startTime = formatDateEpoch(startDate!) || -Infinity
const endTime = formatDateEpoch(endDate!) + 86400000 || Infinity
const startTime = parseDate(startDate) || undefined
const endTime = parseDate(endDate) + 86400000 || undefined

const {
body: {
Expand Down

0 comments on commit 165b380

Please sign in to comment.