feat: displaying episode publication as "dd mmm yyyy" instead of xyz ago (close #48)
All checks were successful
repod / xml (push) Successful in 28s
repod / php (push) Successful in 58s
repod / nodejs (push) Successful in 2m11s
repod / release (push) Has been skipped

This commit is contained in:
Michel Roux 2024-01-29 15:47:50 +01:00
parent 896fbf3e75
commit b63e1175a0
4 changed files with 36 additions and 8 deletions

View File

@ -4,7 +4,7 @@
<ul v-if="!loading"> <ul v-if="!loading">
<NcListItem v-for="feed in feeds" <NcListItem v-for="feed in feeds"
:key="feed.link" :key="feed.link"
:details="moment(feed.fetchedAtUnix*1000).fromNow()" :details="formatLocaleDate(new Date(feed.fetchedAtUnix*1000))"
:name="feed.title" :name="feed.title"
:to="toUrl(feed.link)"> :to="toUrl(feed.link)">
<template #icon> <template #icon>
@ -25,8 +25,8 @@ import { NcAvatar, NcListItem } from '@nextcloud/vue'
import Loading from '../Atoms/Loading.vue' import Loading from '../Atoms/Loading.vue'
import axios from '@nextcloud/axios' import axios from '@nextcloud/axios'
import { debounce } from '../../utils/debounce.js' import { debounce } from '../../utils/debounce.js'
import { formatLocaleDate } from '../../utils/time.js'
import { generateUrl } from '@nextcloud/router' import { generateUrl } from '@nextcloud/router'
import moment from '@nextcloud/moment'
import { showError } from '@nextcloud/dialogs' import { showError } from '@nextcloud/dialogs'
import { toUrl } from '../../utils/url.js' import { toUrl } from '../../utils/url.js'
@ -55,7 +55,7 @@ export default {
}, },
}, },
methods: { methods: {
moment, formatLocaleDate,
toUrl, toUrl,
search: debounce(async function value() { search: debounce(async function value() {
try { try {

View File

@ -6,7 +6,7 @@
:key="episode.guid" :key="episode.guid"
:active="isCurrentEpisode(episode)" :active="isCurrentEpisode(episode)"
:class="hasEnded(episode) ? 'ended': ''" :class="hasEnded(episode) ? 'ended': ''"
:details="moment(episode.pubDate.date).fromNow()" :details="formatLocaleDate(new Date(episode.pubDate.date))"
:force-display-actions="true" :force-display-actions="true"
:name="episode.name" :name="episode.name"
:title="episode.description" :title="episode.description"
@ -55,8 +55,8 @@ import PlayButton from 'vue-material-design-icons/Play.vue'
import StopButton from 'vue-material-design-icons/Stop.vue' import StopButton from 'vue-material-design-icons/Stop.vue'
import axios from '@nextcloud/axios' import axios from '@nextcloud/axios'
import { decodeUrl } from '../../utils/url.js' import { decodeUrl } from '../../utils/url.js'
import { formatLocaleDate } from '../../utils/time.js'
import { generateUrl } from '@nextcloud/router' import { generateUrl } from '@nextcloud/router'
import moment from '@nextcloud/moment'
import { showError } from '@nextcloud/dialogs' import { showError } from '@nextcloud/dialogs'
export default { export default {
@ -99,7 +99,7 @@ export default {
} }
}, },
methods: { methods: {
moment, formatLocaleDate,
hasEnded(episode) { hasEnded(episode) {
return episode.action && (episode.action.action === 'DELETE' || ( return episode.action && (episode.action.action === 'DELETE' || (
episode.action.position > 0 episode.action.position > 0

View File

@ -1,7 +1,7 @@
import axios from '@nextcloud/axios' import axios from '@nextcloud/axios'
import { decodeUrl } from '../utils/url.js' import { decodeUrl } from '../utils/url.js'
import { formatEpisodeTimestamp } from '../utils/time.js'
import { generateUrl } from '@nextcloud/router' import { generateUrl } from '@nextcloud/router'
import moment from '@nextcloud/moment'
import router from '../router.js' import router from '../router.js'
import store from './main.js' import store from './main.js'
@ -108,7 +108,7 @@ export const player = {
episode: context.state.episode.url, episode: context.state.episode.url,
guid: context.state.episode.guid, guid: context.state.episode.guid,
action: 'play', action: 'play',
timestamp: moment().format('YYYY-MM-DD[T]HH:mm:ss'), timestamp: formatEpisodeTimestamp(new Date()),
started: Math.round(context.state.started), started: Math.round(context.state.started),
position: Math.round(audio.currentTime), position: Math.round(audio.currentTime),
total: Math.round(audio.duration), total: Math.round(audio.duration),

View File

@ -1,3 +1,8 @@
/**
* Format a date to a timer
* @param {Date} date The date
* @return {string}
*/
export const formatTimer = (date) => { export const formatTimer = (date) => {
const minutes = date.getUTCMinutes().toString().padStart(2, 0) const minutes = date.getUTCMinutes().toString().padStart(2, 0)
const seconds = date.getUTCSeconds().toString().padStart(2, 0) const seconds = date.getUTCSeconds().toString().padStart(2, 0)
@ -9,3 +14,26 @@ export const formatTimer = (date) => {
return timer return timer
} }
/**
* Format a date to a usefull timestamp string for the gPodder API
* @param {Date} date The date
* @return {string}
*/
export const formatEpisodeTimestamp = (date) => {
const year = date.getFullYear()
const month = (date.getMonth() + 1).toString().padStart(2, '0')
const day = date.getDate().toString().padStart(2, '0')
const hours = date.getHours().toString().padStart(2, '0')
const mins = date.getMinutes().toString().padStart(2, '0')
const secs = date.getSeconds().toString().padStart(2, '0')
return `${year}-${month}-${day}T${hours}:${mins}:${secs}`
}
/**
* Format a date to a localized date string
* @param {Date} date The date
* @return {string}
*/
export const formatLocaleDate = (date) => date.toLocaleDateString(undefined, { dateStyle: 'medium' })