1
0
Fork 0
mirror of https://github.com/muerwre/vault-frontend.git synced 2025-04-25 04:46:40 +07:00

better prettydate for older dates

This commit is contained in:
Fedor Katurov 2019-11-27 10:10:50 +07:00
parent e3bfacddcb
commit aaa8eb5275

View file

@ -1,9 +1,12 @@
import { IFile, ValueOf } from '~/redux/types';
import formatDistanceToNow from 'date-fns/formatDistanceToNow';
import { ru } from 'date-fns/locale';
import isAfter from 'date-fns/isAfter';
import differenceInMonths from 'date-fns/differenceInMonths';
import ru from 'date-fns/locale/ru';
import Axios from 'axios';
import { PRESETS } from '~/constants/urls';
import { ICommentBlock, COMMENT_BLOCK_DETECTORS, COMMENT_BLOCK_TYPES } from '~/constants/comment';
import format from 'date-fns/format';
export const getStyle = (oElm: any, strCssRule: string) => {
if (document.defaultView && document.defaultView.getComputedStyle) {
@ -118,12 +121,19 @@ export const formatCommentText = (author: string, text: string): ICommentBlock[]
export const formatCellText = (text: string): string => formatText(text);
export const getPrettyDate = (date: string): string =>
formatDistanceToNow(new Date(date), {
export const getPrettyDate = (date: string): string => {
if (differenceInMonths(new Date(), new Date(date)) >= 3) {
return format(new Date(date), 'd MMMM yyyy', { locale: ru });
}
return isAfter(new Date(date), new Date())
? 'Только что'
: formatDistanceToNow(new Date(date), {
locale: ru,
includeSeconds: true,
addSuffix: true,
});
};
export const getYoutubeTitle = async (id: string) => {
Axios.get(`http://youtube.com/get_video_info?video_id=${id}`).then(console.log);