-
Notifications
You must be signed in to change notification settings - Fork 6
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 #237 from qqlexa/replace-moment-with-dayjs
Replace moment with dayjs
- Loading branch information
Showing
14 changed files
with
101 additions
and
106 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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,9 +1,36 @@ | ||
import axios from "axios"; | ||
let headers = {}; | ||
const BASE_URL = "https://api.campus.kpi.ua"; | ||
|
||
export const Http = axios.create({ | ||
baseURL: "https://api.campus.kpi.ua/", | ||
headers, | ||
}); | ||
const defaultHeaders = { | ||
"Content-Type": "application/json", | ||
}; | ||
|
||
interface FetchOptions extends RequestInit { | ||
headers?: Record<string, string>; | ||
} | ||
|
||
const fetchWrapper = async (requestUrl: string, options: FetchOptions = {}) => { | ||
const { headers = {}, ...restOptions } = options; | ||
|
||
const requestOptions: RequestInit = { | ||
...restOptions, | ||
headers: { | ||
...defaultHeaders, | ||
...headers, | ||
}, | ||
}; | ||
|
||
const url = BASE_URL + requestUrl; | ||
const response = await fetch(url, requestOptions); | ||
|
||
if (!response.ok) { | ||
throw new Error(`HTTP error! status: ${response.status} in request to ${url}`); | ||
} | ||
return await response.json(); | ||
}; | ||
|
||
const Http = { | ||
get: (url: string, options: FetchOptions = {}) => | ||
fetchWrapper(url, { ...options, method: 'GET' }), | ||
}; | ||
|
||
export default Http; |
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
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 |
---|---|---|
|
@@ -15,4 +15,4 @@ export const useCurrentDateParams = () => { | |
}, []); | ||
|
||
return dateParams; | ||
}; | ||
}; |
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,15 +1,26 @@ | ||
import moment from 'moment'; | ||
import dayjs from 'dayjs'; | ||
import { TIME_POINTS } from '../../common/constants/scheduleParams'; | ||
|
||
export const parseTime = (timeString: string) => { | ||
const [hours, minutes] = timeString.split(':').map(Number); | ||
|
||
const today = dayjs().startOf('day'); | ||
|
||
return today | ||
.hour(hours) | ||
.minute(minutes) | ||
.second(0); | ||
}; | ||
|
||
|
||
export const getActiveTimePoint = () => { | ||
const PAIR_DURATION_IN_MINUTES = 95; | ||
const now = moment(); | ||
const now = dayjs(); | ||
|
||
return TIME_POINTS.findIndex((timePoint) => { | ||
const timeNumbers = timePoint.split('.').map(item => +item); | ||
const pairStartDate = moment().set({ hours: timeNumbers[0], minutes: timeNumbers[1], seconds: 0 }); | ||
const pairEndDate = moment(pairStartDate).set({ minutes: timeNumbers[1] + PAIR_DURATION_IN_MINUTES }) | ||
const pairStartDate = parseTime(timePoint); | ||
const pairEndDate = pairStartDate.add(PAIR_DURATION_IN_MINUTES, 'minute'); | ||
|
||
return now.isBetween(pairStartDate, pairEndDate); | ||
}); | ||
}; | ||
}; |
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
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
Oops, something went wrong.