diff --git a/apps/schedule/src/app/models/schedule.ts b/apps/schedule/src/app/models/slot.ts
similarity index 70%
rename from apps/schedule/src/app/models/schedule.ts
rename to apps/schedule/src/app/models/slot.ts
index d57c839..832ef71 100644
--- a/apps/schedule/src/app/models/schedule.ts
+++ b/apps/schedule/src/app/models/slot.ts
@@ -8,9 +8,3 @@ export interface Slot {
minutes: number;
offset: number;
}
-
-export interface Schedule {
- schedule: {
- scheduleSlots: Slot[];
- };
-}
diff --git a/apps/schedule/src/app/pipes/dayshoursminutes.pipe.ts b/apps/schedule/src/app/pipes/dayshoursminutes.pipe.ts
index dac1fbf..7d455c8 100644
--- a/apps/schedule/src/app/pipes/dayshoursminutes.pipe.ts
+++ b/apps/schedule/src/app/pipes/dayshoursminutes.pipe.ts
@@ -18,6 +18,8 @@ export class DaysHoursMinutesPipe implements PipeTransform {
let hours = hrs % 24;
let days = (hrs - hours) / 24 >> 0;
let result = minutes.toString() + ' minutes';
+ if (minutes == 1)
+ result = minutes.toString() + ' minute';
if (hours == 1)
result = hours.toString() + ' hour, ' + result;
else if (hours > 1)
diff --git a/apps/schedule/src/app/pipes/getdatetime.pipe.ts b/apps/schedule/src/app/pipes/getdatetime.pipe.ts
index 2448306..703ea05 100644
--- a/apps/schedule/src/app/pipes/getdatetime.pipe.ts
+++ b/apps/schedule/src/app/pipes/getdatetime.pipe.ts
@@ -3,7 +3,7 @@ import {
PipeTransform
} from '@angular/core';
-import { Slot } from '../models/schedule';
+import { Slot } from '../models/slot';
@Pipe({
@@ -13,15 +13,26 @@ export class GetDateTimePipe implements PipeTransform {
transform(slot: Slot): Date {
let result = new Date();
- let weekdays = ['sunday', 'monday', 'tuesday', 'wednesday', 'thursday', 'friday', 'saturday'];
- let day = weekdays.indexOf(slot.label.toLowerCase());
- let offset = day - result.getDay();
- if (offset < 0)
- offset += 7;
- result.setDate(result.getDate() + offset)
+ let day = WEEKDAYS.indexOf(slot.label.toLowerCase());
+ result.setDate(result.getDate() + day - result.getDay());
let remainder = slot.offset % 60;
result.setUTCHours(slot.hours - (slot.offset - remainder) / 60 >> 0);
result.setUTCMinutes(slot.minutes - remainder);
+ result.setUTCSeconds(0);
+ result.setUTCMilliseconds(0);
+ if (result.getTime() < Date.now()) {
+ result.setDate(result.getDate() + 7);
+ }
return result;
}
}
+
+const WEEKDAYS = [
+ 'sunday',
+ 'monday',
+ 'tuesday',
+ 'wednesday',
+ 'thursday',
+ 'friday',
+ 'saturday'
+];
diff --git a/apps/schedule/src/app/schedule/schedule.component.html b/apps/schedule/src/app/schedule/schedule.component.html
index 8a6a6b5..32b5cbc 100644
--- a/apps/schedule/src/app/schedule/schedule.component.html
+++ b/apps/schedule/src/app/schedule/schedule.component.html
@@ -18,7 +18,21 @@
Next scheduled livestream
- In {{dataSource.countdown$ | async | dayshoursminutes}}
+
+
+
+
+
+
+ = 1">In {{countdown | dayshoursminutes}}
+
+ Right now!
+
+
+
+
+
+
diff --git a/apps/schedule/src/app/schedule/schedule.component.ts b/apps/schedule/src/app/schedule/schedule.component.ts
index 3f21f12..fde5b1c 100644
--- a/apps/schedule/src/app/schedule/schedule.component.ts
+++ b/apps/schedule/src/app/schedule/schedule.component.ts
@@ -39,4 +39,9 @@ export class ScheduleComponent implements OnInit {
changeTimeZone(value) {
this.timeZone = value;
}
+
+ calcColor(value) {
+ let x = Math.min(Math.exp(value / 600000), 255);
+ return `rgb(255, ${x}, ${x})`;
+ }
}
diff --git a/apps/schedule/src/app/services/schedule.datasource.ts b/apps/schedule/src/app/services/schedule.datasource.ts
index 05b4a86..d50a58e 100644
--- a/apps/schedule/src/app/services/schedule.datasource.ts
+++ b/apps/schedule/src/app/services/schedule.datasource.ts
@@ -17,7 +17,7 @@ import { GetDateTimePipe } from '../pipes/getdatetime.pipe';
import { ScheduleService } from './schedule.service';
-import { Slot } from '../models/schedule';
+import { Slot } from '../models/slot';
export class ScheduleDataSource implements DataSource {
@@ -28,6 +28,8 @@ export class ScheduleDataSource implements DataSource {
public loading$ = this.loadingSubject.asObservable();
public countdown$ = this.countdownSubject.asObservable();
+ private lastCountdown = 0;
+
constructor(private scheduleService: ScheduleService) { }
loadSchedule(disabled: boolean) {
@@ -38,35 +40,52 @@ export class ScheduleDataSource implements DataSource {
catchError(() => of([])),
finalize(() => this.loadingSubject.next(false))
)
- .subscribe(schedule => {
+ .subscribe((schedule: Slot[]) => {
schedule = this.sorted(schedule);
this.scheduleSubject.next(schedule);
- timer(0, 1000).subscribe(() =>
- this.countdownSubject.next(this.countdown(schedule))
- );
+ timer(0, 1000).subscribe(() => {
+ if (schedule.length == 0) {
+ return;
+ }
+
+ let nearest = (new GetDateTimePipe()).transform(schedule[0]);
+
+ if (schedule.length > 1) {
+ let nearest2 = (new GetDateTimePipe()).transform(schedule[1]);
+
+ if (nearest.getTime() > nearest2.getTime()) {
+ schedule = this.sorted(schedule);
+ this.scheduleSubject.next(schedule);
+ return;
+ }
+ }
+
+ let countdown = nearest.getTime() - Date.now();
+ let h = countdown - this.lastCountdown;
+
+ if (h > 0 && h < 2000) {
+ countdown = this.lastCountdown;
+ }
+
+ this.lastCountdown = countdown;
+
+ this.countdownSubject.next(countdown);
+ });
});
}
private sorted(schedule) {
schedule.sort(function(a, b) {
- a = new GetDateTimePipe().transform(a);
- b = new GetDateTimePipe().transform(b);
+ a = (new GetDateTimePipe()).transform(a);
+ b = (new GetDateTimePipe()).transform(b);
return a.getTime() - b.getTime();
});
return schedule;
}
- private countdown(schedule) {
- if (schedule.length == 0)
- return undefined;
-
- let next = new GetDateTimePipe().transform(schedule[0]);
- return next.getTime() - Date.now();
- }
-
connect(collectionViewer: CollectionViewer): Observable {
console.log('Connecting data source');
return this.scheduleSubject.asObservable();
diff --git a/apps/schedule/src/app/services/schedule.service.ts b/apps/schedule/src/app/services/schedule.service.ts
index 8772938..6b27de3 100644
--- a/apps/schedule/src/app/services/schedule.service.ts
+++ b/apps/schedule/src/app/services/schedule.service.ts
@@ -9,10 +9,7 @@ import { Observable } from 'rxjs/Observable';
import { map } from 'rxjs/operators';
-import {
- Schedule,
- Slot
-} from '../models/schedule';
+import { Slot } from '../models/slot';
@Injectable()
@@ -21,9 +18,11 @@ export class ScheduleService {
getSchedule(disabled = false): Observable {
- return this.http.get('https://schedule.twitch.serpent.ai/schedule/92737529')
+ return this.http.get('https://schedule.twitch.serpent.ai/schedule/92737529')
.pipe(
- map(res => res.schedule.scheduleSlots.filter(slot => disabled || slot.isEnabled))
+ map((res: any) => res.schedule.scheduleSlots.filter(
+ (slot: Slot) => disabled || slot.isEnabled
+ ))
);
}
}