Skip to content

Commit

Permalink
fixed text-input and month-number errors
Browse files Browse the repository at this point in the history
  • Loading branch information
varCepheid committed Jan 1, 2024
1 parent 7ca8d9c commit e1591bc
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
10 changes: 5 additions & 5 deletions src/routes/match-editor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -80,12 +80,12 @@ const EditorForm = ({
<TextInput
label="Date (in mm/dd format) or leave blank for current date"
onInput={setDay}
value={formatDate(matchDate)}
placeholder={formatDate(matchDate)}
/>
<TextInput
label="Time (in hh:mm format) or leave blank for current time"
onInput={setTime}
value={formatTime(matchDate)}
placeholder={formatTime(matchDate)}
/>
<TextInput
label="Teams (separate numbers with commas and spaces, red alliance first)"
Expand All @@ -97,17 +97,17 @@ const EditorForm = ({
}
setTeamList(teams)
}}
value={formatTeams()}
placeholder={formatTeams()}
/>
<TextInput
label="Red Alliance Score"
onInput={(input) => setRedScore(Number.parseInt(input))}
value={match?.redScore || 0}
placeholder={match?.redScore?.toString() || '0'}
/>
<TextInput
label="Blue Alliance Score"
onInput={(input) => setBlueScore(Number.parseInt(input))}
value={match?.blueScore || 0}
placeholder={match?.blueScore?.toString() || '0'}
/>
<Button disabled={isLoading || !isValid}>
{isLoading ? 'Saving Match Information' : 'Save Match'}
Expand Down
6 changes: 3 additions & 3 deletions src/utils/get-time-from-parts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export const formatTime = (date: Date) => {
}

export const formatDate = (date: Date) => {
const monthNumber = date.getMonth()
const monthNumber = date.getMonth() + 1
const dayNumber = date.getDate()
const month =
monthNumber < 10 ? '0' + String(monthNumber) : String(monthNumber)
Expand All @@ -18,7 +18,7 @@ export const formatDate = (date: Date) => {

export const getTimeFromParts = (date: string, time?: string) => {
const now = new Date(Date.now())
if ((date && date.length !== 5) || (time && time.length !== 5))
if ((date && date.length > 5) || (time && time.length !== 5))
return now.toISOString()
if (!time) time = formatTime(now)
if (!date) date = formatDate(now)
Expand All @@ -27,6 +27,6 @@ export const getTimeFromParts = (date: string, time?: string) => {
const day = Number.parseInt(date.slice(3, 5))
const hour = Number.parseInt(time.slice(0, 2))
const minute = Number.parseInt(time.slice(3, 5))
const inputDate = new Date(now.getFullYear(), month, day, hour, minute)
const inputDate = new Date(now.getFullYear(), month - 1, day, hour, minute)
return inputDate.toISOString()
}

0 comments on commit e1591bc

Please sign in to comment.