Skip to content

Commit

Permalink
Merge branch 'unixtime' into development
Browse files Browse the repository at this point in the history
  • Loading branch information
MoralCode committed Dec 26, 2020
2 parents 7730a9f + 9df2a40 commit 50bb237
Show file tree
Hide file tree
Showing 13 changed files with 138 additions and 136 deletions.
18 changes: 10 additions & 8 deletions package.json
Expand Up @@ -24,6 +24,7 @@
"date-fns": "^1.30.1",
"jsonapi-serializer": "^3.6.6",
"lodash.clonedeep": "^4.5.0",
"luxon": "^1.25.0",
"react": "^16.8.6",
"react-dom": "^16.8.6",
"react-redux": "^7.1.0",
Expand Down Expand Up @@ -60,29 +61,30 @@
"devDependencies": {
"@babel/helper-builder-react-jsx": "^7.10.4",
"@babel/helper-regex": "^7.10.5",
"@types/fetch-mock": "^7.3.2",
"@types/jest": "^24.0.18",
"@types/jsonapi-serializer": "^3.6.2",
"@types/lodash.clonedeep": "^4.5.6",
"@types/lodash.find": "^4.6.6",
"@types/luxon": "^1.25.0",
"@types/node": "^12.7.3",
"@types/react": "^16.9.2",
"@types/react-dom": "^16.9.0",
"@types/react-redux": "^7.1.0",
"@types/react-test-renderer": "^16.9.0",
"@types/redux-first-routing": "^0.3.0",
"@types/redux-logger": "^3.0.7",
"@types/fetch-mock": "^7.3.2",
"@types/react-test-renderer": "^16.9.0",
"@types/redux-mock-store": "^1.0.1",
"fetch-mock": "^8.1.0",
"lodash.find": "^4.6.0",
"mockdate": "^2.0.5",
"node-fetch": "^2.6.0",
"prettier": "1.18.2",
"react-test-renderer": "16.8.6",
"redux-logger": "^3.0.6",
"redux-mock-store": "^1.5.4",
"tslint": "^5.18.0",
"tslint-config-prettier": "^1.18.0",
"tslint-react": "^4.0.0",
"fetch-mock": "^8.1.0",
"mockdate": "^2.0.5",
"node-fetch": "^2.6.0",
"react-test-renderer": "16.8.6",
"redux-mock-store": "^1.5.4"
"tslint-react": "^4.0.0"
}
}
1 change: 0 additions & 1 deletion src/@types/bellschedule.test.ts
@@ -1,5 +1,4 @@
import BellSchedule from "./bellschedule";
import Time from "./time";
import { bellSchedule as schedule, bellScheduleJSON, classPeriod, bellScheduleEndpoint, bellScheduleName, bellScheduleDisplayName, bellScheduleId, startTime, beforeClass, duringClass, endTime, afterClass, bellScheduleClasses } from "../utils/testconstants";

