other moment functions to native

This commit is contained in:
feruz 2019-12-19 07:21:55 +02:00
parent c0ba58e7f4
commit 9da578a53e

View File

@ -1,15 +1,8 @@
import moment from 'moment'; import moment from 'moment';
const TODAY = moment().startOf('day'); const TODAY = new Date(); //moment().startOf('day');
const YESTERDAY = moment() const ONE_DAY = new Date(TODAY.getTime() - 24 * 60 * 60 * 1000);
.subtract(1, 'days') const SEVEN_DAY = new Date(TODAY.getTime() - 7 * 24 * 60 * 60 * 1000);
.startOf('day');
const THIS_WEEK = moment()
.subtract(7, 'days')
.startOf('day');
const THIS_MONTH = moment()
.subtract(1, 'M')
.startOf('day');
export const getTimeFromNow = (value, isWithoutUtc) => { export const getTimeFromNow = (value, isWithoutUtc) => {
if (!value) { if (!value) {
@ -33,13 +26,29 @@ export const getFormatedCreatedDate = value => {
export const isBefore = (a, b) => new Date(b) - new Date(a); export const isBefore = (a, b) => new Date(b) - new Date(a);
export const isToday = value => moment(value).isSame(TODAY, 'd'); export const isToday = value => {
const day = new Date(value);
return TODAY.getDate() === day.getDate() &&
TODAY.getMonth() === day.getMonth() &&
TODAY.getFullYear() === day.getFullYear()
? 1
: 0;
};
export const isYesterday = value => moment(value).isSame(YESTERDAY, 'd'); export const isYesterday = value => {
const day = new Date(value).getTime();
return day < TODAY.getTime() && day > ONE_DAY.getTime();
};
export const isThisWeek = value => moment(value).isSameOrAfter(THIS_WEEK); export const isThisWeek = value => {
const day = new Date(value).getTime();
return day < TODAY.getTime() && day > SEVEN_DAY.getTime();
};
export const isThisMonth = value => moment(value).isSameOrAfter(THIS_MONTH); export const isThisMonth = value => {
const day = new Date(value);
return TODAY.getMonth() === day.getMonth() && TODAY.getFullYear() === day.getFullYear() ? 1 : 0;
};
export const isEmptyContentDate = value => { export const isEmptyContentDate = value => {
if (!value) { if (!value) {