统一处理低版本safari浏览器Date兼容性问题

This commit is contained in:
Allen
2024-04-24 10:06:32 +08:00
parent 72088dff2e
commit e1524c26cd
6 changed files with 18 additions and 15 deletions

View File

@@ -171,6 +171,7 @@ export function formatDateDifference(dateString: string): string {
// return `${minutesDifference}分钟前`
// else
// return '刚刚'
if (!dateString)
return ''
return dayjs(dateString).fromNow()
}

View File

@@ -33,12 +33,16 @@ export function isToday(date: Date) {
)
}
// 计算时间差返回xx天/xx小时/xx分钟/xx秒
/**
* 计算时间差返回xx天/xx小时/xx分钟/xx秒
*
* @deprecated 建议使用:@core/utils/formatters.ts formatDateDifference
*/
export function calculateTimeDifference(inputTime: string): string {
if (!inputTime)
return ''
const inputDate = new Date(inputTime)
const inputDate = new Date(inputTime.replaceAll(/-/g, '/'))
const currentDate = new Date()
const timeDifference = currentDate.getTime() - inputDate.getTime()
@@ -70,7 +74,7 @@ export function calculateTimeDiff(inputTime: string): string {
return ''
// 使用当前时区
const inputDate = new Date(inputTime)
const inputDate = new Date(inputTime.replaceAll(/-/g, '/'))
const currentDate = new Date()
const timeDifference = currentDate.getTime() - inputDate.getTime()

View File

@@ -423,14 +423,14 @@ function getSeasonPoster(posterPath: string) {
function formatAirDate(airDate: string) {
if (!airDate)
return ''
const date = new Date(airDate)
const date = new Date(airDate.replaceAll(/-/g, '/'))
return `${date.getFullYear()}${date.getMonth() + 1}${date.getDate()}`
}
// 从yyyy-mm-dd中提取年份
function getYear(airDate: string) {
if (!airDate)
return ''
const date = new Date(airDate)
const date = new Date(airDate.replaceAll(/-/g, '/'))
return date.getFullYear()
}
</script>

View File

@@ -1,7 +1,7 @@
<script lang='ts' setup>
import { useToast } from 'vue-toast-notification'
import SubscribeEditDialog from '../dialog/SubscribeEditDialog.vue'
import { calculateTimeDifference } from '@/@core/utils'
import { formatDateDifference } from '@/@core/utils/formatters'
import { formatSeason } from '@/@core/utils/formatters'
import api from '@/api'
import type { Subscribe } from '@/api/types'
@@ -26,11 +26,9 @@ const subscribeEditDialog = ref(false)
// 上一次更新时间
const lastUpdateText = ref(
`${
props.media?.last_update
? `${calculateTimeDifference(props.media?.last_update || '')}`
: ''
}`,
props.media && props.media.last_update
? formatDateDifference(props.media.last_update)
: '',
)
// 图片加载完成响应

View File

@@ -1,5 +1,5 @@
<script lang="ts" setup>
import { calculateTimeDifference } from '@/@core/utils'
import { formatDateDifference } from '@/@core/utils/formatters'
import api from '@/api'
// 系统环境变量
@@ -62,7 +62,7 @@ async function queryAllRelease() {
// 计算发布时间
function releaseTime(releaseDate: string) {
// 上一次更新时间
return `${calculateTimeDifference(releaseDate)}`
return formatDateDifference(releaseDate)
}
onMounted(() => {

View File

@@ -100,7 +100,7 @@ function compareTime(time1: string, time2: string) {
return -1
if (!time2)
return 1
return new Date(time1).getTime() - new Date(time2).getTime()
return new Date(time1.replaceAll(/-/g, '/')).getTime() - new Date(time2.replaceAll(/-/g, '/')).getTime()
}
onBeforeUnmount(() => {