Skip to content

Instantly share code, notes, and snippets.

@malihassan20
Last active February 3, 2018 14:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save malihassan20/bd750b9c51f2ee519d406497fbefad08 to your computer and use it in GitHub Desktop.
Save malihassan20/bd750b9c51f2ee519d406497fbefad08 to your computer and use it in GitHub Desktop.
nextJs-tour-diary-app\Helper\Helper.js
import cookie from 'react-cookies';
export function getCurrentDate() {
const today = new Date();
let dd = today.getDate();
let mm = today.getMonth() + 1; //January is 0!
const yyyy = today.getFullYear();
if (dd < 10) {
dd = `0${dd}`;
}
if (mm < 10) {
mm = `0${mm}`;
}
return `${yyyy}-${mm}-${dd}`;
}
export function disabledDate(current) {
//disable future dates
return current && current.valueOf() > Date.now();
}
export function allowSpecificDates(current) {
const tour = cookie.load('tour');
//enable dates which are within the tour range dates
if (tour) {
return !(
current.valueOf() >= new Date(tour.metadata.start_date) &&
current.valueOf() <= new Date(tour.metadata.end_date)
);
}
//disable future dates
return current && current.valueOf() > Date.now();
}
export function sortArr(arr) {
//ascending order
return arr.sort((a, b) => new Date(a.metadata.date) - new Date(b.metadata.date));
}
export function getTourStartDate() {
const tour = cookie.load('tour');
//enable dates which are within the tour range dates
if (tour) {
return new Date(tour.metadata.start_date);
}
return getCurrentDate();
}
export function getCurrentTour() {
const tour = cookie.load('tour');
if (tour) {
return tour;
}
return null;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment