Skip to content

Commit 22ebf79

Browse files
authored
Merge pull request #57503 from nextcloud/chore/drop-moment
refactor: drop moment from new bundles
2 parents 9fde252 + a623bff commit 22ebf79

File tree

187 files changed

+226
-255
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

187 files changed

+226
-255
lines changed

apps/files_versions/src/components/VersionEntry.vue

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -139,8 +139,7 @@ import type { Version } from '../utils/versions.ts'
139139
import { getCurrentUser } from '@nextcloud/auth'
140140
import { formatFileSize, Permission } from '@nextcloud/files'
141141
import { loadState } from '@nextcloud/initial-state'
142-
import { t } from '@nextcloud/l10n'
143-
import moment from '@nextcloud/moment'
142+
import { getCanonicalLocale, t } from '@nextcloud/l10n'
144143
import { getRootUrl } from '@nextcloud/router'
145144
import { computed, nextTick, ref } from 'vue'
146145
import NcActionButton from '@nextcloud/vue/components/NcActionButton'
@@ -233,7 +232,13 @@ const versionAuthor = computed(() => {
233232
})
234233
235234
const versionHumanExplicitDate = computed(() => {
236-
return moment(props.version.mtime).format('LLLL')
235+
return new Date(props.version.mtime).toLocaleString(
236+
[getCanonicalLocale(), getCanonicalLocale().split('-')[0]!],
237+
{
238+
timeStyle: 'long',
239+
dateStyle: 'long',
240+
},
241+
)
237242
})
238243
239244
const downloadURL = computed(() => {

apps/files_versions/src/utils/versions.ts

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import type { FileStat, ResponseDataDetailed } from 'webdav'
99
import { getCurrentUser } from '@nextcloud/auth'
1010
import axios from '@nextcloud/axios'
1111
import { getClient } from '@nextcloud/files/dav'
12-
import moment from '@nextcloud/moment'
12+
import { getCanonicalLocale } from '@nextcloud/l10n'
1313
import { encodePath, join } from '@nextcloud/paths'
1414
import { generateRemoteUrl, generateUrl } from '@nextcloud/router'
1515
import davRequest from '../utils/davRequest.ts'
@@ -97,7 +97,7 @@ export async function restoreVersion(version: Version) {
9797
* @param node - The original node
9898
*/
9999
function formatVersion(version: Required<FileStat>, node: INode): Version {
100-
const mtime = moment(version.lastmod).unix() * 1000
100+
const mtime = Date.parse(version.lastmod)
101101
let previewUrl = ''
102102

103103
if (mtime === node.mtime?.getTime()) { // Version is the current one
@@ -119,7 +119,13 @@ function formatVersion(version: Required<FileStat>, node: INode): Version {
119119
author: version.props['version-author'] ? String(version.props['version-author']) : null,
120120
authorName: null,
121121
filename: version.filename,
122-
basename: moment(mtime).format('LLL'),
122+
basename: new Date(mtime).toLocaleString(
123+
[getCanonicalLocale(), getCanonicalLocale().split('-')[0]!],
124+
{
125+
timeStyle: 'long',
126+
dateStyle: 'medium',
127+
},
128+
),
123129
mime: version.mime,
124130
etag: `${version.props.getetag}`,
125131
size: version.size,

apps/user_status/src/services/clearAtService.js

Lines changed: 25 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,7 @@
33
* SPDX-License-Identifier: AGPL-3.0-or-later
44
*/
55

6-
import { t } from '@nextcloud/l10n'
7-
import moment from '@nextcloud/moment'
6+
import { formatRelativeTime, t } from '@nextcloud/l10n'
87
import { dateFactory } from './dateService.js'
98

109
/**
@@ -13,7 +12,7 @@ import { dateFactory } from './dateService.js'
1312
* @param {object | null} clearAt The clear-at config
1413
* @return {number | null}
1514
*/
16-
function getTimestampForClearAt(clearAt) {
15+
export function getTimestampForClearAt(clearAt) {
1716
if (clearAt === null) {
1817
return null
1918
}
@@ -27,8 +26,9 @@ function getTimestampForClearAt(clearAt) {
2726
if (clearAt.type === 'end-of') {
2827
switch (clearAt.time) {
2928
case 'day':
29+
return Math.floor(getEndOfDay(date).getTime() / 1000)
3030
case 'week':
31-
return Number(moment(date).endOf(clearAt.time).format('X'))
31+
return Math.floor(getEndOfWeek(date).getTime() / 1000)
3232
}
3333
}
3434
// This is not an officially supported type
@@ -47,7 +47,7 @@ function getTimestampForClearAt(clearAt) {
4747
* @param {object} clearAt The clearAt object
4848
* @return {string|null}
4949
*/
50-
function clearAtFormat(clearAt) {
50+
export function clearAtFormat(clearAt) {
5151
if (clearAt === null) {
5252
return t('user_status', 'Don\'t clear')
5353
}
@@ -65,23 +65,35 @@ function clearAtFormat(clearAt) {
6565
}
6666

6767
if (clearAt.type === 'period') {
68-
return moment.duration(clearAt.time * 1000).humanize()
68+
return formatRelativeTime(Date.now() + clearAt.time * 1000)
6969
}
7070

7171
// This is not an officially supported type
7272
// but only used internally to show the remaining time
7373
// in the Set Status Modal
7474
if (clearAt.type === '_time') {
75-
const momentNow = moment(dateFactory())
76-
const momentClearAt = moment(clearAt.time, 'X')
77-
78-
return moment.duration(momentNow.diff(momentClearAt)).humanize()
75+
return formatRelativeTime(clearAt.time * 1000)
7976
}
8077

8178
return null
8279
}
8380

84-
export {
85-
clearAtFormat,
86-
getTimestampForClearAt,
81+
/**
82+
* @param {Date} date - The date to calculate the end of the day for
83+
*/
84+
function getEndOfDay(date) {
85+
const endOfDay = new Date(date)
86+
endOfDay.setHours(23, 59, 59, 999)
87+
return endOfDay
88+
}
89+
90+
/**
91+
* Calculates the end of the week for a given date
92+
*
93+
* @param {Date} date - The date to calculate the end of the week for
94+
*/
95+
function getEndOfWeek(date) {
96+
const endOfWeek = getEndOfDay(date)
97+
endOfWeek.setDate(date.getDate() + ((endOfWeek.getFirstDay() - 1 - endOfWeek.getDay() + 7) % 7))
98+
return endOfWeek
8799
}
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
import{b as g,p as y,q as v,c as p,u as o,o as n,N as h,w as _,g as V,t as k,r as x,s as M,j as d,e as f,F as q,C as w,E as U,G as j}from"./runtime-dom.esm-bundler-BrYCUcZF.chunk.mjs";import{c as C}from"./index-FffHbzvj.chunk.mjs";import{a as E}from"./index-JpgrUA2Z-BU0x-nEh.chunk.mjs";import{t as s}from"./translation-DoG5ZELJ-Cr5LJw9O.chunk.mjs";import{g as N}from"./createElementId-DhjFt1I9-CmaX6aVQ.chunk.mjs";import{c as S}from"./NcNoteCard-CVhtNL04-DvQ-q8jC.chunk.mjs";import{N as A}from"./NcSelect-Czzsi3P_-DYeov0Mn.chunk.mjs";import{N as K}from"./NcCheckboxRadioSwitch-BCSKF7Tk-BfYgMYeK.chunk.mjs";import{N as z}from"./NcPasswordField-djttkA5Q-PPKLVftl.chunk.mjs";import{_ as B}from"./TrashCanOutline-Dy-u-_ok.chunk.mjs";import{a as c,C as b}from"./types-enGIHWiM.chunk.mjs";import{l as G}from"./logger-CrDakPzW.chunk.mjs";const P=g({__name:"ConfigurationEntry",props:y({configKey:{},configOption:{}},{modelValue:{type:[String,Boolean],default:""},modelModifiers:{}}),emits:["update:modelValue"],setup(e){const a=v(e,"modelValue");return(t,i)=>e.configOption.type!==o(c).Boolean?(n(),p(h(e.configOption.type===o(c).Password?o(z):o(B)),{key:0,modelValue:a.value,"onUpdate:modelValue":i[0]||(i[0]=l=>a.value=l),name:e.configKey,required:!(e.configOption.flags&o(b).Optional),label:e.configOption.value,title:e.configOption.tooltip},null,8,["modelValue","name","required","label","title"])):(n(),p(o(K),{key:1,modelValue:a.value,"onUpdate:modelValue":i[1]||(i[1]=l=>a.value=l),type:"switch",title:e.configOption.tooltip},{default:_(()=>[V(k(e.configOption.value),1)]),_:1},8,["modelValue","title"]))}}),R=g({__name:"AuthMechanismRsa",props:y({authMechanism:{}},{modelValue:{required:!0},modelModifiers:{}}),emits:["update:modelValue"],setup(e){const a=v(e,"modelValue"),t=x();M(t,()=>{t.value&&(a.value.private_key="",a.value.public_key="")});async function i(){try{const{data:l}=await C.post(N("/apps/files_external/ajax/public_key.php"),{keyLength:t.value});a.value.private_key=l.data.private_key,a.value.public_key=l.data.public_key}catch(l){G.error("Error generating RSA key pair",{error:l}),E(s("files_external","Error generating key pair"))}}return(l,m)=>(n(),d("div",null,[(n(!0),d(q,null,w(e.authMechanism.configuration,(r,u)=>U((n(),p(P,{key:r.value,modelValue:a.value[u],"onUpdate:modelValue":O=>a.value[u]=O,"config-key":u,"config-option":r},null,8,["modelValue","onUpdate:modelValue","config-key","config-option"])),[[j,!(r.flags&o(b).Hidden)]])),128)),f(o(A),{modelValue:t.value,"onUpdate:modelValue":m[0]||(m[0]=r=>t.value=r),clearable:!1,"input-label":o(s)("files_external","Key size"),options:[1024,2048,4096],required:""},null,8,["modelValue","input-label"]),f(o(S),{disabled:!t.value,wide:"",onClick:i},{default:_(()=>[V(k(o(s)("files_external","Generate keys")),1)]),_:1},8,["disabled"])]))}}),$=Object.freeze(Object.defineProperty({__proto__:null,default:R},Symbol.toStringTag,{value:"Module"}));export{$ as A,P as _};
2-
//# sourceMappingURL=AuthMechanismRsa-C7Dhz5x5.chunk.mjs.map
1+
import{b as g,p as y,q as v,c as p,u as o,o as n,N as h,w as _,g as V,t as k,r as x,s as M,j as d,e as f,F as q,C as w,E as U,G as j}from"./runtime-dom.esm-bundler-BrYCUcZF.chunk.mjs";import{c as C}from"./index-BfylblLb.chunk.mjs";import{a as E}from"./index-JpgrUA2Z-BFiKKJ1W.chunk.mjs";import{t as s}from"./translation-DoG5ZELJ-gw0g4US-.chunk.mjs";import{g as N}from"./createElementId-DhjFt1I9--Zqj3wLs.chunk.mjs";import{c as S}from"./NcNoteCard-CVhtNL04-hwuc093N.chunk.mjs";import{N as A}from"./NcSelect-Czzsi3P_-DLFUGW7z.chunk.mjs";import{N as K}from"./NcCheckboxRadioSwitch-BCSKF7Tk-yPckcGKs.chunk.mjs";import{N as z}from"./NcPasswordField-djttkA5Q-2g87vOpY.chunk.mjs";import{_ as B}from"./TrashCanOutline-CvWRJ8GE.chunk.mjs";import{a as c,C as b}from"./types-BoPN4zt3.chunk.mjs";import{l as G}from"./logger-CrDakPzW.chunk.mjs";const P=g({__name:"ConfigurationEntry",props:y({configKey:{},configOption:{}},{modelValue:{type:[String,Boolean],default:""},modelModifiers:{}}),emits:["update:modelValue"],setup(e){const a=v(e,"modelValue");return(t,i)=>e.configOption.type!==o(c).Boolean?(n(),p(h(e.configOption.type===o(c).Password?o(z):o(B)),{key:0,modelValue:a.value,"onUpdate:modelValue":i[0]||(i[0]=l=>a.value=l),name:e.configKey,required:!(e.configOption.flags&o(b).Optional),label:e.configOption.value,title:e.configOption.tooltip},null,8,["modelValue","name","required","label","title"])):(n(),p(o(K),{key:1,modelValue:a.value,"onUpdate:modelValue":i[1]||(i[1]=l=>a.value=l),type:"switch",title:e.configOption.tooltip},{default:_(()=>[V(k(e.configOption.value),1)]),_:1},8,["modelValue","title"]))}}),R=g({__name:"AuthMechanismRsa",props:y({authMechanism:{}},{modelValue:{required:!0},modelModifiers:{}}),emits:["update:modelValue"],setup(e){const a=v(e,"modelValue"),t=x();M(t,()=>{t.value&&(a.value.private_key="",a.value.public_key="")});async function i(){try{const{data:l}=await C.post(N("/apps/files_external/ajax/public_key.php"),{keyLength:t.value});a.value.private_key=l.data.private_key,a.value.public_key=l.data.public_key}catch(l){G.error("Error generating RSA key pair",{error:l}),E(s("files_external","Error generating key pair"))}}return(l,m)=>(n(),d("div",null,[(n(!0),d(q,null,w(e.authMechanism.configuration,(r,u)=>U((n(),p(P,{key:r.value,modelValue:a.value[u],"onUpdate:modelValue":O=>a.value[u]=O,"config-key":u,"config-option":r},null,8,["modelValue","onUpdate:modelValue","config-key","config-option"])),[[j,!(r.flags&o(b).Hidden)]])),128)),f(o(A),{modelValue:t.value,"onUpdate:modelValue":m[0]||(m[0]=r=>t.value=r),clearable:!1,"input-label":o(s)("files_external","Key size"),options:[1024,2048,4096],required:""},null,8,["modelValue","input-label"]),f(o(S),{disabled:!t.value,wide:"",onClick:i},{default:_(()=>[V(k(o(s)("files_external","Generate keys")),1)]),_:1},8,["disabled"])]))}}),$=Object.freeze(Object.defineProperty({__proto__:null,default:R},Symbol.toStringTag,{value:"Module"}));export{$ as A,P as _};
2+
//# sourceMappingURL=AuthMechanismRsa-e40gyg0q.chunk.mjs.map
File renamed without changes.

0 commit comments

Comments
 (0)