Initial commit of akmon project

This commit is contained in:
2026-01-20 08:04:15 +08:00
commit 77a2bab985
1309 changed files with 343305 additions and 0 deletions

View File

@@ -0,0 +1,31 @@
## 0.1.52025-06-01
- feat: 支持传入纯数字的日期
## 0.1.42025-05-22
- fix: 修复uniapp x 缺少类型问题
## 0.1.32025-04-24
- fix: 修复uniapp v2 app 导出类型问题
## 0.1.22025-04-24
- fix: 修复uniapp v2 app报错的问题
## 0.1.12025-04-22
- fix: 修复uniapp app报错的问题
- feat: 兼容uniappx 鸿蒙next
## 0.1.02025-04-16
- fix: 修复locale en缺少`DayutsRelativeTime`
## 0.0.92025-03-05
- fix: 修复uniappx ios interface引入问题
## 0.0.82025-01-06
- fix: 修复uniapp app报错的问题
## 0.0.72024-12-27
- feat: 支持`hbx4.42`
## 0.0.62024-06-19
- feat: 支持`uniapp`
## 0.0.52024-05-02
- fix: 修复因安卓 `字面量 === 字面量``false`导致加减等操作不起作用。
## 0.0.42024-04-19
- fix: 修复`parseDate`数组长度判断时报错
## 0.0.32024-04-02
- fix: 因多写f导致运行不起来
## 0.0.22024-04-01
- chore: 兼容uniapp x ios(app-js)
## 0.0.12024-03-30
- init

View File

@@ -0,0 +1,32 @@
// @ts-nocheck
export const SECONDS_A_MINUTE = 60
export const SECONDS_A_HOUR = SECONDS_A_MINUTE * 60
export const SECONDS_A_DAY = SECONDS_A_HOUR * 24
export const SECONDS_A_WEEK = SECONDS_A_DAY * 7
export const MILLISECONDS_A_SECOND = 1e3
export const MILLISECONDS_A_MINUTE = SECONDS_A_MINUTE * MILLISECONDS_A_SECOND
export const MILLISECONDS_A_HOUR = SECONDS_A_HOUR * MILLISECONDS_A_SECOND
export const MILLISECONDS_A_DAY = SECONDS_A_DAY * MILLISECONDS_A_SECOND
export const MILLISECONDS_A_WEEK = SECONDS_A_WEEK * MILLISECONDS_A_SECOND
// English locales
export const MS = 'millisecond'
export const S = 'second'
export const MIN = 'minute'
export const H = 'hour'
export const D = 'day'
export const W = 'week'
export const M = 'month'
export const Q = 'quarter'
export const Y = 'year'
export const DATE = 'date'
export const FORMAT_DEFAULT = 'YYYY-MM-DDTHH:mm:ssZ'
export const INVALID_DATE_STRING = 'Invalid Date'
// regex
export const REGEX_PARSE = /^(\d{4})[-/]?(\d{1,2})?[-/]?(\d{0,2})[Tt\s]*(\d{1,2})?:?(\d{1,2})?:?(\d{1,2})?[.:]?(\d+)?$/
export const REGEX_FORMAT = /\[([^\]]+)]|Y{1,4}|M{1,4}|D{1,2}|d{1,4}|H{1,2}|h{1,2}|a|A|m{1,2}|s{1,2}|Z{1,2}|SSS/g
// export const REGEX_FORMAT = /(?:[^\]]+)|Y{1,4}|M{1,4}|D{1,2}|d{1,4}|H{1,2}|h{1,2}|a|A|m{1,2}|s{1,2}|Z{1,2}|SSS/g;

View File

