mirror of
https://gitee.com/wot-design-uni/wot-design-uni.git
synced 2025-12-06 09:08:51 +08:00
refactor: ♻️ 替换内置的dayjs为1.11.13版本,以便2.0版本直接使用dayjs
This commit is contained in:
parent
6c6d5c9ea3
commit
569a46b10d
@ -113,7 +113,7 @@
|
||||
"@vant/touch-emulator": "^1.4.0",
|
||||
"@vitalets/google-translate-api": "^9.2.1",
|
||||
"@vitejs/plugin-vue": "^5.2.3",
|
||||
"@vitest/coverage-v8": "^3.1.1",
|
||||
"@vitest/coverage-v8": "^1.6.0",
|
||||
"@vue/runtime-core": "^3.4.38",
|
||||
"@vue/test-utils": "^2.4.6",
|
||||
"@vue/tsconfig": "^0.1.3",
|
||||
@ -142,12 +142,11 @@
|
||||
"sass": "^1.59.3",
|
||||
"standard-version": "^9.5.0",
|
||||
"typescript": "^5.5.4",
|
||||
"uni-read-pages-vite": "^0.0.6",
|
||||
"unplugin-auto-import": "^0.17.5",
|
||||
"unplugin-vue-components": "^0.26.0",
|
||||
"vite": "5",
|
||||
"vite": "^5.4.19",
|
||||
"vitepress-plugin-llms": "^1.1.3",
|
||||
"vitest": "^3.1.1",
|
||||
"vitest": "^1.6.0",
|
||||
"vue-eslint-parser": "^9.1.0",
|
||||
"vue-tsc": "^2.0.29"
|
||||
},
|
||||
|
||||
819
pnpm-lock.yaml
generated
819
pnpm-lock.yaml
generated
File diff suppressed because it is too large
Load Diff
@ -1,148 +0,0 @@
|
||||
import { isDate } from './util'
|
||||
|
||||
/* eslint-disable */
|
||||
class Dayjs {
|
||||
utc: boolean
|
||||
date: Date
|
||||
timeZone: number
|
||||
timeZoneString: any
|
||||
mYear: any
|
||||
mMonth: any
|
||||
mDay: any
|
||||
mWeek: any
|
||||
mHour: any
|
||||
mMinute: any
|
||||
mSecond: any
|
||||
constructor(dateStr?: string | number | Date) {
|
||||
this.utc = false
|
||||
const parsedDate = this.parseConfig(dateStr)
|
||||
this.date = new Date(parsedDate)
|
||||
this.timeZone = this.date.getTimezoneOffset() / 60
|
||||
this.timeZoneString = this.padNumber(String(-1 * this.timeZone).replace(/^(.)?(\d)/, '$10$200'), 5, '+')
|
||||
this.mYear = this.date.getFullYear()
|
||||
this.mMonth = this.date.getMonth()
|
||||
this.mDay = this.date.getDate()
|
||||
this.mWeek = this.date.getDay()
|
||||
this.mHour = this.date.getHours()
|
||||
this.mMinute = this.date.getMinutes()
|
||||
this.mSecond = this.date.getSeconds()
|
||||
}
|
||||
|
||||
parseConfig(dateStr?:string | number | Date) {
|
||||
if (!dateStr) return new Date()
|
||||
if (isDate(dateStr)) return dateStr
|
||||
if (/^(\d){8}$/.test(dateStr as string)) {
|
||||
this.utc = true
|
||||
return `${(dateStr as string).substr(0, 4)}-${(dateStr as string).substr(4, 2)}-${(dateStr as string).substr(6, 2)}`
|
||||
}
|
||||
return dateStr
|
||||
}
|
||||
|
||||
padNumber(num:string, length:number, padChar:string) {
|
||||
return !num || num.length >= length ? num : `${Array(length + 1 - num.length).join(padChar)}${num}`
|
||||
}
|
||||
|
||||
year() {
|
||||
return this.mYear
|
||||
}
|
||||
|
||||
month() {
|
||||
return this.mMonth
|
||||
}
|
||||
|
||||
unix() {
|
||||
const timeZoneOffset = this.utc ? 60 * this.timeZone * 60 * 1000 : 0
|
||||
return Math.floor((this.date.getTime() + timeZoneOffset) / 1000)
|
||||
}
|
||||
|
||||
toString() {
|
||||
return this.date.toUTCString()
|
||||
}
|
||||
|
||||
startOf(unit:string) {
|
||||
switch (unit) {
|
||||
case 'year':
|
||||
return new Dayjs(new Date(this.year(), 0, 1))
|
||||
case 'month':
|
||||
return new Dayjs(new Date(this.year(), this.month(), 1))
|
||||
default:
|
||||
return this
|
||||
}
|
||||
}
|
||||
|
||||
add(amount:number, unit:string) {
|
||||
let interval
|
||||
switch (unit) {
|
||||
case 'm':
|
||||
case 'minutes':
|
||||
interval = 60
|
||||
break
|
||||
case 'h':
|
||||
case 'hours':
|
||||
interval = 60 * 60
|
||||
break
|
||||
case 'd':
|
||||
case 'days':
|
||||
interval = 24 * 60 * 60
|
||||
break
|
||||
case 'w':
|
||||
case 'weeks':
|
||||
interval = 7 * 24 * 60 * 60
|
||||
break
|
||||
default:
|
||||
interval = 1
|
||||
}
|
||||
const newUnixTime = this.unix() + amount * interval
|
||||
return new Dayjs(1000 * newUnixTime)
|
||||
}
|
||||
|
||||
subtract(amount:number, unit:string) {
|
||||
return this.add(-1 * amount, unit)
|
||||
}
|
||||
|
||||
format(formatStr = 'YYYY-MM-DDTHH:mm:ssZ') {
|
||||
const weekdays = ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday']
|
||||
return formatStr.replace(/Y{2,4}|M{1,2}|D{1,2}|d{1,4}|H{1,2}|m{1,2}|s{1,2}|Z{1,2}/g, (match) => {
|
||||
switch (match) {
|
||||
case 'YY':
|
||||
return String(this.mYear).slice(-2)
|
||||
case 'YYYY':
|
||||
return String(this.mYear)
|
||||
case 'M':
|
||||
return String(this.mMonth + 1)
|
||||
case 'MM':
|
||||
return this.padNumber(String(this.mMonth + 1), 2, '0')
|
||||
case 'D':
|
||||
return String(this.mDay)
|
||||
case 'DD':
|
||||
return this.padNumber(String(this.mDay), 2, '0')
|
||||
case 'd':
|
||||
return String(this.mWeek)
|
||||
case 'dddd':
|
||||
return weekdays[this.mWeek]
|
||||
case 'H':
|
||||
return String(this.mHour)
|
||||
case 'HH':
|
||||
return this.padNumber(String(this.mHour), 2, '0')
|
||||
case 'm':
|
||||
return String(this.mMinute)
|
||||
case 'mm':
|
||||
return this.padNumber(String(this.mMinute), 2, '0')
|
||||
case 's':
|
||||
return String(this.mSecond)
|
||||
case 'ss':
|
||||
return this.padNumber(String(this.mSecond), 2, '0')
|
||||
case 'Z':
|
||||
return `${this.timeZoneString.slice(0, -2)}:00`
|
||||
case 'ZZ':
|
||||
return this.timeZoneString
|
||||
default:
|
||||
return match
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
export function dayjs(dateStr?: string | number | Date) {
|
||||
return new Dayjs(dateStr)
|
||||
}
|
||||
@ -1,5 +1,5 @@
|
||||
import { computed } from 'vue'
|
||||
import { dayjs } from '../common/dayjs'
|
||||
import dayjs from '../../dayjs'
|
||||
import { isArray, isFunction, padZero } from '../common/util'
|
||||
import { useTranslate } from '../composables/useTranslate'
|
||||
import type { CalendarDayType, CalendarItem, CalendarTimeFilter, CalendarType } from './types'
|
||||
|
||||
@ -36,7 +36,7 @@ import { deepClone, isArray, isFunction } from '../../common/util'
|
||||
import { compareMonth, formatYearTitle, getDateByDefaultTime, getItemClass, getMonthByOffset, getMonthOffset } from '../utils'
|
||||
import { useToast } from '../../wd-toast'
|
||||
import { useTranslate } from '../../composables/useTranslate'
|
||||
import { dayjs } from '../../common/dayjs'
|
||||
import dayjs from '../../../dayjs'
|
||||
import { yearProps } from './types'
|
||||
import type { CalendarDayItem, CalendarDayType } from '../types'
|
||||
|
||||
|
||||
@ -121,7 +121,7 @@ import wdCalendarView from '../wd-calendar-view/wd-calendar-view.vue'
|
||||
import wdActionSheet from '../wd-action-sheet/wd-action-sheet.vue'
|
||||
import wdButton from '../wd-button/wd-button.vue'
|
||||
import { ref, computed, watch } from 'vue'
|
||||
import { dayjs } from '../common/dayjs'
|
||||
import dayjs from '../../dayjs'
|
||||
import { deepClone, isArray, isEqual, padZero, pause } from '../common/util'
|
||||
import { getWeekNumber, isRange } from '../wd-calendar-view/utils'
|
||||
import { useCell } from '../composables/useCell'
|
||||
|
||||
@ -173,7 +173,7 @@ import { FORM_KEY, type FormItemRule } from '../wd-form/types'
|
||||
import { useParent } from '../composables/useParent'
|
||||
import { useTranslate } from '../composables/useTranslate'
|
||||
import { datetimePickerProps, type DatetimePickerExpose } from './types'
|
||||
import { dayjs } from '../common/dayjs'
|
||||
import dayjs from '../../dayjs'
|
||||
import { getPickerValue } from '../wd-datetime-picker-view/util'
|
||||
|
||||
const props = defineProps(datetimePickerProps)
|
||||
|
||||
@ -21,7 +21,7 @@ export default {
|
||||
import { computed, ref, watch } from 'vue'
|
||||
import { isDef, objToStyle } from '../common/util'
|
||||
import { textProps } from './types'
|
||||
import { dayjs } from '../common/dayjs'
|
||||
import dayjs from '../../dayjs'
|
||||
|
||||
// 获取组件的 props 和 emit 函数
|
||||
const props = defineProps(textProps)
|
||||
|
||||
26
src/uni_modules/wot-design-uni/dayjs/constant.js
Normal file
26
src/uni_modules/wot-design-uni/dayjs/constant.js
Normal file
@ -0,0 +1,26 @@
|
||||
/* eslint-disable */
|
||||
export var SECONDS_A_MINUTE = 60;
|
||||
export var SECONDS_A_HOUR = SECONDS_A_MINUTE * 60;
|
||||
export var SECONDS_A_DAY = SECONDS_A_HOUR * 24;
|
||||
export var SECONDS_A_WEEK = SECONDS_A_DAY * 7;
|
||||
export var MILLISECONDS_A_SECOND = 1e3;
|
||||
export var MILLISECONDS_A_MINUTE = SECONDS_A_MINUTE * MILLISECONDS_A_SECOND;
|
||||
export var MILLISECONDS_A_HOUR = SECONDS_A_HOUR * MILLISECONDS_A_SECOND;
|
||||
export var MILLISECONDS_A_DAY = SECONDS_A_DAY * MILLISECONDS_A_SECOND;
|
||||
export var MILLISECONDS_A_WEEK = SECONDS_A_WEEK * MILLISECONDS_A_SECOND; // English locales
|
||||
|
||||
export var MS = 'millisecond';
|
||||
export var S = 'second';
|
||||
export var MIN = 'minute';
|
||||
export var H = 'hour';
|
||||
export var D = 'day';
|
||||
export var W = 'week';
|
||||
export var M = 'month';
|
||||
export var Q = 'quarter';
|
||||
export var Y = 'year';
|
||||
export var DATE = 'date';
|
||||
export var FORMAT_DEFAULT = 'YYYY-MM-DDTHH:mm:ssZ';
|
||||
export var INVALID_DATE_STRING = 'Invalid Date'; // regex
|
||||
|
||||
export var REGEX_PARSE = /^(\d{4})[-/]?(\d{1,2})?[-/]?(\d{0,2})[Tt\s]*(\d{1,2})?:?(\d{1,2})?:?(\d{1,2})?[.:]?(\d+)?$/;
|
||||
export var 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;
|
||||
430
src/uni_modules/wot-design-uni/dayjs/index.d.ts
vendored
Normal file
430
src/uni_modules/wot-design-uni/dayjs/index.d.ts
vendored
Normal file
@ -0,0 +1,430 @@
|
||||
/* eslint-disable */
|
||||
/// <reference path="./locale/index.d.ts" />
|
||||
|
||||
export = dayjs;
|
||||
|
||||
declare function dayjs (date?: dayjs.ConfigType): dayjs.Dayjs
|
||||
|
||||
declare function dayjs (date?: dayjs.ConfigType, format?: dayjs.OptionType, strict?: boolean): dayjs.Dayjs
|
||||
|
||||
declare function dayjs (date?: dayjs.ConfigType, format?: dayjs.OptionType, locale?: string, strict?: boolean): dayjs.Dayjs
|
||||
|
||||
declare namespace dayjs {
|
||||
interface ConfigTypeMap {
|
||||
default: string | number | Date | Dayjs | null | undefined
|
||||
}
|
||||
|
||||
export type ConfigType = ConfigTypeMap[keyof ConfigTypeMap]
|
||||
|
||||
export interface FormatObject { locale?: string, format?: string, utc?: boolean }
|
||||
|
||||
export type OptionType = FormatObject | string | string[]
|
||||
|
||||
export type UnitTypeShort = 'd' | 'D' | 'M' | 'y' | 'h' | 'm' | 's' | 'ms'
|
||||
|
||||
export type UnitTypeLong = 'millisecond' | 'second' | 'minute' | 'hour' | 'day' | 'month' | 'year' | 'date'
|
||||
|
||||
export type UnitTypeLongPlural = 'milliseconds' | 'seconds' | 'minutes' | 'hours' | 'days' | 'months' | 'years' | 'dates'
|
||||
|
||||
export type UnitType = UnitTypeLong | UnitTypeLongPlural | UnitTypeShort;
|
||||
|
||||
export type OpUnitType = UnitType | "week" | "weeks" | 'w';
|
||||
export type QUnitType = UnitType | "quarter" | "quarters" | 'Q';
|
||||
export type ManipulateType = Exclude<OpUnitType, 'date' | 'dates'>;
|
||||
class Dayjs {
|
||||
constructor (config?: ConfigType)
|
||||
/**
|
||||
* All Day.js objects are immutable. Still, `dayjs#clone` can create a clone of the current object if you need one.
|
||||
* ```
|
||||
* dayjs().clone()// => Dayjs
|
||||
* dayjs(dayjs('2019-01-25')) // passing a Dayjs object to a constructor will also clone it
|
||||
* ```
|
||||
* Docs: https://day.js.org/docs/en/parse/dayjs-clone
|
||||
*/
|
||||
clone(): Dayjs
|
||||
/**
|
||||
* This returns a `boolean` indicating whether the Day.js object contains a valid date or not.
|
||||
* ```
|
||||
* dayjs().isValid()// => boolean
|
||||
* ```
|
||||
* Docs: https://day.js.org/docs/en/parse/is-valid
|
||||
*/
|
||||
isValid(): boolean
|
||||
/**
|
||||
* Get the year.
|
||||
* ```
|
||||
* dayjs().year()// => 2020
|
||||
* ```
|
||||
* Docs: https://day.js.org/docs/en/get-set/year
|
||||
*/
|
||||
year(): number
|
||||
/**
|
||||
* Set the year.
|
||||
* ```
|
||||
* dayjs().year(2000)// => Dayjs
|
||||
* ```
|
||||
* Docs: https://day.js.org/docs/en/get-set/year
|
||||
*/
|
||||
year(value: number): Dayjs
|
||||
/**
|
||||
* Get the month.
|
||||
*
|
||||
* Months are zero indexed, so January is month 0.
|
||||
* ```
|
||||
* dayjs().month()// => 0-11
|
||||
* ```
|
||||
* Docs: https://day.js.org/docs/en/get-set/month
|
||||
*/
|
||||
month(): number
|
||||
/**
|
||||
* Set the month.
|
||||
*
|
||||
* Months are zero indexed, so January is month 0.
|
||||
*
|
||||
* Accepts numbers from 0 to 11. If the range is exceeded, it will bubble up to the next year.
|
||||
* ```
|
||||
* dayjs().month(0)// => Dayjs
|
||||
* ```
|
||||
* Docs: https://day.js.org/docs/en/get-set/month
|
||||
*/
|
||||
month(value: number): Dayjs
|
||||
/**
|
||||
* Get the date of the month.
|
||||
* ```
|
||||
* dayjs().date()// => 1-31
|
||||
* ```
|
||||
* Docs: https://day.js.org/docs/en/get-set/date
|
||||
*/
|
||||
date(): number
|
||||
/**
|
||||
* Set the date of the month.
|
||||
*
|
||||
* Accepts numbers from 1 to 31. If the range is exceeded, it will bubble up to the next months.
|
||||
* ```
|
||||
* dayjs().date(1)// => Dayjs
|
||||
* ```
|
||||
* Docs: https://day.js.org/docs/en/get-set/date
|
||||
*/
|
||||
date(value: number): Dayjs
|
||||
/**
|
||||
* Get the day of the week.
|
||||
*
|
||||
* Returns numbers from 0 (Sunday) to 6 (Saturday).
|
||||
* ```
|
||||
* dayjs().day()// 0-6
|
||||
* ```
|
||||
* Docs: https://day.js.org/docs/en/get-set/day
|
||||
*/
|
||||
day(): 0 | 1 | 2 | 3 | 4 | 5 | 6
|
||||
/**
|
||||
* Set the day of the week.
|
||||
*
|
||||
* Accepts numbers from 0 (Sunday) to 6 (Saturday). If the range is exceeded, it will bubble up to next weeks.
|
||||
* ```
|
||||
* dayjs().day(0)// => Dayjs
|
||||
* ```
|
||||
* Docs: https://day.js.org/docs/en/get-set/day
|
||||
*/
|
||||
day(value: number): Dayjs
|
||||
/**
|
||||
* Get the hour.
|
||||
* ```
|
||||
* dayjs().hour()// => 0-23
|
||||
* ```
|
||||
* Docs: https://day.js.org/docs/en/get-set/hour
|
||||
*/
|
||||
hour(): number
|
||||
/**
|
||||
* Set the hour.
|
||||
*
|
||||
* Accepts numbers from 0 to 23. If the range is exceeded, it will bubble up to the next day.
|
||||
* ```
|
||||
* dayjs().hour(12)// => Dayjs
|
||||
* ```
|
||||
* Docs: https://day.js.org/docs/en/get-set/hour
|
||||
*/
|
||||
hour(value: number): Dayjs
|
||||
/**
|
||||
* Get the minutes.
|
||||
* ```
|
||||
* dayjs().minute()// => 0-59
|
||||
* ```
|
||||
* Docs: https://day.js.org/docs/en/get-set/minute
|
||||
*/
|
||||
minute(): number
|
||||
/**
|
||||
* Set the minutes.
|
||||
*
|
||||
* Accepts numbers from 0 to 59. If the range is exceeded, it will bubble up to the next hour.
|
||||
* ```
|
||||
* dayjs().minute(59)// => Dayjs
|
||||
* ```
|
||||
* Docs: https://day.js.org/docs/en/get-set/minute
|
||||
*/
|
||||
minute(value: number): Dayjs
|
||||
/**
|
||||
* Get the seconds.
|
||||
* ```
|
||||
* dayjs().second()// => 0-59
|
||||
* ```
|
||||
* Docs: https://day.js.org/docs/en/get-set/second
|
||||
*/
|
||||
second(): number
|
||||
/**
|
||||
* Set the seconds.
|
||||
*
|
||||
* Accepts numbers from 0 to 59. If the range is exceeded, it will bubble up to the next minutes.
|
||||
* ```
|
||||
* dayjs().second(1)// Dayjs
|
||||
* ```
|
||||
*/
|
||||
second(value: number): Dayjs
|
||||
/**
|
||||
* Get the milliseconds.
|
||||
* ```
|
||||
* dayjs().millisecond()// => 0-999
|
||||
* ```
|
||||
* Docs: https://day.js.org/docs/en/get-set/millisecond
|
||||
*/
|
||||
millisecond(): number
|
||||
/**
|
||||
* Set the milliseconds.
|
||||
*
|
||||
* Accepts numbers from 0 to 999. If the range is exceeded, it will bubble up to the next seconds.
|
||||
* ```
|
||||
* dayjs().millisecond(1)// => Dayjs
|
||||
* ```
|
||||
* Docs: https://day.js.org/docs/en/get-set/millisecond
|
||||
*/
|
||||
millisecond(value: number): Dayjs
|
||||
/**
|
||||
* Generic setter, accepting unit as first argument, and value as second, returns a new instance with the applied changes.
|
||||
*
|
||||
* In general:
|
||||
* ```
|
||||
* dayjs().set(unit, value) === dayjs()[unit](value)
|
||||
* ```
|
||||
* Units are case insensitive, and support plural and short forms.
|
||||
* ```
|
||||
* dayjs().set('date', 1)
|
||||
* dayjs().set('month', 3) // April
|
||||
* dayjs().set('second', 30)
|
||||
* ```
|
||||
* Docs: https://day.js.org/docs/en/get-set/set
|
||||
*/
|
||||
set(unit: UnitType, value: number): Dayjs
|
||||
/**
|
||||
* String getter, returns the corresponding information getting from Day.js object.
|
||||
*
|
||||
* In general:
|
||||
* ```
|
||||
* dayjs().get(unit) === dayjs()[unit]()
|
||||
* ```
|
||||
* Units are case insensitive, and support plural and short forms.
|
||||
* ```
|
||||
* dayjs().get('year')
|
||||
* dayjs().get('month') // start 0
|
||||
* dayjs().get('date')
|
||||
* ```
|
||||
* Docs: https://day.js.org/docs/en/get-set/get
|
||||
*/
|
||||
get(unit: UnitType): number
|
||||
/**
|
||||
* Returns a cloned Day.js object with a specified amount of time added.
|
||||
* ```
|
||||
* dayjs().add(7, 'day')// => Dayjs
|
||||
* ```
|
||||
* Units are case insensitive, and support plural and short forms.
|
||||
*
|
||||
* Docs: https://day.js.org/docs/en/manipulate/add
|
||||
*/
|
||||
add(value: number, unit?: ManipulateType): Dayjs
|
||||
/**
|
||||
* Returns a cloned Day.js object with a specified amount of time subtracted.
|
||||
* ```
|
||||
* dayjs().subtract(7, 'year')// => Dayjs
|
||||
* ```
|
||||
* Units are case insensitive, and support plural and short forms.
|
||||
*
|
||||
* Docs: https://day.js.org/docs/en/manipulate/subtract
|
||||
*/
|
||||
subtract(value: number, unit?: ManipulateType): Dayjs
|
||||
/**
|
||||
* Returns a cloned Day.js object and set it to the start of a unit of time.
|
||||
* ```
|
||||
* dayjs().startOf('year')// => Dayjs
|
||||
* ```
|
||||
* Units are case insensitive, and support plural and short forms.
|
||||
*
|
||||
* Docs: https://day.js.org/docs/en/manipulate/start-of
|
||||
*/
|
||||
startOf(unit: OpUnitType): Dayjs
|
||||
/**
|
||||
* Returns a cloned Day.js object and set it to the end of a unit of time.
|
||||
* ```
|
||||
* dayjs().endOf('month')// => Dayjs
|
||||
* ```
|
||||
* Units are case insensitive, and support plural and short forms.
|
||||
*
|
||||
* Docs: https://day.js.org/docs/en/manipulate/end-of
|
||||
*/
|
||||
endOf(unit: OpUnitType): Dayjs
|
||||
/**
|
||||
* Get the formatted date according to the string of tokens passed in.
|
||||
*
|
||||
* To escape characters, wrap them in square brackets (e.g. [MM]).
|
||||
* ```
|
||||
* dayjs().format()// => current date in ISO8601, without fraction seconds e.g. '2020-04-02T08:02:17-05:00'
|
||||
* dayjs('2019-01-25').format('[YYYYescape] YYYY-MM-DDTHH:mm:ssZ[Z]')// 'YYYYescape 2019-01-25T00:00:00-02:00Z'
|
||||
* dayjs('2019-01-25').format('DD/MM/YYYY') // '25/01/2019'
|
||||
* ```
|
||||
* Docs: https://day.js.org/docs/en/display/format
|
||||
*/
|
||||
format(template?: string): string
|
||||
/**
|
||||
* This indicates the difference between two date-time in the specified unit.
|
||||
*
|
||||
* To get the difference in milliseconds, use `dayjs#diff`
|
||||
* ```
|
||||
* const date1 = dayjs('2019-01-25')
|
||||
* const date2 = dayjs('2018-06-05')
|
||||
* date1.diff(date2) // 20214000000 default milliseconds
|
||||
* date1.diff() // milliseconds to current time
|
||||
* ```
|
||||
*
|
||||
* To get the difference in another unit of measurement, pass that measurement as the second argument.
|
||||
* ```
|
||||
* const date1 = dayjs('2019-01-25')
|
||||
* date1.diff('2018-06-05', 'month') // 7
|
||||
* ```
|
||||
* Units are case insensitive, and support plural and short forms.
|
||||
*
|
||||
* Docs: https://day.js.org/docs/en/display/difference
|
||||
*/
|
||||
diff(date?: ConfigType, unit?: QUnitType | OpUnitType, float?: boolean): number
|
||||
/**
|
||||
* This returns the number of **milliseconds** since the Unix Epoch of the Day.js object.
|
||||
* ```
|
||||
* dayjs('2019-01-25').valueOf() // 1548381600000
|
||||
* +dayjs(1548381600000) // 1548381600000
|
||||
* ```
|
||||
* To get a Unix timestamp (the number of seconds since the epoch) from a Day.js object, you should use Unix Timestamp `dayjs#unix()`.
|
||||
*
|
||||
* Docs: https://day.js.org/docs/en/display/unix-timestamp-milliseconds
|
||||
*/
|
||||
valueOf(): number
|
||||
/**
|
||||
* This returns the Unix timestamp (the number of **seconds** since the Unix Epoch) of the Day.js object.
|
||||
* ```
|
||||
* dayjs('2019-01-25').unix() // 1548381600
|
||||
* ```
|
||||
* This value is floored to the nearest second, and does not include a milliseconds component.
|
||||
*
|
||||
* Docs: https://day.js.org/docs/en/display/unix-timestamp
|
||||
*/
|
||||
unix(): number
|
||||
/**
|
||||
* Get the number of days in the current month.
|
||||
* ```
|
||||
* dayjs('2019-01-25').daysInMonth() // 31
|
||||
* ```
|
||||
* Docs: https://day.js.org/docs/en/display/days-in-month
|
||||
*/
|
||||
daysInMonth(): number
|
||||
/**
|
||||
* To get a copy of the native `Date` object parsed from the Day.js object use `dayjs#toDate`.
|
||||
* ```
|
||||
* dayjs('2019-01-25').toDate()// => Date
|
||||
* ```
|
||||
*/
|
||||
toDate(): Date
|
||||
/**
|
||||
* To serialize as an ISO 8601 string.
|
||||
* ```
|
||||
* dayjs('2019-01-25').toJSON() // '2019-01-25T02:00:00.000Z'
|
||||
* ```
|
||||
* Docs: https://day.js.org/docs/en/display/as-json
|
||||
*/
|
||||
toJSON(): string
|
||||
/**
|
||||
* To format as an ISO 8601 string.
|
||||
* ```
|
||||
* dayjs('2019-01-25').toISOString() // '2019-01-25T02:00:00.000Z'
|
||||
* ```
|
||||
* Docs: https://day.js.org/docs/en/display/as-iso-string
|
||||
*/
|
||||
toISOString(): string
|
||||
/**
|
||||
* Returns a string representation of the date.
|
||||
* ```
|
||||
* dayjs('2019-01-25').toString() // 'Fri, 25 Jan 2019 02:00:00 GMT'
|
||||
* ```
|
||||
* Docs: https://day.js.org/docs/en/display/as-string
|
||||
*/
|
||||
toString(): string
|
||||
/**
|
||||
* Get the UTC offset in minutes.
|
||||
* ```
|
||||
* dayjs().utcOffset()
|
||||
* ```
|
||||
* Docs: https://day.js.org/docs/en/manipulate/utc-offset
|
||||
*/
|
||||
utcOffset(): number
|
||||
/**
|
||||
* This indicates whether the Day.js object is before the other supplied date-time.
|
||||
* ```
|
||||
* dayjs().isBefore(dayjs('2011-01-01')) // default milliseconds
|
||||
* ```
|
||||
* If you want to limit the granularity to a unit other than milliseconds, pass it as the second parameter.
|
||||
* ```
|
||||
* dayjs().isBefore('2011-01-01', 'year')// => boolean
|
||||
* ```
|
||||
* Units are case insensitive, and support plural and short forms.
|
||||
*
|
||||
* Docs: https://day.js.org/docs/en/query/is-before
|
||||
*/
|
||||
isBefore(date?: ConfigType, unit?: OpUnitType): boolean
|
||||
/**
|
||||
* This indicates whether the Day.js object is the same as the other supplied date-time.
|
||||
* ```
|
||||
* dayjs().isSame(dayjs('2011-01-01')) // default milliseconds
|
||||
* ```
|
||||
* If you want to limit the granularity to a unit other than milliseconds, pass it as the second parameter.
|
||||
* ```
|
||||
* dayjs().isSame('2011-01-01', 'year')// => boolean
|
||||
* ```
|
||||
* Docs: https://day.js.org/docs/en/query/is-same
|
||||
*/
|
||||
isSame(date?: ConfigType, unit?: OpUnitType): boolean
|
||||
/**
|
||||
* This indicates whether the Day.js object is after the other supplied date-time.
|
||||
* ```
|
||||
* dayjs().isAfter(dayjs('2011-01-01')) // default milliseconds
|
||||
* ```
|
||||
* If you want to limit the granularity to a unit other than milliseconds, pass it as the second parameter.
|
||||
* ```
|
||||
* dayjs().isAfter('2011-01-01', 'year')// => boolean
|
||||
* ```
|
||||
* Units are case insensitive, and support plural and short forms.
|
||||
*
|
||||
* Docs: https://day.js.org/docs/en/query/is-after
|
||||
*/
|
||||
isAfter(date?: ConfigType, unit?: OpUnitType): boolean
|
||||
|
||||
locale(): string
|
||||
|
||||
locale(preset: string | ILocale, object?: Partial<ILocale>): Dayjs
|
||||
}
|
||||
|
||||
export type PluginFunc<T = unknown> = (option: T, c: typeof Dayjs, d: typeof dayjs) => void
|
||||
|
||||
export function extend<T = unknown>(plugin: PluginFunc<T>, option?: T): Dayjs
|
||||
|
||||
export function locale(preset?: string | ILocale, object?: Partial<ILocale>, isLocal?: boolean): string
|
||||
|
||||
export function isDayjs(d: any): d is Dayjs
|
||||
|
||||
export function unix(t: number): Dayjs
|
||||
|
||||
const Ls : { [key: string] : ILocale }
|
||||
}
|
||||
542
src/uni_modules/wot-design-uni/dayjs/index.js
Normal file
542
src/uni_modules/wot-design-uni/dayjs/index.js
Normal file
@ -0,0 +1,542 @@
|
||||
/* eslint-disable */
|
||||
import * as C from './constant';
|
||||
import en from './locale/en';
|
||||
import U from './utils';
|
||||
var L = 'en'; // global locale
|
||||
|
||||
var Ls = {}; // global loaded locale
|
||||
|
||||
Ls[L] = en;
|
||||
var IS_DAYJS = '$isDayjsObject'; // eslint-disable-next-line no-use-before-define
|
||||
|
||||
var isDayjs = function isDayjs(d) {
|
||||
return d instanceof Dayjs || !!(d && d[IS_DAYJS]);
|
||||
};
|
||||
|
||||
var parseLocale = function parseLocale(preset, object, isLocal) {
|
||||
var l;
|
||||
if (!preset) return L;
|
||||
|
||||
if (typeof preset === 'string') {
|
||||
var presetLower = preset.toLowerCase();
|
||||
|
||||
if (Ls[presetLower]) {
|
||||
l = presetLower;
|
||||
}
|
||||
|
||||
if (object) {
|
||||
Ls[presetLower] = object;
|
||||
l = presetLower;
|
||||
}
|
||||
|
||||
var presetSplit = preset.split('-');
|
||||
|
||||
if (!l && presetSplit.length > 1) {
|
||||
return parseLocale(presetSplit[0]);
|
||||
}
|
||||
} else {
|
||||
var name = preset.name;
|
||||
Ls[name] = preset;
|
||||
l = name;
|
||||
}
|
||||
|
||||
if (!isLocal && l) L = l;
|
||||
return l || !isLocal && L;
|
||||
};
|
||||
|
||||
var dayjs = function dayjs(date, c) {
|
||||
if (isDayjs(date)) {
|
||||
return date.clone();
|
||||
} // eslint-disable-next-line no-nested-ternary
|
||||
|
||||
|
||||
var cfg = typeof c === 'object' ? c : {};
|
||||
cfg.date = date;
|
||||
cfg.args = arguments; // eslint-disable-line prefer-rest-params
|
||||
|
||||
return new Dayjs(cfg); // eslint-disable-line no-use-before-define
|
||||
};
|
||||
|
||||
var wrapper = function wrapper(date, instance) {
|
||||
return dayjs(date, {
|
||||
locale: instance.$L,
|
||||
utc: instance.$u,
|
||||
x: instance.$x,
|
||||
$offset: instance.$offset // todo: refactor; do not use this.$offset in you code
|
||||
|
||||
});
|
||||
};
|
||||
|
||||
var Utils = U; // for plugin use
|
||||
|
||||
Utils.l = parseLocale;
|
||||
Utils.i = isDayjs;
|
||||
Utils.w = wrapper;
|
||||
|
||||
var parseDate = function parseDate(cfg) {
|
||||
var date = cfg.date,
|
||||
utc = cfg.utc;
|
||||
if (date === null) return new Date(NaN); // null is invalid
|
||||
|
||||
if (Utils.u(date)) return new Date(); // today
|
||||
|
||||
if (date instanceof Date) return new Date(date);
|
||||
|
||||
if (typeof date === 'string' && !/Z$/i.test(date)) {
|
||||
var d = date.match(C.REGEX_PARSE);
|
||||
|
||||
if (d) {
|
||||
var m = d[2] - 1 || 0;
|
||||
var ms = (d[7] || '0').substring(0, 3);
|
||||
|
||||
if (utc) {
|
||||
return new Date(Date.UTC(d[1], m, d[3] || 1, d[4] || 0, d[5] || 0, d[6] || 0, ms));
|
||||
}
|
||||
|
||||
return new Date(d[1], m, d[3] || 1, d[4] || 0, d[5] || 0, d[6] || 0, ms);
|
||||
}
|
||||
}
|
||||
|
||||
return new Date(date); // everything else
|
||||
};
|
||||
|
||||
var Dayjs = /*#__PURE__*/function () {
|
||||
function Dayjs(cfg) {
|
||||
this.$L = parseLocale(cfg.locale, null, true);
|
||||
this.parse(cfg); // for plugin
|
||||
|
||||
this.$x = this.$x || cfg.x || {};
|
||||
this[IS_DAYJS] = true;
|
||||
}
|
||||
|
||||
var _proto = Dayjs.prototype;
|
||||
|
||||
_proto.parse = function parse(cfg) {
|
||||
this.$d = parseDate(cfg);
|
||||
this.init();
|
||||
};
|
||||
|
||||
_proto.init = function init() {
|
||||
var $d = this.$d;
|
||||
this.$y = $d.getFullYear();
|
||||
this.$M = $d.getMonth();
|
||||
this.$D = $d.getDate();
|
||||
this.$W = $d.getDay();
|
||||
this.$H = $d.getHours();
|
||||
this.$m = $d.getMinutes();
|
||||
this.$s = $d.getSeconds();
|
||||
this.$ms = $d.getMilliseconds();
|
||||
} // eslint-disable-next-line class-methods-use-this
|
||||
;
|
||||
|
||||
_proto.$utils = function $utils() {
|
||||
return Utils;
|
||||
};
|
||||
|
||||
_proto.isValid = function isValid() {
|
||||
return !(this.$d.toString() === C.INVALID_DATE_STRING);
|
||||
};
|
||||
|
||||
_proto.isSame = function isSame(that, units) {
|
||||
var other = dayjs(that);
|
||||
return this.startOf(units) <= other && other <= this.endOf(units);
|
||||
};
|
||||
|
||||
_proto.isAfter = function isAfter(that, units) {
|
||||
return dayjs(that) < this.startOf(units);
|
||||
};
|
||||
|
||||
_proto.isBefore = function isBefore(that, units) {
|
||||
return this.endOf(units) < dayjs(that);
|
||||
};
|
||||
|
||||
_proto.$g = function $g(input, get, set) {
|
||||
if (Utils.u(input)) return this[get];
|
||||
return this.set(set, input);
|
||||
};
|
||||
|
||||
_proto.unix = function unix() {
|
||||
return Math.floor(this.valueOf() / 1000);
|
||||
};
|
||||
|
||||
_proto.valueOf = function valueOf() {
|
||||
// timezone(hour) * 60 * 60 * 1000 => ms
|
||||
return this.$d.getTime();
|
||||
};
|
||||
|
||||
_proto.startOf = function startOf(units, _startOf) {
|
||||
var _this = this;
|
||||
|
||||
// startOf -> endOf
|
||||
var isStartOf = !Utils.u(_startOf) ? _startOf : true;
|
||||
var unit = Utils.p(units);
|
||||
|
||||
var instanceFactory = function instanceFactory(d, m) {
|
||||
var ins = Utils.w(_this.$u ? Date.UTC(_this.$y, m, d) : new Date(_this.$y, m, d), _this);
|
||||
return isStartOf ? ins : ins.endOf(C.D);
|
||||
};
|
||||
|
||||
var instanceFactorySet = function instanceFactorySet(method, slice) {
|
||||
var argumentStart = [0, 0, 0, 0];
|
||||
var argumentEnd = [23, 59, 59, 999];
|
||||
return Utils.w(_this.toDate()[method].apply( // eslint-disable-line prefer-spread
|
||||
_this.toDate('s'), (isStartOf ? argumentStart : argumentEnd).slice(slice)), _this);
|
||||
};
|
||||
|
||||
var $W = this.$W,
|
||||
$M = this.$M,
|
||||
$D = this.$D;
|
||||
var utcPad = "set" + (this.$u ? 'UTC' : '');
|
||||
|
||||
switch (unit) {
|
||||
case C.Y:
|
||||
return isStartOf ? instanceFactory(1, 0) : instanceFactory(31, 11);
|
||||
|
||||
case C.M:
|
||||
return isStartOf ? instanceFactory(1, $M) : instanceFactory(0, $M + 1);
|
||||
|
||||
case C.W:
|
||||
{
|
||||
var weekStart = this.$locale().weekStart || 0;
|
||||
var gap = ($W < weekStart ? $W + 7 : $W) - weekStart;
|
||||
return instanceFactory(isStartOf ? $D - gap : $D + (6 - gap), $M);
|
||||
}
|
||||
|
||||
case C.D:
|
||||
case C.DATE:
|
||||
return instanceFactorySet(utcPad + "Hours", 0);
|
||||
|
||||
case C.H:
|
||||
return instanceFactorySet(utcPad + "Minutes", 1);
|
||||
|
||||
case C.MIN:
|
||||
return instanceFactorySet(utcPad + "Seconds", 2);
|
||||
|
||||
case C.S:
|
||||
return instanceFactorySet(utcPad + "Milliseconds", 3);
|
||||
|
||||
default:
|
||||
return this.clone();
|
||||
}
|
||||
};
|
||||
|
||||
_proto.endOf = function endOf(arg) {
|
||||
return this.startOf(arg, false);
|
||||
};
|
||||
|
||||
_proto.$set = function $set(units, _int) {
|
||||
var _C$D$C$DATE$C$M$C$Y$C;
|
||||
|
||||
// private set
|
||||
var unit = Utils.p(units);
|
||||
var utcPad = "set" + (this.$u ? 'UTC' : '');
|
||||
var name = (_C$D$C$DATE$C$M$C$Y$C = {}, _C$D$C$DATE$C$M$C$Y$C[C.D] = utcPad + "Date", _C$D$C$DATE$C$M$C$Y$C[C.DATE] = utcPad + "Date", _C$D$C$DATE$C$M$C$Y$C[C.M] = utcPad + "Month", _C$D$C$DATE$C$M$C$Y$C[C.Y] = utcPad + "FullYear", _C$D$C$DATE$C$M$C$Y$C[C.H] = utcPad + "Hours", _C$D$C$DATE$C$M$C$Y$C[C.MIN] = utcPad + "Minutes", _C$D$C$DATE$C$M$C$Y$C[C.S] = utcPad + "Seconds", _C$D$C$DATE$C$M$C$Y$C[C.MS] = utcPad + "Milliseconds", _C$D$C$DATE$C$M$C$Y$C)[unit];
|
||||
var arg = unit === C.D ? this.$D + (_int - this.$W) : _int;
|
||||
|
||||
if (unit === C.M || unit === C.Y) {
|
||||
// clone is for badMutable plugin
|
||||
var date = this.clone().set(C.DATE, 1);
|
||||
date.$d[name](arg);
|
||||
date.init();
|
||||
this.$d = date.set(C.DATE, Math.min(this.$D, date.daysInMonth())).$d;
|
||||
} else if (name) this.$d[name](arg);
|
||||
|
||||
this.init();
|
||||
return this;
|
||||
};
|
||||
|
||||
_proto.set = function set(string, _int2) {
|
||||
return this.clone().$set(string, _int2);
|
||||
};
|
||||
|
||||
_proto.get = function get(unit) {
|
||||
return this[Utils.p(unit)]();
|
||||
};
|
||||
|
||||
_proto.add = function add(number, units) {
|
||||
var _this2 = this,
|
||||
_C$MIN$C$H$C$S$unit;
|
||||
|
||||
number = Number(number); // eslint-disable-line no-param-reassign
|
||||
|
||||
var unit = Utils.p(units);
|
||||
|
||||
var instanceFactorySet = function instanceFactorySet(n) {
|
||||
var d = dayjs(_this2);
|
||||
return Utils.w(d.date(d.date() + Math.round(n * number)), _this2);
|
||||
};
|
||||
|
||||
if (unit === C.M) {
|
||||
return this.set(C.M, this.$M + number);
|
||||
}
|
||||
|
||||
if (unit === C.Y) {
|
||||
return this.set(C.Y, this.$y + number);
|
||||
}
|
||||
|
||||
if (unit === C.D) {
|
||||
return instanceFactorySet(1);
|
||||
}
|
||||
|
||||
if (unit === C.W) {
|
||||
return instanceFactorySet(7);
|
||||
}
|
||||
|
||||
var step = (_C$MIN$C$H$C$S$unit = {}, _C$MIN$C$H$C$S$unit[C.MIN] = C.MILLISECONDS_A_MINUTE, _C$MIN$C$H$C$S$unit[C.H] = C.MILLISECONDS_A_HOUR, _C$MIN$C$H$C$S$unit[C.S] = C.MILLISECONDS_A_SECOND, _C$MIN$C$H$C$S$unit)[unit] || 1; // ms
|
||||
|
||||
var nextTimeStamp = this.$d.getTime() + number * step;
|
||||
return Utils.w(nextTimeStamp, this);
|
||||
};
|
||||
|
||||
_proto.subtract = function subtract(number, string) {
|
||||
return this.add(number * -1, string);
|
||||
};
|
||||
|
||||
_proto.format = function format(formatStr) {
|
||||
var _this3 = this;
|
||||
|
||||
var locale = this.$locale();
|
||||
if (!this.isValid()) return locale.invalidDate || C.INVALID_DATE_STRING;
|
||||
var str = formatStr || C.FORMAT_DEFAULT;
|
||||
var zoneStr = Utils.z(this);
|
||||
var $H = this.$H,
|
||||
$m = this.$m,
|
||||
$M = this.$M;
|
||||
var weekdays = locale.weekdays,
|
||||
months = locale.months,
|
||||
meridiem = locale.meridiem;
|
||||
|
||||
var getShort = function getShort(arr, index, full, length) {
|
||||
return arr && (arr[index] || arr(_this3, str)) || full[index].slice(0, length);
|
||||
};
|
||||
|
||||
var get$H = function get$H(num) {
|
||||
return Utils.s($H % 12 || 12, num, '0');
|
||||
};
|
||||
|
||||
var meridiemFunc = meridiem || function (hour, minute, isLowercase) {
|
||||
var m = hour < 12 ? 'AM' : 'PM';
|
||||
return isLowercase ? m.toLowerCase() : m;
|
||||
};
|
||||
|
||||
var matches = function matches(match) {
|
||||
switch (match) {
|
||||
case 'YY':
|
||||
return String(_this3.$y).slice(-2);
|
||||
|
||||
case 'YYYY':
|
||||
return Utils.s(_this3.$y, 4, '0');
|
||||
|
||||
case 'M':
|
||||
return $M + 1;
|
||||
|
||||
case 'MM':
|
||||
return Utils.s($M + 1, 2, '0');
|
||||
|
||||
case 'MMM':
|
||||
return getShort(locale.monthsShort, $M, months, 3);
|
||||
|
||||
case 'MMMM':
|
||||
return getShort(months, $M);
|
||||
|
||||
case 'D':
|
||||
return _this3.$D;
|
||||
|
||||
case 'DD':
|
||||
return Utils.s(_this3.$D, 2, '0');
|
||||
|
||||
case 'd':
|
||||
return String(_this3.$W);
|
||||
|
||||
case 'dd':
|
||||
return getShort(locale.weekdaysMin, _this3.$W, weekdays, 2);
|
||||
|
||||
case 'ddd':
|
||||
return getShort(locale.weekdaysShort, _this3.$W, weekdays, 3);
|
||||
|
||||
case 'dddd':
|
||||
return weekdays[_this3.$W];
|
||||
|
||||
case 'H':
|
||||
return String($H);
|
||||
|
||||
case 'HH':
|
||||
return Utils.s($H, 2, '0');
|
||||
|
||||
case 'h':
|
||||
return get$H(1);
|
||||
|
||||
case 'hh':
|
||||
return get$H(2);
|
||||
|
||||
case 'a':
|
||||
return meridiemFunc($H, $m, true);
|
||||
|
||||
case 'A':
|
||||
return meridiemFunc($H, $m, false);
|
||||
|
||||
case 'm':
|
||||
return String($m);
|
||||
|
||||
case 'mm':
|
||||
return Utils.s($m, 2, '0');
|
||||
|
||||
case 's':
|
||||
return String(_this3.$s);
|
||||
|
||||
case 'ss':
|
||||
return Utils.s(_this3.$s, 2, '0');
|
||||
|
||||
case 'SSS':
|
||||
return Utils.s(_this3.$ms, 3, '0');
|
||||
|
||||
case 'Z':
|
||||
return zoneStr;
|
||||
// 'ZZ' logic below
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return null;
|
||||
};
|
||||
|
||||
return str.replace(C.REGEX_FORMAT, function (match, $1) {
|
||||
return $1 || matches(match) || zoneStr.replace(':', '');
|
||||
}); // 'ZZ'
|
||||
};
|
||||
|
||||
_proto.utcOffset = function utcOffset() {
|
||||
// Because a bug at FF24, we're rounding the timezone offset around 15 minutes
|
||||
// https://github.com/moment/moment/pull/1871
|
||||
return -Math.round(this.$d.getTimezoneOffset() / 15) * 15;
|
||||
};
|
||||
|
||||
_proto.diff = function diff(input, units, _float) {
|
||||
var _this4 = this;
|
||||
|
||||
var unit = Utils.p(units);
|
||||
var that = dayjs(input);
|
||||
var zoneDelta = (that.utcOffset() - this.utcOffset()) * C.MILLISECONDS_A_MINUTE;
|
||||
var diff = this - that;
|
||||
|
||||
var getMonth = function getMonth() {
|
||||
return Utils.m(_this4, that);
|
||||
};
|
||||
|
||||
var result;
|
||||
|
||||
switch (unit) {
|
||||
case C.Y:
|
||||
result = getMonth() / 12;
|
||||
break;
|
||||
|
||||
case C.M:
|
||||
result = getMonth();
|
||||
break;
|
||||
|
||||
case C.Q:
|
||||
result = getMonth() / 3;
|
||||
break;
|
||||
|
||||
case C.W:
|
||||
result = (diff - zoneDelta) / C.MILLISECONDS_A_WEEK;
|
||||
break;
|
||||
|
||||
case C.D:
|
||||
result = (diff - zoneDelta) / C.MILLISECONDS_A_DAY;
|
||||
break;
|
||||
|
||||
case C.H:
|
||||
result = diff / C.MILLISECONDS_A_HOUR;
|
||||
break;
|
||||
|
||||
case C.MIN:
|
||||
result = diff / C.MILLISECONDS_A_MINUTE;
|
||||
break;
|
||||
|
||||
case C.S:
|
||||
result = diff / C.MILLISECONDS_A_SECOND;
|
||||
break;
|
||||
|
||||
default:
|
||||
result = diff; // milliseconds
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
return _float ? result : Utils.a(result);
|
||||
};
|
||||
|
||||
_proto.daysInMonth = function daysInMonth() {
|
||||
return this.endOf(C.M).$D;
|
||||
};
|
||||
|
||||
_proto.$locale = function $locale() {
|
||||
// get locale object
|
||||
return Ls[this.$L];
|
||||
};
|
||||
|
||||
_proto.locale = function locale(preset, object) {
|
||||
if (!preset) return this.$L;
|
||||
var that = this.clone();
|
||||
var nextLocaleName = parseLocale(preset, object, true);
|
||||
if (nextLocaleName) that.$L = nextLocaleName;
|
||||
return that;
|
||||
};
|
||||
|
||||
_proto.clone = function clone() {
|
||||
return Utils.w(this.$d, this);
|
||||
};
|
||||
|
||||
_proto.toDate = function toDate() {
|
||||
return new Date(this.valueOf());
|
||||
};
|
||||
|
||||
_proto.toJSON = function toJSON() {
|
||||
return this.isValid() ? this.toISOString() : null;
|
||||
};
|
||||
|
||||
_proto.toISOString = function toISOString() {
|
||||
// ie 8 return
|
||||
// new Dayjs(this.valueOf() + this.$d.getTimezoneOffset() * 60000)
|
||||
// .format('YYYY-MM-DDTHH:mm:ss.SSS[Z]')
|
||||
return this.$d.toISOString();
|
||||
};
|
||||
|
||||
_proto.toString = function toString() {
|
||||
return this.$d.toUTCString();
|
||||
};
|
||||
|
||||
return Dayjs;
|
||||
}();
|
||||
|
||||
var proto = Dayjs.prototype;
|
||||
dayjs.prototype = proto;
|
||||
[['$ms', C.MS], ['$s', C.S], ['$m', C.MIN], ['$H', C.H], ['$W', C.D], ['$M', C.M], ['$y', C.Y], ['$D', C.DATE]].forEach(function (g) {
|
||||
proto[g[1]] = function (input) {
|
||||
return this.$g(input, g[0], g[1]);
|
||||
};
|
||||
});
|
||||
|
||||
dayjs.extend = function (plugin, option) {
|
||||
if (!plugin.$i) {
|
||||
// install plugin only once
|
||||
plugin(option, Dayjs, dayjs);
|
||||
plugin.$i = true;
|
||||
}
|
||||
|
||||
return dayjs;
|
||||
};
|
||||
|
||||
dayjs.locale = parseLocale;
|
||||
dayjs.isDayjs = isDayjs;
|
||||
|
||||
dayjs.unix = function (timestamp) {
|
||||
return dayjs(timestamp * 1e3);
|
||||
};
|
||||
|
||||
dayjs.en = Ls[L];
|
||||
dayjs.Ls = Ls;
|
||||
dayjs.p = {};
|
||||
export default dayjs;
|
||||
13
src/uni_modules/wot-design-uni/dayjs/locale/en.js
Normal file
13
src/uni_modules/wot-design-uni/dayjs/locale/en.js
Normal file
@ -0,0 +1,13 @@
|
||||
/* eslint-disable */
|
||||
// English [en]
|
||||
// We don't need weekdaysShort, weekdaysMin, monthsShort in en.js locale
|
||||
export default {
|
||||
name: 'en',
|
||||
weekdays: 'Sunday_Monday_Tuesday_Wednesday_Thursday_Friday_Saturday'.split('_'),
|
||||
months: 'January_February_March_April_May_June_July_August_September_October_November_December'.split('_'),
|
||||
ordinal: function ordinal(n) {
|
||||
var s = ['th', 'st', 'nd', 'rd'];
|
||||
var v = n % 100;
|
||||
return "[" + n + (s[(v - 20) % 10] || s[v] || s[0]) + "]";
|
||||
}
|
||||
};
|
||||
59
src/uni_modules/wot-design-uni/dayjs/utils.js
Normal file
59
src/uni_modules/wot-design-uni/dayjs/utils.js
Normal file
@ -0,0 +1,59 @@
|
||||
/* eslint-disable */
|
||||
import * as C from './constant';
|
||||
|
||||
var padStart = function padStart(string, length, pad) {
|
||||
var s = String(string);
|
||||
if (!s || s.length >= length) return string;
|
||||
return "" + Array(length + 1 - s.length).join(pad) + string;
|
||||
};
|
||||
|
||||
var padZoneStr = function padZoneStr(instance) {
|
||||
var negMinutes = -instance.utcOffset();
|
||||
var minutes = Math.abs(negMinutes);
|
||||
var hourOffset = Math.floor(minutes / 60);
|
||||
var minuteOffset = minutes % 60;
|
||||
return "" + (negMinutes <= 0 ? '+' : '-') + padStart(hourOffset, 2, '0') + ":" + padStart(minuteOffset, 2, '0');
|
||||
};
|
||||
|
||||
var monthDiff = function monthDiff(a, b) {
|
||||
// function from moment.js in order to keep the same result
|
||||
if (a.date() < b.date()) return -monthDiff(b, a);
|
||||
var wholeMonthDiff = (b.year() - a.year()) * 12 + (b.month() - a.month());
|
||||
var anchor = a.clone().add(wholeMonthDiff, C.M);
|
||||
var c = b - anchor < 0;
|
||||
var anchor2 = a.clone().add(wholeMonthDiff + (c ? -1 : 1), C.M);
|
||||
return +(-(wholeMonthDiff + (b - anchor) / (c ? anchor - anchor2 : anchor2 - anchor)) || 0);
|
||||
};
|
||||
|
||||
var absFloor = function absFloor(n) {
|
||||
return n < 0 ? Math.ceil(n) || 0 : Math.floor(n);
|
||||
};
|
||||
|
||||
var prettyUnit = function prettyUnit(u) {
|
||||
var special = {
|
||||
M: C.M,
|
||||
y: C.Y,
|
||||
w: C.W,
|
||||
d: C.D,
|
||||
D: C.DATE,
|
||||
h: C.H,
|
||||
m: C.MIN,
|
||||
s: C.S,
|
||||
ms: C.MS,
|
||||
Q: C.Q
|
||||
};
|
||||
return special[u] || String(u || '').toLowerCase().replace(/s$/, '');
|
||||
};
|
||||
|
||||
var isUndefined = function isUndefined(s) {
|
||||
return s === undefined;
|
||||
};
|
||||
|
||||
export default {
|
||||
s: padStart,
|
||||
z: padZoneStr,
|
||||
m: monthDiff,
|
||||
a: absFloor,
|
||||
p: prettyUnit,
|
||||
u: isUndefined
|
||||
};
|
||||
@ -1,7 +1,7 @@
|
||||
/*
|
||||
* @Author: weisheng
|
||||
* @Date: 2021-12-21 14:22:03
|
||||
* @LastEditTime: 2025-03-25 14:01:43
|
||||
* @LastEditTime: 2025-07-10 16:25:42
|
||||
* @LastEditors: weisheng
|
||||
* @Description:
|
||||
* @FilePath: /wot-design-uni/src/uni_modules/wot-design-uni/index.ts
|
||||
@ -15,7 +15,7 @@ export { useUpload } from './components/composables/useUpload'
|
||||
export { useTouch } from './components/composables/useTouch'
|
||||
export * from './components/wd-notify'
|
||||
|
||||
export { dayjs } from './components/common/dayjs'
|
||||
export { default as dayjs } from './dayjs'
|
||||
|
||||
export * as CommonUtil from './components/common/util'
|
||||
export * as clickOut from './components/common/clickoutside'
|
||||
|
||||
@ -11,7 +11,7 @@ describe('分段器组件', () => {
|
||||
let isSelectAll = false
|
||||
let boundingClientRectCallback: ((rect: any) => void) | null = null
|
||||
|
||||
const mockQuery = {
|
||||
const mockQuery: any = {
|
||||
// 简化 in 方法,直接返回 mockQuery 自身
|
||||
in: vi.fn(() => {
|
||||
return mockQuery
|
||||
|
||||
@ -92,7 +92,7 @@ vi.stubGlobal('uni', {
|
||||
scrollLeft: 0
|
||||
}
|
||||
|
||||
const mockQuery = {
|
||||
const mockQuery: any = {
|
||||
// 支持 in 方法,用于组件内查询
|
||||
in: vi.fn((scope) => {
|
||||
currentScope = scope
|
||||
@ -235,7 +235,7 @@ vi.stubGlobal('uni', {
|
||||
let relativeToOptions: any = null
|
||||
let relativeToViewportOptions: any = null
|
||||
|
||||
const mockObserver = {
|
||||
const mockObserver: any = {
|
||||
relativeTo: vi.fn((selector, margins) => {
|
||||
relativeToOptions = { selector, margins }
|
||||
return mockObserver
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
/*
|
||||
* @Author: weisheng
|
||||
* @Date: 2025-04-09 00:02:58
|
||||
* @LastEditTime: 2025-05-05 17:35:42
|
||||
* @LastEditTime: 2025-07-10 15:33:49
|
||||
* @LastEditors: weisheng
|
||||
* @Description:
|
||||
* @FilePath: /wot-design-uni/vitest.config.ts
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user