refactor: move moment stuff to utils

old-stable24
Varun Patil 2022-10-17 20:06:01 -07:00
parent 3b56446305
commit 3acf64e96e
2 changed files with 11 additions and 4 deletions

View File

@ -100,7 +100,6 @@ import { showError } from '@nextcloud/dialogs'
import { getCanonicalLocale } from '@nextcloud/l10n';
import { NcEmptyContent } from '@nextcloud/vue';
import GlobalMixin from '../mixins/GlobalMixin';
import moment from 'moment';
import { ViewerManager } from "../services/Viewer";
import { getLayout } from "../services/Layout";
@ -584,9 +583,7 @@ export default class Timeline extends Mixins(GlobalMixin, UserConfig) {
} else if (this.$route.name === 'thisday' && (!prevDay || Math.abs(prevDay.dayid - day.dayid) > 30)) {
// thisday view with new year title
head.size = 67;
const dateTaken = moment(utils.dayIdToDate(day.dayid));
const text = dateTaken.locale(getCanonicalLocale()).fromNow();
head.super = text.charAt(0).toUpperCase() + text.slice(1);
head.super = utils.getFromNowStr(utils.dayIdToDate(day.dayid));
}
// Add header to list

View File

@ -2,6 +2,7 @@ import { getCanonicalLocale } from "@nextcloud/l10n";
import { getCurrentUser } from '@nextcloud/auth'
import { loadState } from '@nextcloud/initial-state'
import { IPhoto } from "../types";
import moment from 'moment';
// Memoize the result of short date conversions
// These operations are surprisingly expensive
@ -45,6 +46,15 @@ export function getLongDateStr(date: Date, skipYear=false, time=false) {
});
}
/** Get text like "5 years ago" from a date */
export function getFromNowStr(date: Date) {
// Get fromNow in correct locale
const text = moment(date).locale(getCanonicalLocale()).fromNow();
// Title case
return text.charAt(0).toUpperCase() + text.slice(1);
}
/**
* Returns a hash code from a string
* @param {String} str The string to hash.