@@ -0,0 +1,194 @@
// @ts-nocheck
import {dayuts, Dayuts} from "./index"
// import {DayutsConfig} from '../../types/date.uts'
import { DayutsConfig } from '../utssdk/interface'
export class Dates {
/**
* Dayuts实例
*/
newDate() : Dayuts;
newDate(date : string) : Dayuts;
newDate(date : any[]) : Dayuts;
newDate(date : number) : Dayuts;
newDate(date : UTSJSONObject) : Dayuts;
newDate(date : Date) : Dayuts;
newDate(date : Dayuts) : Dayuts;
// #ifndef APP-ANDROID || APP-IOS || APP-HARMONY
newDate(date : any | null, format : string) : Dayuts;
newDate(date : any | null, format : string | null, locale : string | null) : Dayuts;
// #endif
newDate(date : any | null = null, format : string | null = null, locale : string | null = null) : Dayuts {
if (date != null && date instanceof Dayuts) return date.clone()
return new Dayuts({
date,
format,
locale
} as DayutsConfig)
}
/**
* 万能转日期对象
* @param date 时间
*/
toDate(date : string) : Date {
date = date.split('周')[0].trim().split('星期')[0].trim().split('礼拜')[0].trim()
if (date == '') {
return new Date()
}
if (date.length >= 10 && /^\d+$/.test(date)) {
// 时间戳
let timestamp = parseInt(date)
// 若为unix秒时间戳则转为毫秒时间戳
if (/^\d{10}$/.test(timestamp.toString())) {
return new Date(timestamp * 1000)
} else {
return new Date(timestamp)
}
} else {
if (!date.includes('T')) {
// 容错
date = date.replace(/\//g, '-').
replace(/年/g, '-').
replace(/月/g, '-').
replace(/日/g, '').
replace(/时/g, ':').
replace(/分/g, ':').
replace(/秒/g, '').
replace(/^-+|-+$/g, '').
trim()
// 补全
if (date.length == 4) {
date += '-01-01 00:00:00'
} else if (date.length == 7) {
date += '-01 00:00:00'
} else if (date.length == 8) {
date = `${this.today()} ${date}`
} else if (date.length == 10) {
date += ' 00:00:00'
} else if (date.length == 13) {
date += ':00:00'
} else if (date.length == 16) {
date += ':00'
}
let d = date.split(/[^0-9]/)
try{
return new Date(parseInt(d[0]), parseInt(d[1]) - 1, parseInt(d[2]), parseInt(d[3]), parseInt(d[4]), parseInt(d[5]))
}catch(e){
console.error(`[ux-date]解析失败:${date}`)
return new Date()
}
} else {
return new Date(date)
}
}
}
/**
* 万能格式化日期
* @param date 时间
* @param format 格式化规则 支持yyyy-MM-dd|yyyy-MM-dd HH:mm:ss|yyyy/MM/dd|yyyy/MM/dd HH:mm:ss|yyyy年MM月dd日等组合 默认yyyy-mm-dd
*/
fmtDate(date : string, format : string) : string {
if(format == '') {
format = 'yyyy-MM-dd'
}
date = date.split('周')[0].trim().split('星期')[0].trim().split('礼拜')[0].trim()
let d = this.toDate(date)
let timeSource = new Map<string, string>()
timeSource.set('y', d.getFullYear().toString())
timeSource.set('M', (d.getMonth() + 1).toString().padStart(2, '0'))
timeSource.set('d', d.getDate().toString().padStart(2, '0'))
timeSource.set('H', d.getHours().toString().padStart(2, '0'))
timeSource.set('m', d.getMinutes().toString().padStart(2, '0'))
timeSource.set('s', d.getSeconds().toString().padStart(2, '0'))
let result = format.split('周')[0].trim().split('星期')[0].trim().split('礼拜')[0].trim()
timeSource.forEach((v : string, key : string) => {
const rets = new RegExp(`${key}+`).exec(result) ?? [] as RegExp[]
if (rets.length > 0) {
result = result.replace(rets[0].toString(), v)
}
})
let fmtWeek = format.indexOf('周') != -1 || format.indexOf('星期') != -1 || format.indexOf('礼拜') != -1
if(fmtWeek) {
result += ` ${this.weekName(this.toDate(result).getDay(), format)}`
}
return result
}
/**
* 现在 yyyy-MM-dd HH:mm:ss
*/
now() : string {
let date = new Date()
let year = date.getFullYear()
let month = `${date.getMonth() + 1}`.padStart(2, '0')
let day = `${date.getDate()}`.padStart(2, '0')
let hour = `${date.getHours()}`.padStart(2, '0')
let minute = `${date.getMinutes()}`.padStart(2, '0')
let second = `${date.getSeconds()}`.padStart(2, '0')
return `${year}-${month}-${day} ${hour}:${minute}:${second}`
}
/**
* 今天
* @param n n为负则代表取前n天为正则代表取后n天0则为今天
*/
today(n : number = 0) : string {
let date = new Date()
date.setDate(date.getDate() + n)
let year = date.getFullYear()
let month = `${date.getMonth() + 1}`.padStart(2, '0')
let day = `${date.getDate()}`.padStart(2, '0')
return `${year}-${month}-${day}`
}
/**
* 本周所有日期
*/
weeks() : string[] {
const fDate = new Date()
const eDate = new Date()
fDate.setDate(fDate.getDate() - fDate.getDay() + 1)
eDate.setDate(eDate.getDate() - eDate.getDay() + 7)
const result : string[] = []
for (let d = fDate; d.getTime() <= eDate.getTime(); d.setDate(d.getDate() + 1)) {
result.push(d.toISOString().slice(0, 10))
}
return result;
}
/**
* 周几
*/
weekName(day: number, format: string) : string {
if(format.indexOf('星期') != -1) {
return ['星期天', '星期一', '星期二', '星期三', '星期四', '星期五', '星期六'][day]
} else if(format.indexOf('礼拜') != -1 ) {
return ['礼拜天', '礼拜一', '礼拜二', '礼拜三', '礼拜四', '礼拜五', '礼拜六'][day]
} else {
return ['周日', '周一', '周二', '周三', '周四', '周五', '周六'][day]
}
}
}

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,57 @@
// @ts-nocheck
import type { DayutsLocale, DayutsRelativeTime} from '../../../utssdk/interface'
/**
* 英语本地化对象。
*/
export default {
name: 'en',
/**
* 星期名称数组。
*/
weekdays: ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'],
/**
* 月份名称数组。
*/
months: [
'January',
'February',
'March',
'April',
'May',
'June',
'July',
'August',
'September',
'October',
'November',
'December',
],
relativeTime: {
future: 'in %s',
past: '%s ago',
s: 'a few seconds',
m: 'a minute',
mm: '%d minutes',
h: 'an hour',
hh: '%d hours',
d: 'a day',
dd: '%d days',
M: 'a month',
MM: '%d months',
y: 'a year',
yy: '%d years'
} as DayutsRelativeTime,
/**
* 序数函数,用于将数字转换为带有序数后缀的字符串。
*
* @param {number} n - 要转换的数字。
* @returns {string} 带有序数后缀的字符串。
*/
ordinal: (n : number, _ : string) : string => {
const s = ['th', 'st', 'nd', 'rd']
const v = n % 100
const i = (v - 20) % 10
const k = i < s.length ? i : v < s.length ? v : 0
return `[${n}${(s[k])}]`
},
} as DayutsLocale

View File

@@ -0,0 +1,75 @@
// @ts-nocheck
import type { DayutsLocale, DayutsRelativeTime, DayutsFormats } from '../../../utssdk/interface'
const locale : DayutsLocale = {
name: 'zh-cn',
weekdays: ['星期日', '星期一', '星期二', '星期三', '星期四', '星期五', '星期六'],
weekdaysShort: ['周日', '周一', '周二', '周三', '周四', '周五', '周六'],
weekdaysMin: ['日', '一', '二', '三', '四', '五', '六'],
months: [
'一月', '二月', '三月', '四月', '五月', '六月',
'七月', '八月', '九月', '十月', '十一月', '十二月'
],
monthsShort: [
'1月', '2月', '3月', '4月', '5月', '6月',
'7月', '8月', '9月', '10月', '11月', '12月'
],
ordinal: (number:number, period:string):string => {
// switch (period) {
// case 'W':
// return `${number}周`;
// default:
// return `${number}日`;
// }
if(period == 'W'){
return `${number}`;
}
return `${number}`
},
weekStart: 1,
yearStart: 4,
formats: {
LT: 'HH:mm',
LTS: 'HH:mm:ss',
L: 'YYYY/MM/DD',
LL: 'YYYY年M月D日',
LLL: 'YYYY年M月D日Ah点mm分',
LLLL: 'YYYY年M月D日ddddAh点mm分',
l: 'YYYY/M/D',
ll: 'YYYY年M月D日',
lll: 'YYYY年M月D日 HH:mm',
llll: 'YYYY年M月D日dddd HH:mm'
} as DayutsFormats,
relativeTime: {
future: '%s内',
past: '%s前',
s: '几秒',
m: '1 分钟',
mm: '%d 分钟',
h: '1 小时',
hh: '%d 小时',
d: '1 天',
dd: '%d 天',
M: '1 个月',
MM: '%d 个月',
y: '1 年',
yy: '%d 年'
} as DayutsRelativeTime,
meridiem: (hour:number, minute:number, _ : boolean):string => {
const hm = (hour * 100) + minute;
if (hm < 600) {
return '凌晨';
} else if (hm < 900) {
return '早上';
} else if (hm < 1100) {
return '上午';
} else if (hm < 1300) {
return '中午';
} else if (hm < 1800) {
return '下午';
}
return '晚上';
}
};
export default locale;

View File

@@ -0,0 +1,104 @@
// @ts-nocheck
import { dayuts } from "./index"
// import { Dates } from "./dates"
import { dayutsIntl } from './use'
console.log('dayuts:::test::12')
// console.log('format1', dayuts().format())
console.log('string number', dayuts(`${Date.now()}`))
console.log('format1', dayuts('2018-04-04T16:00:00.000Z'))
console.log('format1', dayuts('2018 三月 15', 'YYYY MMMM DD', 'zh-cn'))
console.log('format2', dayuts([2010, 1, 14, 15, 25, 50, 125]))
console.log('format1', dayuts('1970-00-00', 'YYYY-MM-DD'))
console.log('format1', dayuts(1318781876406))
console.log('format1', dayuts(new Date(2018, 8, 18)))
console.log('format1', dayuts([2010, 1, 14, 15, 25, 50, 125]))
console.log('millisecond2', dayuts().millisecond())
console.log('millisecond2', dayuts().millisecond(1))
console.log('second2', dayuts().second())
console.log('second2', dayuts().second(1))
console.log('minute2', dayuts().minute())
console.log('minute2', dayuts().minute(1))
console.log('hour2', dayuts().hour())
console.log('hour2', dayuts().hour(12))
console.log('date2', dayuts().date())
console.log('date2', dayuts().date(1))
console.log('dayOfYear', dayuts().dayOfYear())
console.log('dayOfYear', dayuts().dayOfYear(1))
console.log('month', dayuts().month())
console.log('month', dayuts().month(1))
console.log('year', dayuts().year())
console.log('year', dayuts().year(2000))
console.log(dayuts().get('year'))
console.log(dayuts().get('month')) // start 0
console.log(dayuts().get('date'))
console.log(dayuts().get('hour'))
console.log(dayuts().get('minute'))
console.log(dayuts().get('second'))
console.log(dayuts().get('millisecond'))
console.log('add', dayuts().add(7, 'day'))
// console.log('add1', new Dates().newDate().add(7, 'day').format('YYYY-MM-DD'))
console.log('subtract', dayuts().subtract(7, 'year'))
console.log('startOf', dayuts().startOf('year'))
console.log('endOf', dayuts().endOf('month'))
console.log('format', dayuts().format())
console.log('format', dayuts('2019-01-25').format('[YYYYescape] YYYY-MM-DDTHH:mm:ssZ[Z]'))
console.log('format', dayuts('2019-01-25').format('DD/MM/YYYY'))
console.log('fromNow:1', dayuts('1999-01-01').fromNow())
console.log('fromNow:1', dayuts('1999-01-01').fromNow(true))
console.log('fromNow:1', dayuts('2024-03-29').fromNow(true))
console.log('from1', dayuts('1999-01-01').from(dayuts()))
console.log('from1', dayuts('1999-01-01').from(dayuts(), true))
console.log('toNow1', dayuts('1999-01-01').toNow(true))
console.log('toNow1', dayuts('1999-01-01').to(dayuts()))
console.log('diff1', dayuts('2019-01-25').diff(dayuts('2018-06-05')))
console.log('diff1', dayuts('2019-01-25').diff(dayuts('2018-06-05'), 'month'))
console.log('diff1', dayuts('2019-01-25').diff(dayuts('2018-06-05'), 'month', true))
console.log('valueOf', dayuts('2019-01-25').valueOf())
console.log('unix', dayuts('2019-01-25').unix())
console.log('daysInMonth', dayuts('2019-01-25').daysInMonth())
console.log('toDate', dayuts().toDate())
console.log('toArray', dayuts().toArray())
console.log('toJSON', dayuts().toJSON())
console.log('toObject', dayuts().toObject())
console.log('toString', dayuts().toString())
console.log('isBefore', dayuts().isBefore(dayuts('2011-01-01')))
console.log('isBefore', dayuts().isBefore('2011-01-01', 'month'))
console.log('isSame', dayuts().isSame(dayuts('2011-01-01')))
console.log('isSame', dayuts().isSame('2011-01-01', 'year'))
console.log('isAfter', dayuts().isAfter(dayuts('2011-01-01')))
console.log('isAfter', dayuts().isAfter('2011-01-01', 'month'))
console.log('isSameOrBefore', dayuts().isSameOrBefore(dayuts('2011-01-01')))
console.log('isSameOrBefore', dayuts().isSameOrBefore('2011-01-01', 'month'))
console.log('isSameOrBefore', dayuts().isSameOrAfter(dayuts('2011-01-01')))
console.log('isSameOrBefore', dayuts().isSameOrAfter('2011-01-01', 'month'))
console.log('isBetween', dayuts('2010-10-20').isBetween('2010-10-19', dayuts('2010-10-25')))
console.log('isBetween', dayuts().isBetween('2010-10-19', '2010-10-25', 'month'))
console.log('isBetween', dayuts('2016-10-30').isBetween('2016-01-01', '2016-10-30', 'day', '[)'))
console.log('isLeapYear', dayuts().isLeapYear())
console.log('isToday', dayuts().isToday())
// const a = dayuts('1999-01-01')
// const b = dayuts()
// console.log('fromNow:1',a.diff(b, 'year', true))
// console.log('a', a)
// console.log('b', b)
// console.log('fromNow:2',a.diff(b, 'year', true))
dayutsIntl.locale = 'zh-cn'
console.log('new::1', dayuts().$L)
// setTimeout(()=>{
// console.log('new::23')
// },100)
export const test = (n : number) : number => {
switch (n) {
case 1:
return 1
default:
return 0
}
}
console.log('test::::', test(1))

View File

@@ -0,0 +1,63 @@
// @ts-nocheck
import {DayutsLocale} from '../utssdk/interface'
import en from './locale/en'
import zhCn from './locale/zh-cn'
// #ifndef UNI-APP-X
// #ifdef VUE2
import {reactive} from '@vue/composition-api'
// #endif
// #ifdef VUE3
import {reactive} from 'vue'
// #endif
// #endif
const localesMap = new Map<string, DayutsLocale>()
//定义一个大写的State类型
type LocaleState = {
lang: string;
locales: Map<string, DayutsLocale>
}
export let localeState = reactive({
lang: 'en',
locales: localesMap
} as LocaleState)
localeState.locales.set('en', en)
localeState.locales.set('zh-cn', zhCn)
class DayutsIntl {
constructor(){}
use(locale:DayutsLocale):DayutsIntl{
localeState.locales.set(locale.name, locale)
return this
}
set locale(locale: string){
if(localeState.locales.has(locale)){
localeState.lang = locale
} else {
let list:string[] = []
localeState.locales.forEach(function(_:any,key:string){
list.push(key)
})
console.warn(`未知语言: "${locale}". 请使用以下已知语言之一:${list.join(', ')}`);
}
}
get locale(): string{
return localeState.lang
}
set(name: string, locale:DayutsLocale){
localeState.locales.set(name, locale)
}
has(name: string):boolean{
return localeState.locales.has(name)
}
}
export const dayutsIntl = new DayutsIntl()
// const dyauts = use(xx).use(xx).use(xx).use(xx)
// dyauts.locale ='zh'

View File

@@ -0,0 +1,106 @@
// @ts-nocheck
import { Dayuts } from './index'
import { M, Y, W, D, DATE, H, MIN, S, MS, Q } from './constant'
import {DayutsUnit} from '../utssdk/interface'
/**
* 用指定字符串填充目标字符串的开头,以达到指定的总长度。
*
* @param {string} string - 需要填充的目标字符串。
* @param {number} length - 填充后的总长度。
* @param {string} pad - 用于填充的字符串。
* @returns {string} 填充后的字符串。
*/
function padStart(string : string, length : number, pad : string) : string {
const str = string//`${string}`
if (str.length >= length) return str
return str.padStart(length, pad) //`${Array((length + 1) - string.length).join(pad)}${string}`
}
export {
padStart
}
function padZoneStr(instance : Dayuts) : string {
const negMinutes = -instance.utcOffset()
const minutes = Math.abs(negMinutes)
const hourOffset = Math.floor(minutes / 60)
const minuteOffset = minutes % 60
return `${negMinutes <= 0 ? '+' : '-'}${padStart(hourOffset.toString(), 2, '0')}:${padStart(minuteOffset.toString(), 2, '0')}`
}
export {
padZoneStr
}
// export function isNull(s): boolean{
// return s == null
// }
export function isNumber(value : any | null) : boolean {
// #ifdef APP-ANDROID
return ['Byte', 'UByte', 'Short', 'UShort', 'Int', 'UInt', 'Long', 'ULong', 'Float', 'Double', 'number'].includes(typeof value)
// #endif
// #ifdef APP-IOS
return ['Int8', 'UInt8', 'Int16', 'UInt16', 'Int32', 'UInt32', 'Int64', 'UInt64', 'Int', 'UInt', 'Float', 'Float16', 'Float32', 'Float64', 'Double', 'number'].includes(typeof value)
// #endif
// #ifndef APP-ANDROID || APP-IOS
return typeof value === 'number' && !isNaN(value);
// #endif
}
/**
* 将给定的时间单位转换为标准格式。
*
* @param {string} u - 要转换的时间单位。
* @returns {string} 返回转换后的时间单位。
*/
export function prettyUnit(u : string) : DayutsUnit {
const special = new Map<string, string>([
['M', M],
['y', Y],
['w', W],
['d', D],
['D', DATE],
['h', H],
['m', MIN],
['s', S],
['ms', MS],
['Q', Q]
])
return (special.get(u) ?? `${u}`.toLowerCase().replace(/s$/, '')) as DayutsUnit
}
/**
* 计算两个日期之间的月份差值
* @param {Dayjs} a - 第一个日期
* @param {Dayjs} b - 第二个日期
* @returns {number} 返回两个日期之间的月份差值
*/
export function monthDiff(a : Dayuts, b : Dayuts) : number {
// 该函数来自 moment.js以保持相同的结果
if (a.date() < b.date()) return -monthDiff(b, a)
const wholeMonthDiff = ((b.year() - a.year()) * 12) + (b.month() - a.month())
const anchor = a.clone().add(wholeMonthDiff, M).valueOf()
const c = b.valueOf() - anchor < 0
const anchor2 = a.clone().add(wholeMonthDiff + (c ? -1 : 1), M).valueOf()
// return +(-(wholeMonthDiff + ((b.valueOf() - anchor) / (c ? (anchor - anchor2) :
// (anchor2 - anchor)))) || 0)
const decimalMonthDiff = (b.valueOf() - anchor) / (c ? (anchor - anchor2) : (anchor2 - anchor));
const result = wholeMonthDiff + decimalMonthDiff;
const negatedResult = -result;
const absResult = +negatedResult;
const finalResult = !isNaN(absResult) ? absResult : 0;
return finalResult;
}
/**
* 返回向下取整的绝对值
* @param {number} n - 输入的数字
* @returns {number} 返回向下取整的绝对值
*/
export function absFloor(n : number):number {
// return (n < 0 ? Math.ceil(n) || 0 : Math.floor(n))
return (n < 0 ? Math.max(Math.ceil(n), 0) : Math.floor(n))
}

View File

@@ -0,0 +1,6 @@
// @ts-nocheck
export * from './common'
export * from './common/use'
// #ifndef VUE2
export * from './utssdk/interface'
// #endif

View File

@@ -0,0 +1,86 @@
{
"id": "lime-dayuts",
"displayName": "lime-dayuts dayjs 日期库",
"version": "0.1.5",
"description": "lime-dayuts 是dayjs的uts版一个轻量的处理时间和日期的 UTS 库几乎和dayjs保持一样的API",
"keywords": [
"lime-dayuts",
"dayjs",
"日期",
"时间格式化"
],
"repository": "",
"engines": {
"HBuilderX": "^4.14"
},
"dcloudext": {
"type": "uts",
"sale": {
"regular": {
"price": "0.00"
},
"sourcecode": {
"price": "0.00"
}
},
"contact": {
"qq": ""
},
"declaration": {
"ads": "无",
"data": "无",
"permissions": "无"
},
"npmurl": ""
},
"uni_modules": {
"dependencies": [],
"encrypt": [],
"platforms": {
"cloud": {
"tcb": "y",
"aliyun": "y",
"alipay": "n"
},
"client": {
"Vue": {
"vue2": "y",
"vue3": "y"
},
"App": {
"app-android": "y",
"app-ios": "y",
"app-harmony": "y"
},
"H5-mobile": {
"Safari": "y",
"Android Browser": "y",
"微信浏览器(Android)": "y",
"QQ浏览器(Android)": "y"
},
"H5-pc": {
"Chrome": "y",
"IE": "y",
"Edge": "y",
"Firefox": "y",
"Safari": "y"
},
"小程序": {
"微信": "y",
"阿里": "u",
"百度": "u",
"字节跳动": "u",
"QQ": "u",
"钉钉": "u",
"快手": "u",
"飞书": "u",
"京东": "u"
},
"快应用": {
"华为": "u",
"联盟": "u"
}
}
}
}
}

View File

@@ -0,0 +1,441 @@
# lime-dayuts 日期库
- lime-dayuts 是dayjs的uts版一个轻量的处理时间和日期的 UTS 库几乎和dayjs保持一样的API
## 文档
[dayuts](https://limex.qcoon.cn/uts/dayuts.html)
## 安装
插件市场导入插件即可
## 使用
```ts
import {dayuts} from '@/uni_modules/lime-dayuts';
dayuts().format() // 2024-03-25T02:10:16+08:00
```
## 解析
接受 `string``number``Date``Dayuts`等值传入,返回
### 当前时间
空值 `dayuts()` 将返回一个包含当前日期和时间的 `Dayuts` 对象。
```ts
dayuts()
```
### 字符串
```ts
dayuts('2024-03-04T16:00:00.000Z')
dayuts('2024-03-13 19:18:17.040+02:00')
dayuts('2024-03-13 19:18')
dayuts('1748750498228')
```
### 字符串+格式
```ts
dayuts('1970-00-00', 'YYYY-MM-DD')
```
#### 支持的解析占位符列表
| 输入 | 示例 | 描述 |
| ------ | ---------------- | --------------------------------- |
| `YY` | 01 | 两位数的年份 |
| `YYYY` | 2001 | 四位数的年份 |
| `M` | 1-12 | 月份从1开始计数 |
| `MM` | 01-12 | 月份,两位数 |
| `MMM` | Jan-Dec | 缩写的月份名称 |
| `MMMM` | January-December | 完整的月份名称 |
| `D` | 1-31 | 一个月的某一天 |
| `DD` | 01-31 | 一个月的某一天,两位数 |
| `H` | 0-23 | 小时数 |
| `HH` | 00-23 | 小时数,两位数 |
| `h` | 1-12 | 12小时制的小时数 |
| `hh` | 01-12 | 12小时制的小时数两位数 |
| `m` | 0-59 | 分钟数 |
| `mm` | 00-59 | 分钟数,两位数 |
| `s` | 0-59 | 秒数 |
| `ss` | 00-59 | 秒数,两位数 |
| `S` | 0-9 | 百毫秒数,一位数 |
| `SS` | 00-99 | 十毫秒数,两位数 |
| `SSS` | 000-999 | 毫秒数,三位数 |
| `Z` | -05:00 | 相对于UTC的偏移量 |
| `ZZ` | -0500 | 相对UTC的紧凑偏移量两位数 |
| `A` | AM PM | 上午或下午,大写字母 |
| `a` | am pm | 上午或下午,小写字母 |
| `ddd` | 周一 | 周,需要设置`locale = 'zh-cn'` , 默认为英文 |
| `dddd` | 星期一 | 星期 ,需要设置`locale = 'zh-cn'`, 默认为英文 |
### Unix 时间戳 (毫秒)
```ts
dayuts(1318781876406)
```
### Date 对象
```ts
dayuts(new Date(2018, 8, 18))
```
### 数组
```ts
dayuts([2010, 1, 14, 15, 25, 50, 125]);
```
## 取值/赋值
在设计上 Dayuts 的 getter 和 setter 使用了相同的 API也就是说不传参数调用方法即为 getter调用并传入参数为 setter。
### 毫秒 Millisecond
获取或设置毫秒。传入0到999的数字。 如果超出这个范围,它会进位到秒。
```ts
dayuts().millisecond() // gets current millisecond
dayuts().millisecond(1) // returns new dayuts
```
### 秒 Second
获取或设置秒。传入0到59的数字。 如果超出这个范围,它会进位到分钟。
```ts
dayuts().second() // gets current second
dayuts().second(1) // returns new dayuts
```
### 分 Minute
获取或设置分钟。传入0到59的数字。 如果超出这个范围,它会进位到小时。
```ts
dayuts().minute() // gets current minute
dayuts().minute(1) // returns new dayuts
```
### 时 Hour
获取或设置小时。传入0到23的数字。 如果超出这个范围,它会进位到天数。
```ts
dayuts().hour() // gets current hour
dayuts().hour(12) // returns new dayuts
```
### 一个月中的第几天 Date of Month
获取或设置一个月中的某一天。接受从1到31的数字。如果超出范围它将溢出到月份
```ts
dayuts().date() // gets current date
dayuts().date(12) // returns new dayuts
```
### 一周中的第几天 Day of Week
获取或设置一周中的某一天。接受从0星期日到6星期六的数字。如果超出范围它将溢出到其他周
```ts
dayuts().day() // gets current day
dayuts().day(0) // returns new dayuts
```
### 一年的第几天 Day of Year
获取或设置年份里第几天。传入1到366的数字。如果超出这个范围它会进位到下一年。
```ts
dayuts().dayOfYear()
dayuts().dayOfYear(365) // returns new dayuts
```
### 月 Month
获取或设置月份。传入0到11的 number。 如果超出这个范围,它会进位到年份。
```ts
dayuts().month() // gets current month
dayuts().month(0) // returns new dayuts
```
### 年 Year
获取或设置年份。
```ts
dayuts().year() // gets current year
dayuts().year(2000) // returns new dayuts
```
### Get/Set
获取和设置相应信息。
```ts
dayuts().get('year')
dayuts().get('month') // start 0
dayuts().get('date')
dayuts().get('hour')
dayuts().get('minute')
dayuts().get('second')
dayuts().get('millisecond')
dayuts().set('date', 1)
dayuts().set('month', 3) // 四月
dayuts().set('second', 30)
```
## 操作
### 增加 Add
返回增加一定时间的复制的 dayuts 对象。
```ts
dayuts().add(7, 'day')
```
### 减去 Subtract
返回增加一定时间的复制的 dayuts 对象。
```ts
dayuts().subtract(7, 'year')
```
#### 所有可用单位的列表
| 单位 | 缩写 | 描述 |
| ------------- | --------- | ---------------------------------------- |
| `day` | `d` | 日 |
| `week` | `w` | 周 |
| `month` | `M` | 月 |
| `year` | `y` | 年 |
| `hour` | `h` | 小时 |
| `minute` | `m` | 分钟 |
| `second` | `s` | 秒 |
| `millisecond` | `ms` | 毫秒 |
### 时间的开始 Start of Time
设置到一个时间的开始。
```ts
dayuts().startOf('year')
```
### 时间的结束 End of Time
设置到一个时间的末尾。
```ts
dayuts().endOf('month')
```
#### 所有可用单位的列表
| 单位 | 缩写 | 描述 |
| ------------- | --------- | ----------------------------------------- |
| `year` | `y` | 当年1月1日 00:00 |
| `quarter` | `Q` | 当前季度的开始月份的第一天00:00 @>>QuarterOfYear|
| `month` | `M` | 当月的第一天00:00 |
| `week` | `w` | 当周的第一天00:00 (根据地区设置) |
| `date` | `D` | 今天 00:00 |
| `day` | `d` | 今天 00:00 |
| `hour` | `h` | 现在但是分钟、秒和毫秒都为0 |
| `minute` | `m` | 现在但是秒和毫秒都为0 |
| `second` | `s` | 现在但是毫秒为0 |
## 显示
### 格式化 Format
根据传入的占位符返回格式化后的日期。
将字符放在方括号中,即可原样返回而不被格式化替换 (例如, [MM])
```ts
dayuts().format() // 默认返回的是 ISO8601 格式字符串 '2024-03-28T01:33:29+08:00'
// app 暂不支持
dayuts('2019-01-25').format('[YYYYescape] YYYY-MM-DDTHH:mm:ssZ[Z]')
// 'YYYYescape 2019-01-25T00:00:00-02:00Z'
dayuts('2019-01-25').format('DD/MM/YYYY') // '25/01/2019'
```
### 相对当前时间(前) Time from now
返回现在到当前实例的相对时间。
```ts
dayuts('1999-01-01').fromNow() // 25 years ago
//如果传入 true则可以获得不带后缀的值。
dayuts('1999-01-01').fromNow(true) // 25 years
```
### 相对指定时间(前) Time from X
返回 X 到当前实例的相对时间。
```ts
dayuts('1999-01-01').from(dayuts()) // 25 years ago
//如果传入 true则可以获得不带后缀的值。
dayuts('1999-01-01').from(dayuts(), true) // 25 years
```
### 相对当前时间(后) Time to now
返回当前实例到现在的相对时间。
```ts
dayuts('1999-01-01').toNow() // in 25 years
//如果传入 true则可以获得不带后缀的值。
dayuts('1999-01-01').toNow(true) // 25 years
```
### 相对指定时间(后) Time to X
返回当前实例到 X 的相对时间。
```ts
dayuts('1999-01-01').to(dayuts()) // in 25 years
//如果传入 true则可以获得不带后缀的值。
dayuts('1999-01-01').to(true) // 25 years
```
### 差异 Diff
返回指定单位下两个日期时间之间的差异。
```ts
dayuts('2019-01-25')
.diff(dayuts('2018-06-05')) // 20214000000 默认单位是毫秒
// 要获取其他单位下的差异,则在第二个参数传入相应的单位。
dayuts('2019-01-25')
.diff(dayuts('2018-06-05'), 'month') // 7
// 如果要得到一个浮点数,将 true 作为第三个参数传入。
dayuts('2019-01-25')
.diff(dayuts('2018-06-05'), 'month', true) // 7.645161290322581
```
### Unix 时间戳 (毫秒)
返回当前实例的 UNIX 时间戳13位数字毫秒
```ts
dayuts('2019-01-25').valueOf() //1548345600000
```
### Unix 时间戳
返回当前实例的 UNIX 时间戳10位数字秒。
```ts
dayuts('2019-01-25').unix() // 1548345600
```
### 月份的天数
获取当前月份包含的天数。
```ts
dayuts('2019-01-25').daysInMonth() //31
```
### 转Date
从 Dayuts 对象中获取原生的 Date 对象
```ts
dayuts().toDate()
```
### 转Array
返回一个包含各个时间信息的 Array
```ts
dayuts().toArray() //[2024, 2, 29, 2, 57, 28, 775]
```
### 转JSON
序列化为 `ISO 8601` 格式的字符串
```ts
dayuts('2019-01-25').toJSON() // '2019-01-25T02:00:00.000Z'
```
### 转Object
返回包含时间信息的 Object
```ts
dayuts('2019-01-25').toObject() // { years: 2019, months: 0, date: 25, hours: 0, minutes: 0, seconds: 0, milliseconds: 0 }
```
### 转字符串
返回包含时间信息的 string
```ts
dayuts('2019-01-25').toString() // Fri Mar 29 2024 03:20:40 GMT+0800
```
## 查询
### 是否在前 Is Before
这表示 Dayuts 对象是否在另一个提供的日期时间之前。
```ts
// 默认使用毫秒比较
dayuts().isBefore(dayuts('2011-01-01')) // false
// 如果想使用除了毫秒以外的单位进行比较,则将单位作为第二个参数传入。 在这种情况下,会使用传入的单位以及比其范围大的单位进行比较。
dayuts().isBefore('2011-01-01', 'month') // false
```
### 是否在后 Is After
这表示 Dayuts 对象是否在另一个提供的日期时间之后。
```ts
// 默认使用毫秒比较
dayuts().isAfter(dayuts('2011-01-01')) // true
// 如果想使用除了毫秒以外的单位进行比较,则将单位作为第二个参数传入。 在这种情况下,会使用传入的单位以及比其范围大的单位进行比较。
dayuts().isAfter('2011-01-01', 'month') // true
```
### 是否相同 Is Same
这表示 Dayuts 对象是否和另一个提供的日期时间相同。
```ts
// 默认使用毫秒比较
dayuts().isSame(dayuts('2011-01-01')) // false
// 当使用第二个参数时,将会连同去比较更大的单位。 如传入 month 将会比较 month 和 year。 传入 day 将会比较 day、 month和 year。
dayuts().isSame('2011-01-01', 'year') // false
```
### 是否相同或在前 Is Same or Before
这表示 Dayuts 对象是否在另一个提供的日期时间之前。
```ts
// 默认使用毫秒比较
dayuts().isSameOrBefore(dayuts('2011-01-01')) // false
// 如果想使用除了毫秒以外的单位进行比较,则将单位作为第二个参数传入。 在这种情况下,会使用传入的单位以及比其范围大的单位进行比较。
dayuts().isSameOrBefore('2011-01-01', 'month') // false
```
### 是否相同或在后 Is Same or After
这表示 Dayuts 对象是否和另一个提供的日期时间相同或在其之后。
```ts
// 默认使用毫秒比较
dayuts().isSameOrAfter(dayuts('2011-01-01')) // true
// 如果想使用除了毫秒以外的单位进行比较,则将单位作为第二个参数传入。
dayuts().isSameOrAfter('2011-01-01', 'month') // true
```
### 区间 Is Between
这表示 Dayuts 对象是否在其他两个的日期时间之间
```ts
// 默认使用毫秒比较
dayuts('2010-10-20').isBetween('2010-10-19', dayuts('2010-10-25'))// true
// 如果想使用除了毫秒以外的单位进行比较,则将单位作为第三个参数传入。 在这种情况下,会使用传入的单位以及比其范围大的单位进行比较。
dayuts().isBetween('2010-10-19', '2010-10-25', 'month') // false
// 第四个参数是设置包容性。 [ 表示包含。 ( 表示排除。
// 要使用包容性参数,必须同时传入两个指示符。
dayuts('2016-10-30').isBetween('2016-01-01', '2016-10-30', 'day', '[)')
```
### 是否闰年 Is Leap Year
查询 Dayuts 对象的年份是否闰年
```ts
dayuts().isLeapYear()// true
```
### 今日 Is Today
查询 Dayuts 对象的日期是不是今日
```ts
dayuts().isToday()// true
```
## 国际化
目前内置了中英两种语言,欢迎提交 Pull Request 来增加新的语言
### 改变语言配置 (全局)
更改全局的语言配置并不会影响之前存在的实例
```ts
import {dayutsIntl} from '@/uni_modules/lime-dayuts'
dayutsIntl.locale = 'zh-cn' // 全局使用简体中文
dayutsIntl.locale = 'en' // 全局使用默认的英文
```
### 改变语言配置 (当前实例)
```
dayuts().locale('zh-cn').format()
```

View File

@@ -0,0 +1,3 @@
{
"deploymentTarget": "9"
}

View File

@@ -0,0 +1,3 @@
export * from '../../common'
export * from '../../common/use'
export * from '../interface'

View File

@@ -0,0 +1,3 @@
export * from '../common'
export * from '../common/use'
export * from './interface'

View File

@@ -0,0 +1,405 @@
// @ts-nocheck
export type DayutsConfig = {
date: any|null
format : string|null
locale : string|null
}
export type DayutsUnit = 'year' | 'month' | 'day' | 'week' | 'date' | 'hour' | 'minute' | 'second' | 'millisecond' | 'quarter'
export type DayutsFormats = {
/**
* 小时和分钟的格式化字符串。
*/
LT : string;
/**
* 小时、分钟和秒的格式化字符串。
*/
LTS : string;
/**
* 年份、月份和日期的格式化字符串。
*/
L : string;
/**
* 年份、月份、日期和星期的格式化字符串。
*/
LL : string;
/**
* 年份、月份、日期、星期和小时的格式化字符串。
*/
LLL : string;
/**
* 年份、月份、日期、星期、小时和分钟的格式化字符串。
*/
LLLL : string;
/**
* 缩小的年份、月份和日期的格式化字符串。
*/
l : string;
/**
* 缩小的年份、月份、日期和星期的格式化字符串。
*/
ll : string;
/**
* 缩小的年份、月份、日期、星期和小时的格式化字符串。
*/
lll : string;
/**
* 缩小的年份、月份、日期、星期、小时和分钟的格式化字符串。
*/
llll : string;
}
export type DayutsRelativeTime = {
/**
* 时间单位之后的格式化字符串。
*/
future : string;
/**
* 时间单位之前的格式化字符串。
*/
past : string;
/**
* 秒的格式化字符串。
*/
s : string;
/**
* 分钟的格式化字符串。
*/
m : string;
/**
* 分钟(带前缀)的格式化字符串。
*/
mm : string;
/**
* 小时的格式化字符串。
*/
h : string;
/**
* 小时(带前缀)的格式化字符串。
*/
hh : string;
/**
* 天的格式化字符串。
*/
d : string;
/**
* 天(带前缀)的格式化字符串。
*/
dd : string;
/**
* 月的格式化字符串。
*/
M : string;
/**
* 月(带前缀)的格式化字符串。
*/
MM : string;
/**
* 年的格式化字符串。
*/
y : string;
/**
* 年(带前缀)的格式化字符串。
*/
yy : string;
}
/**
* 本地化对象接口。
*/
export type DayutsLocale = {
/**
* 区域设置名称。
*/
name : string;
/**
* 一周中每天的完整名称。
*/
weekdays : string[];
/**
* 一周中每天的缩写名称。
*/
weekdaysShort ?: string[];
/**
* 一周中每天的最小缩写名称。
*/
weekdaysMin ?: string[];
/**
* 一年中的每个月份的名称。
*/
months : string[];
/**
* 一年中的每个月份的缩写名称。
*/
monthsShort ?: string[];
/**
* 返回序数词的函数。
*
* @param number - 要格式化的数字。
* @param period - 周期类型(如 "W" 表示周)。
* @returns 返回格式化后的序数词字符串。
*/
// ordinal : (number : number) => string;
ordinal : (number : number, period : string) => string;
/**
* 一周的开始日期(星期几)。
*/
weekStart ?: number;
/**
* 年的开始月份。
*/
yearStart ?: number;
/**
* 日期和时间格式化选项。
*/
formats ?: DayutsFormats;
/**
* 相对时间格式化选项。
*/
relativeTime ?: DayutsRelativeTime;
/**
* 根据小时和分钟返回上午或下午的函数。
*
* @param hour - 小时数0-23
* @param minute - 分钟数0-59
* @returns 返回上午或下午的字符串。
*/
meridiem ?: (hour : number, minute : number, isLowercase : boolean) => string;
}
export type DayutsObject = {
years : number;
months : number;
date : number;
hours : number;
minutes : number;
seconds : number;
milliseconds : number;
}
// 主 Dayuts 类类型定义
// export interface Dayuts {
// // 公共属性
// $L: string;
// // 私有属性
// $d: Date;
// $y: number;
// $M: number;
// $D: number;
// $W: number;
// $H: number;
// $m: number;
// $s: number;
// $ms: number;
// $u: boolean;
// // 构造函数
// // constructor(cfg: DayutsConfig);
// // 解析配置并初始化日期
// // private parse(cfg: DayutsConfig): void;
// // 初始化日期的各个部分
// // private init(): void;
// // 检查日期是否有效
// isValid(): boolean;
// // 判断当前日期是否与给定日期在指定时间单位内相同
// // isSame(input: string, units?: DayutsUnit): boolean;
// // isSame(input: number, units?: DayutsUnit): boolean;
// // isSame(input: Date, units?: DayutsUnit): boolean;
// // isSame(input: Dayuts, units?: DayutsUnit): boolean;
// // isSame(input: UTSJSONObject, units?: DayutsUnit): boolean;
// // isSame(input : string) : boolean
// // isSame(input : number) : boolean
// // isSame(input : Date) : boolean
// // isSame(input : Dayuts) : boolean
// // isSame(input : UTSJSONObject) : boolean
// // isSame(input : string, units : DayutsUnit) : boolean
// // isSame(input : number, units : DayutsUnit) : boolean
// // isSame(input : Date, units : DayutsUnit) : boolean
// // isSame(input : Dayuts, units : DayutsUnit) : boolean
// // isSame(input : UTSJSONObject, units : DayutsUnit) : boolean
// // isSame(input : any, units : DayutsUnit) : boolean
// // 判断给定日期是否在当前日期指定时间单位之后
// // isAfter(input: string, units?: DayutsUnit): boolean;
// // isAfter(input: number, units?: DayutsUnit): boolean;
// // isAfter(input: Date, units?: DayutsUnit): boolean;
// // isAfter(input: Dayuts, units?: DayutsUnit): boolean;
// // isAfter(input: UTSJSONObject, units?: DayutsUnit): boolean;
// // isAfter(input : string) : boolean
// // isAfter(input : number) : boolean
// // isAfter(input : Date) : boolean
// // isAfter(input : Dayuts) : boolean
// // isAfter(input : UTSJSONObject) : boolean
// // isAfter(input : string, units : DayutsUnit) : boolean
// // isAfter(input : number, units : DayutsUnit) : boolean
// // isAfter(input : Date, units : DayutsUnit) : boolean
// // isAfter(input : Dayuts, units : DayutsUnit) : boolean
// // isAfter(input : UTSJSONObject, units : DayutsUnit) : boolean
// // isAfter(input : any, units : DayutsUnit) : boolean
// // 判断给定日期是否在当前日期指定时间单位之前
// // isBefore(input: string, units?: DayutsUnit): boolean;
// // isBefore(input: number, units?: DayutsUnit): boolean;
// // isBefore(input: Date, units?: DayutsUnit): boolean;
// // isBefore(input: Dayuts, units?: DayutsUnit): boolean;
// // isBefore(input: UTSJSONObject, units?: DayutsUnit): boolean;
// // 判断当前日期是否与给定日期在指定时间单位内相同或之前
// // isSameOrBefore(input: string, units?: DayutsUnit): boolean;
// // isSameOrBefore(input: number, units?: DayutsUnit): boolean;
// // isSameOrBefore(input: Date, units?: DayutsUnit): boolean;
// // isSameOrBefore(input: Dayuts, units?: DayutsUnit): boolean;
// // isSameOrBefore(input: UTSJSONObject, units?: DayutsUnit): boolean;
// // 判断当前日期是否与给定日期在指定时间单位内相同或之后
// // isSameOrAfter(input: string, units?: DayutsUnit): boolean;
// // isSameOrAfter(input: number, units?: DayutsUnit): boolean;
// // isSameOrAfter(input: Date, units?: DayutsUnit): boolean;
// // isSameOrAfter(input: Dayuts, units?: DayutsUnit): boolean;
// // isSameOrAfter(input: UTSJSONObject, units?: DayutsUnit): boolean;
// // 判断当前日期是否在两个给定日期之间
// // isBetween(input: any, input2: any): boolean;
// // isBetween(input: any, input2: any, units?: DayutsUnit, interval?: string): boolean;
// // 判断当前年份是否为闰年
// isLeapYear(): boolean;
// // 判断当前日期是否为今天
// isToday(): boolean;
// // 获取 Unix 时间戳(秒)
// unix(): number;
// // 设置为指定时间单位的开始或结束
// // startOf(units: DayutsUnit): Dayuts;
// // startOf(units: DayutsUnit, startOf?: boolean): Dayuts;
// endOf(units: DayutsUnit): Dayuts;
// // 设置指定时间单位的值
// set(units: DayutsUnit, int: number): Dayuts;
// // 获取指定时间单位的值
// get(units: DayutsUnit): number;
// // 年、月、日、时、分、秒、毫秒的 getter 和 setter 方法
// year(): number;
// year(input?: number): Dayuts;
// month(): number
// month(input?: number): Dayuts;
// // day(): number;
// day(input?: number): Dayuts;
// date(): number;
// date(input?: number): Dayuts;
// // hour(): number;
// hour(input?: number): Dayuts;
// // minute(): number;
// minute(input?: number): Dayuts;
// // second(): number;
// second(input?: number): Dayuts;
// // millisecond(): number;
// millisecond(input?: number): Dayuts;
// // 添加时间
// add(number: number, units: DayutsUnit): Dayuts;
// // 减去时间
// subtract(number: number, units: DayutsUnit): Dayuts;
// // 格式化日期
// format(formatStr?: string): string;
// // 获取 UTC 偏移量(分钟)
// utcOffset(): number;
// // 计算两个日期之间的差值
// diff(input: string, units?: DayutsUnit, float?: boolean): number;
// diff(input: number, units?: DayutsUnit, float?: boolean): number;
// diff(input: Date, units?: DayutsUnit, float?: boolean): number;
// diff(input: Dayuts, units?: DayutsUnit, float?: boolean): number;
// diff(input: UTSJSONObject, units?: DayutsUnit, float?: boolean): number;
// // 转换为原生 Date 对象
// toDate(): Date;
// // 转换为 ISO 8601 字符串
// toJSON(): string | null;
// toISOString(): string;
// // 转换为对象
// toObject(): DayutsObject;
// // 转换为数组
// toArray(): number[];
// // 获取时间戳(毫秒)
// valueOf(): number;
// // 获取月份的天数
// daysInMonth(): number;
// // 获取本地化对象
// // private $locale(): DayutsLocale;
// // 设置或获取本地化配置
// locale(preset: string, object?: DayutsLocale): Dayuts;
// locale(preset: DayutsLocale, object?: DayutsLocale): Dayuts;
// // 克隆当前实例
// clone(): Dayuts;
// // 转换为字符串
// // toString(): string;
// // 获取或设置一年中的第几天
// dayOfYear(): number;
// dayOfYear(input?: number): Dayuts;
// // 相对时间方法
// fromToBase(input: any, withoutSuffix: boolean, instance: Dayuts, isFrom: boolean): string;
// to(input: any, withoutSuffix?: boolean): string;
// from(input: any, withoutSuffix?: boolean): string;
// toNow(withoutSuffix?: boolean): string;
// fromNow(withoutSuffix?: boolean): string;
// }

View File

@@ -0,0 +1,39 @@
/* 此规范为 uni 规范,可以按照自己的需要选择是否实现 */
import { MyApiErrorCode, MyApiFail } from "./interface.uts"
/**
* 错误主题
* 注意:错误主题一般为插件名称,每个组件不同,需要使用时请更改。
* [可选实现]
*/
export const UniErrorSubject = 'uts-api';
/**
* 错误信息
* @UniError
* [可选实现]
*/
export const UniErrors : Map<MyApiErrorCode, string> = new Map([
/**
* 错误码及对应的错误信息
*/
[9010001, 'custom error mseeage1'],
[9010002, 'custom error mseeage2'],
]);
/**
* 错误对象实现
*/
export class MyApiFailImpl extends UniError implements MyApiFail {
/**
* 错误对象构造函数
*/
constructor(errCode : MyApiErrorCode) {
super();
this.errSubject = UniErrorSubject;
this.errCode = errCode;
this.errMsg = UniErrors[errCode] ?? "";
}
}