File tree Expand file tree Collapse file tree 8 files changed +20
-41
lines changed
Expand file tree Collapse file tree 8 files changed +20
-41
lines changed Original file line number Diff line number Diff line change @@ -12,6 +12,7 @@ import {
1212 UpcomingMatchesResponse ,
1313} from '@openapi' ;
1414import { startNextRound } from '@services/round' ;
15+ import dayjs from 'dayjs' ;
1516
1617export default function ActivateNextRoundModal ( {
1718 tournamentId,
@@ -46,7 +47,7 @@ export default function ActivateNextRoundModal({
4647 await startNextRound (
4748 tournamentId ,
4849 stageItem . id ,
49- values . adjust_to_time ? new Date ( ) : null
50+ values . adjust_to_time ? dayjs ( ) : null
5051 ) ;
5152 await swrStagesResponse . mutate ( ) ;
5253 await swrUpcomingMatchesResponse . mutate ( ) ;
Original file line number Diff line number Diff line change @@ -21,6 +21,7 @@ import { assert_not_none } from '@components/utils/assert';
2121import { Club , Tournament , TournamentsResponse } from '@openapi' ;
2222import { getBaseApiUrl , getClubs } from '@services/adapter' ;
2323import { createTournament } from '@services/tournament' ;
24+ import dayjs from 'dayjs' ;
2425
2526export function TournamentLogo ( { tournament } : { tournament : Tournament | null } ) {
2627 if ( tournament == null || tournament . logo_path == null ) return null ;
@@ -45,7 +46,7 @@ function GeneralTournamentForm({
4546 const { t } = useTranslation ( ) ;
4647 const form = useForm ( {
4748 initialValues : {
48- start_time : new Date ( ) . toISOString ( ) ,
49+ start_time : dayjs ( ) ,
4950 name : '' ,
5051 club_id : null ,
5152 dashboard_public : true ,
@@ -123,7 +124,7 @@ function GeneralTournamentForm({
123124 color = "indigo"
124125 leftSection = { < IconCalendarTime size = "1.1rem" stroke = { 1.5 } /> }
125126 onClick = { ( ) => {
126- form . setFieldValue ( 'start_time' , new Date ( ) . toISOString ( ) ) ;
127+ form . setFieldValue ( 'start_time' , dayjs ( ) ) ;
127128 } }
128129 >
129130 { t ( 'now_button' ) }
Original file line number Diff line number Diff line change 11import { MatchWithDetails } from '@openapi' ;
2+ import dayjs from 'dayjs' ;
23import { formatStageItemInput } from './stage_item_input' ;
34import { Translator } from './types' ;
45
@@ -14,25 +15,23 @@ export interface SchedulerSettings {
1415}
1516
1617export function getMatchStartTime ( match : MatchWithDetails ) {
17- return new Date ( match . start_time || '' ) ;
18+ return dayjs ( match . start_time || '' ) ;
1819}
1920
2021export function getMatchEndTime ( match : MatchWithDetails ) {
21- return new Date (
22- getMatchStartTime ( match ) . getTime ( ) + 60000 * ( match . duration_minutes + match . margin_minutes )
23- ) ;
22+ return getMatchStartTime ( match ) . add ( match . duration_minutes + match . margin_minutes , 'minutes' ) ;
2423}
2524
2625export function isMatchHappening ( match : MatchWithDetails ) {
27- return getMatchStartTime ( match ) < new Date ( ) && getMatchEndTime ( match ) > new Date ( ) ;
26+ return getMatchStartTime ( match ) < dayjs ( ) && getMatchEndTime ( match ) > dayjs ( ) ;
2827}
2928
3029export function isMatchInTheFutureOrPresent ( match : MatchWithDetails ) {
31- return getMatchEndTime ( match ) > new Date ( ) ;
30+ return getMatchEndTime ( match ) > dayjs ( ) ;
3231}
3332
3433export function isMatchInTheFuture ( match : MatchWithDetails ) {
35- return getMatchStartTime ( match ) > new Date ( ) ;
34+ return getMatchStartTime ( match ) > dayjs ( ) ;
3635}
3736
3837export function formatMatchInput1 (
Original file line number Diff line number Diff line change @@ -9,32 +9,6 @@ export function capitalize(str: string) {
99 return str . charAt ( 0 ) . toUpperCase ( ) + str . slice ( 1 ) ;
1010}
1111
12- function getTodayAtMidnight ( ) {
13- const d = new Date ( ) ;
14- d . setHours ( 0 , 0 , 0 , 0 ) ;
15- return d ;
16- }
17-
18- export function getDefaultTimeRange ( selectMultipleDates : boolean ) {
19- const maxDate = getTodayAtMidnight ( ) ;
20- const minDate = getTodayAtMidnight ( ) ;
21-
22- let offset = 1 ;
23- if ( minDate . getDay ( ) === 0 ) {
24- offset = 2 ;
25- } else if ( minDate . getDay ( ) === 1 ) {
26- offset = 3 ;
27- }
28-
29- minDate . setDate ( minDate . getDate ( ) - offset ) ;
30-
31- if ( ! selectMultipleDates ) {
32- maxDate . setDate ( minDate . getDate ( ) ) ;
33- }
34-
35- return [ minDate , maxDate ] ;
36- }
37-
3812export function getTournamentIdFromRouter ( ) {
3913 const params = useParams ( ) ;
4014 const { id : idString } : any = params ;
Original file line number Diff line number Diff line change @@ -44,6 +44,7 @@ import {
4444 unarchiveTournament ,
4545 updateTournament ,
4646} from '@services/tournament' ;
47+ import dayjs from 'dayjs' ;
4748
4849export function TournamentLogo ( { tournament } : { tournament : Tournament | null } ) {
4950 if ( tournament == null || tournament . logo_path == null ) return null ;
@@ -126,7 +127,7 @@ function GeneralTournamentForm({
126127
127128 const form = useForm ( {
128129 initialValues : {
129- start_time : new Date ( tournament . start_time ) ,
130+ start_time : dayjs ( tournament . start_time ) ,
130131 name : tournament . name ,
131132 club_id : `${ tournament . club_id } ` ,
132133 dashboard_public : tournament . dashboard_public ,
@@ -202,7 +203,7 @@ function GeneralTournamentForm({
202203 color = "indigo"
203204 leftSection = { < IconCalendarTime size = "1.1rem" stroke = { 1.5 } /> }
204205 onClick = { ( ) => {
205- form . setFieldValue ( 'start_time' , new Date ( ) ) ;
206+ form . setFieldValue ( 'start_time' , dayjs ( ) ) ;
206207 } }
207208 >
208209 { t ( 'set_to_new_button' ) }
Original file line number Diff line number Diff line change @@ -21,6 +21,7 @@ import {
2121 UpcomingMatchesResponse ,
2222 UserPublicResponse ,
2323} from '@openapi' ;
24+ import dayjs from 'dayjs' ;
2425import { getLogin , performLogout , tokenPresent } from './local_storage' ;
2526
2627export function handleRequestError ( response : AxiosError ) {
@@ -100,7 +101,7 @@ function getTimeState() {
100101 // Used to force a refresh on SWRResponse, even when the response stays the same.
101102 // For example, when the page layout depends on time, but the response contains
102103 // timestamps that don't change, this is necessary.
103- return { time : new Date ( ) } ;
104+ return { time : dayjs ( ) } ;
104105}
105106
106107const fetcher = ( url : string ) =>
Original file line number Diff line number Diff line change 1+ import { Dayjs } from 'dayjs' ;
12import { createAxios , handleRequestError } from './adapter' ;
23
34export async function createRound ( tournament_id : number , stage_item_id : number ) {
@@ -28,7 +29,7 @@ export async function updateRound(
2829export async function startNextRound (
2930 tournament_id : number ,
3031 stage_item_id : number ,
31- adjust_to_time : Date | null
32+ adjust_to_time : Dayjs | null
3233) {
3334 return createAxios ( )
3435 . post ( `tournaments/${ tournament_id } /stage_items/${ stage_item_id } /start_next_round` , {
Original file line number Diff line number Diff line change 1+ import { Dayjs } from 'dayjs' ;
12import { createAxios , handleRequestError } from './adapter' ;
23
34export async function createTournament (
@@ -7,7 +8,7 @@ export async function createTournament(
78 dashboard_endpoint : string ,
89 players_can_be_in_multiple_teams : boolean ,
910 auto_assign_courts : boolean ,
10- start_time : string ,
11+ start_time : Dayjs ,
1112 duration_minutes : number ,
1213 margin_minutes : number
1314) {
You can’t perform that action at this time.
0 commit comments