-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #32 from niwla23/development
v2.0.1
- Loading branch information
Showing
5 changed files
with
109 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
/** | ||
* @format | ||
*/ | ||
|
||
import 'react-native'; | ||
import smartTimetableDay from '../src/helpers/smartTimetableDay'; | ||
|
||
it('monday, 11:00', () => { | ||
let result = smartTimetableDay(new Date('2022-04-18T11:00:00Z')); | ||
expect(result).toBe(1); // monday | ||
}); | ||
|
||
it('monday, 20:00', () => { | ||
let result = smartTimetableDay(new Date('2022-04-18T20:00:00Z')); | ||
expect(result).toBe(2); // tuesday | ||
}); | ||
|
||
it('tuesday, 11:00', () => { | ||
let result = smartTimetableDay(new Date('2022-04-19T11:00:00Z')); | ||
expect(result).toBe(2); // tuesday | ||
}); | ||
|
||
it('tuesday, 20:00', () => { | ||
let result = smartTimetableDay(new Date('2022-04-19T20:00:00Z')); | ||
expect(result).toBe(3); // wednesday | ||
}); | ||
|
||
it('wednesday, 5:00', () => { | ||
let result = smartTimetableDay(new Date('2022-04-20T05:00:00Z')); | ||
expect(result).toBe(3); // wednesday | ||
}); | ||
|
||
it('wednesday, 23:59', () => { | ||
let result = smartTimetableDay(new Date('2022-04-20T23:59:00Z')); | ||
expect(result).toBe(4); // thursday | ||
}); | ||
|
||
it('thursday, 10:00', () => { | ||
let result = smartTimetableDay(new Date('2022-04-21T10:00:00Z')); | ||
expect(result).toBe(4); // thursday | ||
}); | ||
|
||
it('thursday, 22:00', () => { | ||
let result = smartTimetableDay(new Date('2022-04-21T22:00:00Z')); | ||
expect(result).toBe(5); // friday | ||
}); | ||
|
||
it('friday, 10:00', () => { | ||
let result = smartTimetableDay(new Date('2022-04-22T10:00:00Z')); | ||
expect(result).toBe(5); // friday | ||
}); | ||
|
||
it('friday, 20:00', () => { | ||
let result = smartTimetableDay(new Date('2022-04-22T20:00:00Z')); | ||
expect(result).toBe(1); // monday | ||
}); | ||
|
||
it('saturday, 14:00', () => { | ||
let result = smartTimetableDay(new Date('2022-04-23T14:00:00Z')); | ||
expect(result).toBe(1); // monday | ||
}); | ||
|
||
it('sunday, 1:00', () => { | ||
let result = smartTimetableDay(new Date('2022-04-24T01:00:00Z')); | ||
expect(result).toBe(1); // monday | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,19 @@ | ||
import AsyncStorage from '@react-native-async-storage/async-storage'; | ||
import { Lesson } from '../types/timetable'; | ||
import {Lesson} from '../types/timetable'; | ||
|
||
export default async (data_to_serialize: Lesson[][]) => { | ||
data_to_serialize.map(async (day, dayIndex) => { | ||
day.map(async (lesson, lessonIndex) => { | ||
await AsyncStorage.setItem(`timetable.${dayIndex}.${lessonIndex}`, JSON.stringify( | ||
{ | ||
"teacher": lesson.teacher, | ||
"subject": lesson.subject, | ||
"room": lesson.room, | ||
"day": dayIndex, | ||
"hour": lessonIndex | ||
} | ||
)) | ||
}) | ||
}) | ||
} | ||
await AsyncStorage.setItem( | ||
`timetable.${dayIndex}.${lessonIndex}`, | ||
JSON.stringify({ | ||
teacher: lesson.teacher, | ||
subject: lesson.subject, | ||
room: lesson.room, | ||
day: dayIndex, | ||
hour: lessonIndex, | ||
}), | ||
); | ||
}); | ||
}); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
export const smartTimetableDay = (currentDate: Date): number => { | ||
let shouldUseNextDay = false; | ||
if (currentDate.getUTCHours() >= 18) { | ||
shouldUseNextDay = true; | ||
} | ||
if (currentDate.getUTCDay() >= 6 || currentDate.getUTCDay() === 0) { | ||
// who thought it is a good idea to make sunday day 0? | ||
// if we are on a weekend always show table for monday | ||
return 1; | ||
} | ||
if (shouldUseNextDay) { | ||
// time is after 18:00, showing next day | ||
if (currentDate.getUTCDay() === 5) { | ||
// friday evening, also show monday | ||
return 1; | ||
} else { | ||
// mo - fr, after 18:00 show next day | ||
return currentDate.getUTCDay() + 1; | ||
} | ||
} | ||
return currentDate.getUTCDay(); | ||
}; | ||
|
||
export default smartTimetableDay; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters