Skip to content

Commit b93b823

Browse files
committed
Fix bug in next timeslot
1 parent 68426b1 commit b93b823

File tree

4 files changed

+65
-27
lines changed

4 files changed

+65
-27
lines changed

Angular/src/app/home/home.component.ts

Lines changed: 7 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { Component, OnInit } from '@angular/core';
2+
import { TrackDataService } from '../track-data.service';
23
import { WatchNowService } from '../watch-now.service';
34

45
@Component({
@@ -7,34 +8,22 @@ import { WatchNowService } from '../watch-now.service';
78
styleUrls: ['./home.component.scss']
89
})
910
export class HomeComponent implements OnInit {
10-
constructor(private watchNowService: WatchNowService) { }
11+
constructor(
12+
private watchNowService: WatchNowService,
13+
private trackDataService: TrackDataService
14+
) { }
1115

1216
public hours: Date[] = [];
1317
public tracks: Track[] = [];
1418

1519
ngOnInit(): void {
16-
const trackNames = ['Web', 'Cloud', 'ML', 'Other'];
20+
const trackNames = TrackDataService.trackNames;
1721
this.tracks = trackNames.map(n => <Track>{
1822
title: n,
1923
liveUrl: this.watchNowService.getUrlForRoom(n)
2024
})
2125

22-
const year = 2021;
23-
const month = 10;
24-
const day = 16;
25-
const hours2 = [
26-
[9, 0],
27-
[9, 30],
28-
[10, 30],
29-
[11, 30],
30-
[13, 0],
31-
[14, 0],
32-
[15, 0],
33-
[16, 0],
34-
]
35-
this.hours = hours2.map(h =>
36-
new Date(year, month-1, day, h[0], h[1])
37-
);
26+
this.hours = this.trackDataService.getTimes();
3827
}
3928
}
4029

Angular/src/app/now-showing/now-showing.component.ts

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import {
66
Session,
77
SessionizeService,
88
} from '../sessionize-service.service';
9+
import { TrackDataService } from '../track-data.service';
910
import { WatchNowService } from '../watch-now.service';
1011

1112
@Component({
@@ -25,7 +26,8 @@ export class NowShowingComponent implements OnInit {
2526
private route: ActivatedRoute,
2627
private sessionizeService: SessionizeService,
2728
private dateConverterService: DateConverterService,
28-
private watchNowService: WatchNowService
29+
private watchNowService: WatchNowService,
30+
private trackDataService: TrackDataService
2931
) {}
3032

3133
ngOnInit(): void {
@@ -38,7 +40,8 @@ export class NowShowingComponent implements OnInit {
3840
this.route.params.subscribe((params) => {
3941
this.sessionsByRoom = {};
4042
const dateAsSeconds = parseInt(params.date, 10);
41-
this.date = new Date(dateAsSeconds);
43+
const dateParam = new Date(dateAsSeconds);
44+
this.date = this.getNearestDate(dateParam);
4245
this.nextDate = this.getNextDate(this.date);
4346

4447
const sessionsAtThisTime = sessionizeApiResult.sessions.filter(
@@ -59,13 +62,13 @@ export class NowShowingComponent implements OnInit {
5962
}
6063

6164
private getNextDate(date: Date): Date {
62-
const nextDate = new Date(date);
63-
if (date.getMinutes() === 0) {
64-
nextDate.setHours(date.getHours() + 1);
65-
} else {
66-
nextDate.setMinutes(date.getMinutes() + 30);
67-
}
68-
return nextDate;
65+
return this.trackDataService.getTimes()
66+
.filter(t => t > date)[0];
67+
}
68+
69+
private getNearestDate(date: Date): Date {
70+
return this.trackDataService.getTimes()
71+
.filter(t => t >= date)[0];
6972
}
7073

7174
public getPlayUrl(room: Room): string {
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import { TestBed } from '@angular/core/testing';
2+
3+
import { TrackDataService } from './track-data.service';
4+
5+
describe('TrackDataService', () => {
6+
let service: TrackDataService;
7+
8+
beforeEach(() => {
9+
TestBed.configureTestingModule({});
10+
service = TestBed.inject(TrackDataService);
11+
});
12+
13+
it('should be created', () => {
14+
expect(service).toBeTruthy();
15+
});
16+
});
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import { Injectable } from '@angular/core';
2+
3+
@Injectable({
4+
providedIn: 'root'
5+
})
6+
export class TrackDataService {
7+
constructor() { }
8+
9+
public static readonly year = 2021;
10+
public static readonly month = 10;
11+
public static readonly day = 16;
12+
public static readonly hours = [
13+
[9, 0],
14+
[9, 30],
15+
[10, 30],
16+
[11, 30],
17+
[13, 0],
18+
[14, 0],
19+
[15, 0],
20+
[16, 0],
21+
];
22+
23+
public static readonly trackNames = ['Web', 'Cloud', 'ML', 'Other'];
24+
25+
public getTimes(): Date[] {
26+
return TrackDataService.hours.map(h =>
27+
new Date(TrackDataService.year, TrackDataService.month-1, TrackDataService.day, h[0], h[1])
28+
);
29+
}
30+
}

0 commit comments

Comments
 (0)