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:
parent
e3bfacddcb
commit
aaa8eb5275
1 changed files with 17 additions and 7 deletions
|
@ -1,9 +1,12 @@
|
||||||
import { IFile, ValueOf } from '~/redux/types';
|
import { IFile, ValueOf } from '~/redux/types';
|
||||||
import formatDistanceToNow from 'date-fns/formatDistanceToNow';
|
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 Axios from 'axios';
|
||||||
import { PRESETS } from '~/constants/urls';
|
import { PRESETS } from '~/constants/urls';
|
||||||
import { ICommentBlock, COMMENT_BLOCK_DETECTORS, COMMENT_BLOCK_TYPES } from '~/constants/comment';
|
import { ICommentBlock, COMMENT_BLOCK_DETECTORS, COMMENT_BLOCK_TYPES } from '~/constants/comment';
|
||||||
|
import format from 'date-fns/format';
|
||||||
|
|
||||||
export const getStyle = (oElm: any, strCssRule: string) => {
|
export const getStyle = (oElm: any, strCssRule: string) => {
|
||||||
if (document.defaultView && document.defaultView.getComputedStyle) {
|
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 formatCellText = (text: string): string => formatText(text);
|
||||||
|
|
||||||
export const getPrettyDate = (date: string): string =>
|
export const getPrettyDate = (date: string): string => {
|
||||||
formatDistanceToNow(new Date(date), {
|
if (differenceInMonths(new Date(), new Date(date)) >= 3) {
|
||||||
locale: ru,
|
return format(new Date(date), 'd MMMM yyyy', { locale: ru });
|
||||||
includeSeconds: true,
|
}
|
||||||
addSuffix: true,
|
|
||||||
});
|
return isAfter(new Date(date), new Date())
|
||||||
|
? 'Только что'
|
||||||
|
: formatDistanceToNow(new Date(date), {
|
||||||
|
locale: ru,
|
||||||
|
includeSeconds: true,
|
||||||
|
addSuffix: true,
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
export const getYoutubeTitle = async (id: string) => {
|
export const getYoutubeTitle = async (id: string) => {
|
||||||
Axios.get(`http://youtube.com/get_video_info?video_id=${id}`).then(console.log);
|
Axios.get(`http://youtube.com/get_video_info?video_id=${id}`).then(console.log);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue