Skip to content

Commit

Permalink
change today to tomorrow for next-day early times
Browse files Browse the repository at this point in the history
  • Loading branch information
cirex-web committed Jan 6, 2024
1 parent 6f49c5b commit 0aeaeef
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 21 deletions.
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,7 @@ yarn-debug.log*
yarn-error.log*

/dist
/dev-dist
/dev-dist

# for testing only
/public/example-response.json
8 changes: 4 additions & 4 deletions src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ import { queryLocations, getLocationStatus } from './util/queryLocations';
import './App.css';
import { IExtendedLocationData, ILocation } from './types/locationTypes';

const CMU_EATS_API_URL = 'https://dining.apis.scottylabs.org/locations';
// const CMU_EATS_API_URL = 'http://localhost:5010/locations'; // for debugging purposes
// const CMU_EATS_API_URL = 'https://dining.apis.scottylabs.org/locations';
const CMU_EATS_API_URL = 'http://localhost:5173/example-response.json'; // for debugging purposes (note that you need an example-response.json file in the /public folder)
function App() {
// Load locations
const [locations, setLocations] = useState<ILocation[]>();
Expand All @@ -27,8 +27,8 @@ function App() {
(function updateExtendedLocationData() {
if (locations !== undefined) {
// Remove .setZone('America/New_York') and change time in computer settings when testing
const now = DateTime.now().setZone('America/New_York');

// const now = DateTime.now().setZone('America/New_York');
const now = DateTime.local(2023, 12, 22, 18, 33);
setExtendedLocationData(
locations.map((location) => ({
...location,
Expand Down
10 changes: 1 addition & 9 deletions src/util/queryLocations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,15 +61,7 @@ export function getStatusMessage(
minutesSinceSundayDateTime(now)
) {
if (weekdayDiff === 1) {
if (
nextTime.hour <= 4 ||
(nextTime.hour === 5 && nextTime.minute === 0)
) {
// Anything in the very early morning of tomorrow counts as today
day = 'today';
} else {
day = 'tomorrow';
}
day = 'tomorrow';
} else if (weekdayDiff === 0) {
day = 'today';
}
Expand Down
14 changes: 7 additions & 7 deletions tests/util/locations.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ test.each([
isOpen: false,
nextTime: { day: 3, hour: 0, minute: 2 },
now: { day: 2, hour: 23, minute: 3 },
expectedString: 'Opens in 59 minutes (today at 12:02 AM)',
expectedString: 'Opens in 59 minutes (tomorrow at 12:02 AM)',
},
{
isOpen: false,
Expand All @@ -53,19 +53,19 @@ test.each([
isOpen: false,
nextTime: { day: 1, hour: 0, minute: 0 },
now: { day: 0, hour: 0, minute: 0 },
expectedString: 'Opens in 1 day (today at 12:00 AM)',
expectedString: 'Opens in 1 day (tomorrow at 12:00 AM)',
},
{
isOpen: false,
nextTime: { day: 1, hour: 0, minute: 0 },
now: { day: 0, hour: 23, minute: 30 },
expectedString: 'Opens in 30 minutes (today at 12:00 AM)',
expectedString: 'Opens in 30 minutes (tomorrow at 12:00 AM)',
},
{
isOpen: false,
nextTime: { day: 1, hour: 0, minute: 0 },
now: { day: 0, hour: 20, minute: 30 },
expectedString: 'Opens in 3 hours (today at 12:00 AM)',
expectedString: 'Opens in 3 hours (tomorrow at 12:00 AM)',
},
{
isOpen: false,
Expand All @@ -83,13 +83,13 @@ test.each([
isOpen: false,
nextTime: { day: 1, hour: 2, minute: 0 },
now: { day: 0, hour: 0, minute: 30 },
expectedString: 'Opens in 1 day (today at 2:00 AM)',
expectedString: 'Opens in 1 day (tomorrow at 2:00 AM)',
},
{
isOpen: false,
nextTime: { day: 1, hour: 5, minute: 0 },
now: { day: 0, hour: 0, minute: 30 },
expectedString: 'Opens in 1 day (today at 5:00 AM)',
expectedString: 'Opens in 1 day (tomorrow at 5:00 AM)',
},
{
isOpen: false,
Expand All @@ -113,7 +113,7 @@ test.each([
isOpen: false,
nextTime: { day: 1, hour: 5, minute: 0 },
now: { day: 0, hour: 19, minute: 30 },
expectedString: 'Opens in 9 hours (today at 5:00 AM)',
expectedString: 'Opens in 9 hours (tomorrow at 5:00 AM)',
},
] satisfies IGetStatusMessageTest[])(
'#%# test of getStatusMessage | Now: $now | Next Time: $nextTime',
Expand Down

0 comments on commit 0aeaeef

Please sign in to comment.