describe("BellSchedule", () => {
Expand Down
27 changes: 13 additions & 14 deletions src/@types/bellschedule.ts
@@ -1,16 +1,15 @@
import ClassPeriod from "./classperiod";
import Time from "./time";
import { DateTime } from "luxon";
import { TimeComparisons } from "../utils/enums";
import { getValueIfKeyInList, sortClassesByStartTime } from "../utils/helpers";
import { parse, isSameDay } from "date-fns";

export default class BellSchedule {
public static fromJson(json: any) {
return new BellSchedule(
getValueIfKeyInList(["id", "identifier"], json),
getValueIfKeyInList(["name", "full_name", "fullName"], json),
getValueIfKeyInList(["endpoint"], json),
getValueIfKeyInList(["dates"], json).map((date: string) => parse(date)),
getValueIfKeyInList(["dates"], json).map((date: string) => DateTime.fromISO(date)),
getValueIfKeyInList(["classes", "meeting_times"], json).map(
(meetingTime: any) => ClassPeriod.fromJson(meetingTime)
),
Expand All @@ -23,18 +22,18 @@ export default class BellSchedule {
private name: string;
private endpoint: string;
private displayName?: string;
private dates: Date[];
private dates: DateTime[];
private classes: ClassPeriod[];
private lastUpdatedDate: Date;
private lastUpdatedDate: DateTime;
private color?: string;

constructor(
id: string,
name: string,
endpoint: string,
dates: Date[],
dates: DateTime[],
classes: ClassPeriod[],
lastUpdatedDate: Date,
lastUpdatedDate: DateTime,
displayName?: string
) {
this.id = id;
Expand Down Expand Up @@ -84,20 +83,20 @@ export default class BellSchedule {
* inaccuracies due to incorrect milliseconds .etc.
*
*/
public getDate(date: Date) {
public getDate(date: DateTime) {
for (const scheduleDate of this.getDates()) {
if (isSameDay(scheduleDate, date)) {
if (scheduleDate.hasSame(date, "day")) {
return scheduleDate;
}
}
return;
}

public addDate(date: Date) {
public addDate(date: DateTime) {
this.dates.push(date);
}

public removeDate(date: Date) {
public removeDate(date: DateTime) {
const actualDate = this.getDate(date);
if (!actualDate){
return false;
Expand All @@ -110,7 +109,7 @@ export default class BellSchedule {
return this.classes;
}

public getClassPeriodForTime(time: Time) {
public getClassPeriodForTime(time: DateTime) {
for (const classPeriod of sortClassesByStartTime(this.classes)) {
if (classPeriod.stateForTime(time) === TimeComparisons.IS_DURING_OR_EXACTLY) {
return classPeriod;
Expand Down Expand Up @@ -148,7 +147,7 @@ export default class BellSchedule {
return this.lastUpdatedDate;
}

public hasChangedSince(date: Date) {
return date.getTime() < this.lastUpdatedDate.getTime();
public hasChangedSince(date: DateTime) {
return date.toMillis() < this.lastUpdatedDate.toMillis();
}
}
24 changes: 12 additions & 12 deletions src/@types/classperiod.ts
@@ -1,4 +1,4 @@
import Time from "./time";
import { DateTime, Interval } from "luxon";
import { checkTimeRange, getValueIfKeyInList } from "../utils/helpers";

export default class ClassPeriod {
Expand All @@ -7,17 +7,17 @@ export default class ClassPeriod {
const end = getValueIfKeyInList(["endTime", "end_time"], json);
return new ClassPeriod(
getValueIfKeyInList(["name", "classPeriodName", "class_period_name"], json),
start instanceof Time ? start : Time.fromString(start),
end instanceof Time ? end : Time.fromString(end),
new Date(getValueIfKeyInList(["creationDate", "creation_date"], json))
start instanceof DateTime ? start : DateTime.fromISO(start),
end instanceof DateTime ? end : DateTime.fromISO(end),
DateTime.fromISO(getValueIfKeyInList(["creationDate", "creation_date"], json))
);
}
private name: string;
private startTime: Time;
private endTime: Time;
private creationDate: Date;
private startTime: DateTime;
private endTime: DateTime;
private creationDate: DateTime;

constructor(name: string, startTime: Time, endTime: Time, creationDate: Date) {
constructor(name: string, startTime: DateTime, endTime: DateTime, creationDate: DateTime) {
this.name = name;
this.startTime = startTime;
this.endTime = endTime;
Expand All @@ -36,28 +36,28 @@ export default class ClassPeriod {
return this.startTime;
}

public setStartTime(time: Time) {
public setStartTime(time: DateTime) {
this.startTime = time;
}

public getEndTime() {
return this.endTime;
}

public setEndTime(time: Time) {
public setEndTime(time: DateTime) {
this.endTime = time;
}

public getDuration() {
return this.startTime.getTimeDeltaTo(this.endTime);
return Interval.fromDateTimes(this.startTime, this.endTime);
}

public getCreationDate() {
return this.creationDate;
}

//remove me
public stateForTime(time: Time) {
public stateForTime(time: DateTime) {
return checkTimeRange(time, this.startTime, this.endTime);
}
}
25 changes: 12 additions & 13 deletions src/@types/school.ts
Expand Up @@ -3,7 +3,7 @@ import {
getValueIfKeyInList,
sortClassesByStartTime
} from "../utils/helpers";
import Time from "./time";
import { DateTime } from "luxon";
import { TimeComparisons } from "../utils/enums";
import BellSchedule from "./bellschedule";
import find from 'lodash.find'
Expand Down Expand Up @@ -35,8 +35,8 @@ export default class School {
private timeZone?: string;
private schedules?: BellSchedule[];
private passingPeriodName?: string;
private creationDate?: Date;
private lastUpdatedDate?: Date;
private creationDate?: DateTime;
private lastUpdatedDate?: DateTime;

constructor(
id: string,
Expand All @@ -47,8 +47,8 @@ export default class School {
timeZone?: string,
schedules?: BellSchedule[],
passingPeriodName?: string,
creationDate?: Date,
lastUpdatedDate?: Date
creationDate?: DateTime,
lastUpdatedDate?: DateTime
) {
this.id = id;
this.ownerId = ownerId;
Expand Down Expand Up @@ -110,23 +110,23 @@ export default class School {
return this.lastUpdatedDate;
}

public hasChangedSince(date: Date) {
public hasChangedSince(date: DateTime) {
if (this.lastUpdatedDate !== undefined) {
return date.getTime() < this.lastUpdatedDate.getTime();
return date.toMillis() < this.lastUpdatedDate.toMillis();
} else {
return undefined;
}
}

//can also be used as isNoSchoolDay() by checking for undefined
public getScheduleForDate(date: Date) {
public getScheduleForDate(date: DateTime) {
if (this.schedules) {
for (const schedule of this.schedules) {
if (
schedule
.getDates()
.map((d: Date) => d.toDateString())
.includes(date.toDateString())
.includes(date)
// .map((d: Date) => d.toDateString())
) {
return schedule;
}
Expand All @@ -143,8 +143,7 @@ export default class School {

//change input to a time
//seems like te current schedule depends on this
public isInSession(date: Date, toLocalTime = false) {
const currentTime = Time.fromDate(date, toLocalTime);
public isInSession(date: DateTime) {
const currentSchedule = this.getScheduleForDate(date);
if (!currentSchedule) {
return false;
Expand All @@ -155,7 +154,7 @@ export default class School {
const lastClass = sortedClasses[currentSchedule.numberOfClasses()]
return (
checkTimeRange(
currentTime,
date,
firstClass.getStartTime(),
lastClass.getEndTime()
) == TimeComparisons.IS_DURING_OR_EXACTLY
Expand Down

0 comments on commit 50bb237

Please sign in to comment.