优化组件/更新

This commit is contained in:
gyq
2025-12-03 10:13:55 +08:00
parent 92f9776a35
commit 09b6e36a52
261 changed files with 22080 additions and 7238 deletions

View File

@@ -1,2 +1,69 @@
## 1.0.62025-06-10
+ 【重要】新增支持鸿蒙运行环境。
+ 【重要】新增支持微信小程序运行环境。
## 1.0.52024-06-27
+ 修复时区偏移量计算bug。
## 1.0.42024-06-02
+ 修复 `isBefore``isSame``isAfter``isSameOrBefore``isSameOrAfter``isBetween` 等比较方法时总是以当前时间为基准比较的bug。
+ 修复安卓部分方法指定日期参数无效的bug。
## 1.0.32024-05-06
+ 【重要】不再支持编译器 4.1 以下版本,请及时更新编译器为 4.1 以上版本以更好兼容后续更新迭代。
+ 【重要】适配支持 `app-js` 引擎版本。(即目前ios的js引擎版本)。
+ 【重要】`diff` api 默认单位调整为毫秒,和 [dayjs](https://day.js.org/docs/zh-CN/display/difference) 实现保持一致。
+ `diff` 方法支持传入构造的 `Dayjs` 对象,示例如下:
```
import { dayjs } from '@/uni_modules/kux-dayjs';
const date1 = dayjs('2024-05-06 12:23:53');
console.log(date1.diff(dayjs('2024-05-06'), 'M')); // 结果为743
```
+ 修复 `startOf` 和 `endOf` 时间基准总是为当前时间的问题。
+ 调整函数签名解决编译器4.1以上版本不兼容的问题。
+ 优化其他已知问题。
## 1.0.22024-03-23
+ 支持通过字符串形式初始化实例,目前支持的字符串格式如下:
+ YYYY-MM-DD
+ YYYY/MM/DD
+ YYYY-MM-DD HH
+ YYYY-MM-DD HH:MM
+ YYYY-MM-DD HH:MM:SS
+ YYYY-MM-DD HH:MM:SS.millis
+ YYYY/MM/DD HH
+ YYYY/MM/DD HH:MM
+ YYYY/MM/DD HH:MM:SS
+ YYYY/MM/DD HH:MM:SS.millis
+ ISO 8601 格式(包括 UTC 时间)
示例代码如下:
```
console.log(dayjs('2023-12-13').format('YYYY-MM-DD'));
console.log(dayjs('2024/01/01').format('YYYY-MM-DD'));
console.log(dayjs('2023-12-13 12:23').format('YYYY-MM-DD HH:mm'));
console.log(dayjs('2023-12-13 12:23:45').format('YYYY-MM-DD HH:mm:ss'));
console.log(dayjs('2023-12-12 19:35:35.123').format('YYYY-MM-DD HH:mm:ss.SSS'));
console.log(dayjs('2023-12-13T10:16:18.000Z').format('YYYY-MM-DD HH:mm:ss'));
console.log(dayjs('2023-12-13T12:25:36.567+08:00').format('YYYY-MM-DD HH:mm:ss.SSS'));
```
+ 支持通过时间戳初始化实例,由于 `uts` 联合类型限制,所以目前通过字符串形式的时间戳传入参数,示例代码如下:
```
console.log(dayjs(`${dayjs().valueOf()}`, true).format('YYYY-MM-DD HH:mm:ss'));
console.log(dayjs('1683234305000', true).format('YY-MM-DD HH:mm:ss'));
```
+ 补全类和函数类型签名
> **说明**
>
> `HBuilderX` 版本 4.0 及以上才支持。
+ 修复部分场景下毫秒丢失的问题。
## 1.0.12024-01-30
+ 支持web版本【hbx4.0及以上支持】
+ `解析` 增加 `YY` 年份两位数选项,示例 YY23
## 1.0.02023-12-14
初始发布

View File

@@ -59,6 +59,7 @@ export type InfoType = {
isLeap : boolean;
}
// #ifndef APP-HARMONY
export type LunarInfoType = {
lYear : number;
lMonth : number;
@@ -79,6 +80,30 @@ export type LunarInfoType = {
Term ?: string;
astro ?: string
}
// #endif
// #ifdef APP-HARMONY
export interface LunarInfoType {
lYear : number;
lMonth : number;
lDay : number;
IMonthCn : string;
IDayCn : string;
cYear : number;
cMonth : number;
cDay : number;
gzYear ?: string;
gzMonth ?: string;
gzDay ?: string;
isToday : boolean;
isLeap : boolean;
nWeek ?: number;
ncWeek ?: string;
isTerm ?: boolean;
Term ?: string;
astro ?: string
}
// #endif
export class Lunar {

View File

@@ -1,63 +1,159 @@
import { Lunar, LunarInfoType } from './calendar';
export type DateType = {
fullDate: string;
year: number;
month: number;
date: number;
hour: number;
minute: number;
second: number;
millisecond: number;
day: number;
isToday: boolean;
lunar: string;
fullDate : string;
year : number;
month : number;
date : number;
hour : number;
minute : number;
second : number;
millisecond : number;
day : number;
isToday : boolean;
lunar : string;
};
export type DateInfo = {
year : number,
month : number,
day : number,
hours : number,
minutes : number,
seconds : number,
milliseconds : number
};
export class DateUtil {
private lunar: Lunar;
constructor () {
private lunar : Lunar;
private static readonly dateRegex = /^(\d{4})[-/](\d{1,2})[-/](\d{1,2})(?:[ T](\d{1,2}):(\d{1,2})(?::(\d{1,2})(?:\.(\d{1,3}))?)?)?(?:[ ]?(Z|[+-]\d{2}:\d{2}))?$/;
constructor() {
this.lunar = new Lunar();
};
/**
* 计算阴历日期显示
*/
getlunar (year : number, month : number, date : number) : LunarInfoType {
getlunar(year : number, month : number, date : number) : LunarInfoType {
return this.lunar.solar2lunar(year, month, date)
}
/**
* 解析时间戳
*/
parseTimestamp(timestamp : number) : DateInfo {
let mTimestamp : number = timestamp;
// 定义每个时间单位的毫秒数
const millisecondsPerSecond : number = 1000;
const millisecondsPerMinute = 60 * millisecondsPerSecond;
const millisecondsPerHour = 60 * millisecondsPerMinute;
const millisecondsPerDay = 24 * millisecondsPerHour;
// 计算总天数
let totalDays = Math.floor(mTimestamp / millisecondsPerDay);
mTimestamp -= totalDays * millisecondsPerDay;
// 计算年、月、日
const startYear : number = 1970;
let year = startYear;
let month : number = 0;
let day : number = 0;
// 计算当前年是否为闰年
const isLeapYear = (year : number) : boolean => (year % 4 == 0 && year % 100 != 0) || year % 400 == 0;
// 计算年份
while (true) {
const daysInYear = isLeapYear(year) ? 366 : 365;
if (totalDays >= daysInYear) {
totalDays -= daysInYear;
year++;
} else {
break;
}
}
// 计算月份
const daysInMonth = [31, isLeapYear(year) ? 29 : 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];
for (month = 0; month < daysInMonth.length; month++) {
if (totalDays < daysInMonth[month]) {
break;
}
totalDays -= daysInMonth[month];
}
month++; // 月份是从0开始的所以需要+1
day = totalDays + 1; // 加1是因为总天数已经减去了一整天的毫秒数
// 计算小时、分钟、秒
const hours = Math.floor(mTimestamp / millisecondsPerHour) % 24;
mTimestamp -= hours * millisecondsPerHour;
const minutes = Math.floor(mTimestamp / millisecondsPerMinute) % 60;
mTimestamp -= minutes * millisecondsPerMinute;
const seconds = Math.floor(mTimestamp / millisecondsPerSecond) % 60;
const milliseconds = mTimestamp % millisecondsPerSecond;
return {
year,
month,
day,
hours,
minutes,
seconds,
milliseconds
} as DateInfo;
}
/**
* 获取任意时间
*/
getDate (date: string): DateType {
let dd: Date = new Date();
let hour = 0;
let minute = 0;
let second = 0;
let milllisceond = 0;
if (date !== '') {
const datePart = date.split(" ");
const dateData = datePart[0].split("-");
const year = parseInt(dateData[0]);
const month = parseInt(dateData[1]);
const day = parseInt(dateData[2]);
if (datePart.length > 1) {
const timeData = datePart[1].split(":");
hour = parseInt(timeData[0]);
minute = parseInt(timeData[1]);
const secondPart = timeData[2].split(".");
second = parseInt(secondPart[0]);
if (secondPart.length > 1) {
milllisceond = parseInt(secondPart[1]);
}
getDate(date : string) : DateType {
let dd : Date = new Date();
// 使用正则表达式解析日期和时间
const match = date.match(DateUtil.dateRegex);
if (match != null && match[1] != null && match[2] != null && match[3] != null && match.length > 0) {
// 解构匹配结果
// const [_, year, month, day, hour, minute, second, milllisceond] = match;
const yearR = parseInt(match[1]!, 10);
const monthR = parseInt(match[2]!, 10);
const dayR = parseInt(match[3]!, 10);
let hourR = 0;
if (match.length >= 5 && match[4] != null) {
hourR = parseInt(match[4]!, 10);
}
let minuteR = 0;
if (match.length >= 6 && match[5] != null) {
minuteR = parseInt(match[5]!, 10);
}
let secondR = 0;
if (match.length >= 7 && match[6] != null) {
secondR = parseInt(match[6]!, 10);
}
let millisceondR = 0;
if (match.length >= 8 && match[7] != null) {
millisceondR = parseInt(match[7]!, 10);
}
let timezoneOffset: string | null = null;
if (match.length >= 9 && match[8] != null) {
timezoneOffset = match[8];
}
// 创建 Date 对象
dd = new Date(yearR, monthR - 1, dayR, hourR, minuteR, secondR, millisceondR);
// 应用时区偏移
if (timezoneOffset != null && timezoneOffset != 'Z') {
const offsetSign = (timezoneOffset.split(''))[0] == '+' ? 1 : -1;
const offsetHours = 8 - parseInt(timezoneOffset.substring(1, 3), 10);
const offsetMinutes = parseInt(timezoneOffset.substring(4, 6), 10);
const offsetMilliseconds = (offsetHours * 60 + offsetMinutes) * 60 * 1000 * offsetSign;
dd = new Date(dd.getTime() + offsetMilliseconds);
}
dd = new Date(year, month - 1, day, hour, minute, second, milllisceond);
}
const y = dd.getFullYear();
const m = dd.getMonth() + 1;
const d = dd.getDate();
@@ -65,11 +161,11 @@ export class DateUtil {
const M = dd.getMinutes();
const s = dd.getSeconds();
const ms = dd.getMilliseconds();
let nowDate = y + '-' + m + '-' + d;
const lunarData = this.getlunar(y, m, d);
const data: DateType = {
const data : DateType = {
fullDate: nowDate,
year: y,
month: m,
@@ -82,7 +178,7 @@ export class DateUtil {
lunar: lunarData.IDayCn,
isToday: this.getlunar(y, m, d).isToday
};
return data;
};
};
};

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,12 @@
// #ifdef APP-ANDROID
import MathFloor from 'kotlin.math.floor';
// #endif
export const floor = (value: number): number => {
// #ifndef APP-ANDROID
return Math.floor(value);
// #endif
// #ifdef APP-ANDROID
return Number.from(MathFloor(value.toDouble()));
// #endif
}

View File

@@ -1,18 +1,19 @@
{
"id": "kux-dayjs",
"displayName": "kux-dayjs",
"version": "1.0.0",
"description": "一个极简的 `uts`API 设计完全参考 `dayjs` 的设计、所以上手该库基本零成本了,方便开发者们验证、操作和显示日期和时间。",
"version": "1.0.6",
"description": "一个极简的 uts 库API 设计完全参考 dayjs 的设计、所以上手该库基本零成本了,方便开发者们验证、操作和显示日期和时间。",
"keywords": [
"时间",
"日期",
"格式化",
"day",
"date"
"kux-dayjs",
"dayjs",
"时间格式化",
"日期"
],
"repository": "https://gitcode.net/kviewui/kviewui-x",
"repository": "https://gitcode.com/kviewui/kux-dayjs",
"engines": {
"HBuilderX": "^3.6.8"
"HBuilderX": "^3.6.8",
"uni-app": "^4.66",
"uni-app-x": "^4.66"
},
"dcloudext": {
"type": "uts",
@@ -32,54 +33,69 @@
"data": "插件不采集任何数据",
"permissions": "无"
},
"npmurl": ""
"npmurl": "",
"darkmode": "x",
"i18n": "x",
"widescreen": "x"
},
"uni_modules": {
"dependencies": [],
"encrypt": [],
"platforms": {
"cloud": {
"tcb": "y",
"aliyun": "y"
"tcb": "",
"aliyun": "√",
"alipay": "x"
},
"client": {
"Vue": {
"vue2": "n",
"vue3": "y"
"uni-app": {
"vue": {
"vue2": "-",
"vue3": "-"
},
"web": {
"safari": "-",
"chrome": "-"
},
"app": {
"vue": "-",
"nvue": "-",
"android": "-",
"ios": "-",
"harmony": "-"
},
"mp": {
"weixin": "-",
"alipay": "-",
"toutiao": "-",
"baidu": "-",
"kuaishou": "-",
"jd": "-",
"harmony": "-",
"qq": "-",
"lark": "-"
},
"quickapp": {
"huawei": "-",
"union": "-"
}
},
"App": {
"app-android": {
"minVersion": "19"
},
"app-ios": "n"
},
"H5-mobile": {
"Safari": "n",
"Android Browser": "n",
"微信浏览器(Android)": "n",
"QQ浏览器(Android)": "n"
},
"H5-pc": {
"Chrome": "n",
"IE": "n",
"Edge": "n",
"Firefox": "n",
"Safari": "n"
},
"小程序": {
"微信": "n",
"阿里": "n",
"百度": "n",
"字节跳动": "n",
"QQ": "n",
"钉钉": "n",
"快手": "n",
"飞书": "n",
"京东": "n"
},
"快应用": {
"华为": "n",
"联盟": "n"
"uni-app-x": {
"web": {
"safari": "√",
"chrome": "√"
},
"app": {
"android": {
"extVersion": "",
"minVersion": "21"
},
"ios": "√",
"harmony": "√"
},
"mp": {
"weixin": "√"
}
}
}
}

View File

@@ -1,13 +1,17 @@
# kux-dayjs
`KuxDayjs` 是一个极简的 `uts`API 设计完全参考 `dayjs` 的设计、所以上手该库基本零成本了,方便开发者们验证、操作和显示日期和时间。
## 开源地址:[https://gitcode.com/kviewui/kux-dayjs](https://gitcode.com/kviewui/kux-dayjs)
## 目录结构
<ol>
<div class="kux-ol" style="list-style-type: none;">
<ol style="list-style-type: none;">
<li><a href="#import">导入插件</a></li>
<li><a href="#parse">解析</a>
<ol>
<li><a href="#parse_shili">实例</a></li>
<li><a href="#parse_dangqianshijian">当前时间</a></li>
<li><a href="#parse_string">字符串</a></li>
<li><a href="#parse_clone">克隆复制</a></li>
</ol>
</li>
@@ -64,33 +68,88 @@
<li><a href="#display_isLeapYear">是否闰年</a></li>
</ol>
</li>
<li><a href="#customType">自定义类型</a>
<ol>
<li><a href="#customType_InfoType">InfoType</a></li>
<li><a href="#customType_LunarType">LunarType</a></li>
<li><a href="#customType_DatetimeUnit">DatetimeUnit</a></li>
<li><a href="#customType_DiffUnit">DiffUnit</a></li>
<li><a href="#customType_DateFormat">DateFormat</a></li>
<li><a href="#customType_RelativeTime">RelativeTime</a></li>
<li><a href="#customType_FromToOptions">FromToOptions</a></li>
<li><a href="#customType_DatetimeOptions">DatetimeOptions</a></li>
<li><a href="#customType_IsBetweenContains">IsBetweenContains</a></li>
</ol>
</li>
</ol>
</div>
### 导入插件
<a id="import"></a>
### 导入插件
```ts
import { dayjs } from '@/uni_modules/kux-dayjs';
```
### 解析
<a id="parse"></a>
### 解析
#### 实例
<a id="parse_shili"></a>
#### 实例
代替修改本地Date.prototype`KuxDayjs``Date` 对象进行了封装,只需要调用 `dayjs()` 即可
`KuxDayjs` 对象是不可变的,也就是说,以某种方式改变 `KuxDayjs` 对象的所有API操作都将返回它的一个新实例。
#### 当前时间
<a id="parse_dangqianshijian"></a>
#### 当前时间
直接调用 `dayjs()` 将返回一个包含当前日期和时间的 `KuxDayjs` 对象。
```ts
const now = dayjs();
```
>目前仅支持传入 `YYYY-MM-DD HH:mm:ss.S` 格式的日期时间字符串
>
> `1.0.2` 及以上版本支持字符串解析。请看 [字符串](#parse_string)
<a id="parse_string"></a>
#### 字符串
`1.0.2` 及以上版本开始支持字符串解析,支持各种主流字符串格式,具体如下:
+ YYYY-MM-DD
+ YYYY/MM/DD
+ YYYY-MM-DD HH
+ YYYY-MM-DD HH:MM
+ YYYY-MM-DD HH:MM:SS
+ YYYY-MM-DD HH:MM:SS.millis
+ YYYY/MM/DD HH
+ YYYY/MM/DD HH:MM
+ YYYY/MM/DD HH:MM:SS
+ YYYY/MM/DD HH:MM:SS.millis
+ ISO 8601 格式(包括 UTC 时间)
示例代码
```
console.log(dayjs('2023-12-13').format('YYYY-MM-DD'));
console.log(dayjs('2024/01/01').format('YYYY-MM-DD'));
console.log(dayjs('2023-12-13 12:23').format('YYYY-MM-DD HH:mm'));
console.log(dayjs('2023-12-13 12:23:45').format('YYYY-MM-DD HH:mm:ss'));
console.log(dayjs('2023-12-12 19:35:35.123').format('YYYY-MM-DD HH:mm:ss.SSS'));
console.log(dayjs('2023-12-13T10:16:18.000Z').format('YYYY-MM-DD HH:mm:ss'));
console.log(dayjs('2023-12-13T12:25:36.567+08:00').format('YYYY-MM-DD HH:mm:ss.SSS'));
console.log(dayjs(`${dayjs().valueOf()}`, true).format('YYYY-MM-DD HH:mm:ss'));
console.log(dayjs('1683234305000', true).format('YY-MM-DD HH:mm:ss'));
```
> **参数说明**
>
> 初始化参数目前为三个,见下面表格
>
> | 参数名 | 类型 | 必填 | 默认值 | 说明
> | --- | --- | --- | --- | ---
> | date | string | 否 | | 日期时间字符串,支持字符串格式的时间戳解析
> | isTimestamp | boolean | 否 | false | 是否为时间戳,是的话内部会自动转为整数作为时间戳解析
> | isCST | boolean | 否 | true | 是否是中国标准时间既UTC时间+8小时`isTimestamp` 为 `true` 时生效,默认为 `true`
#### 克隆复制
<a id="parse_clone"></a>
#### 克隆复制
所有的 `KuxDayjs` 对象都是不可变的。 但如果有必要,使用 `dayjs().clone()` 可以复制出一个当前对象。
```ts
const a = dayjs();
@@ -98,11 +157,11 @@ const b = a.clone();
// a 和 b 是两个独立的 KuxDayjs 对象
```
### 取值/赋值
<a id="getset"></a>
### 取值/赋值
#### 毫秒
<a id="getset_millisecond"></a>
#### 毫秒
获取或设置毫秒。<br/>
传入0到999的数字。 如果超出这个范围,它会进位到秒。
```ts
@@ -110,8 +169,8 @@ dayjs().millisecond()
dayjs().millisecond(1)
```
#### 秒
<a id="getset_second"></a>
#### 秒
获取或设置秒。<br/>
传入0到59的数字。 如果超出这个范围,它会进位到分钟。
```ts
@@ -119,8 +178,8 @@ dayjs().second()
dayjs().second(1)
```
#### 分钟
<a id="getset_minute"></a>
#### 分钟
获取或设置分钟。<br/>
传入0到59的数字。 如果超出这个范围,它会进位到小时。
```ts
@@ -128,8 +187,8 @@ dayjs().minute()
dayjs().minute(59)
```
#### 小时
<a id="getset_hour"></a>
#### 小时
获取或设置小时。<br/>
传入0到23的数字。 如果超出这个范围,它会进位到天数。
```ts
@@ -137,8 +196,8 @@ dayjs().hour()
dayjs().hour(12)
```
#### 日期
<a id="getset_date"></a>
#### 日期
获取或设置日期。<br/>
传入1到31的数字。 如果超出这个范围,它会进位到月份。
```ts
@@ -147,8 +206,8 @@ dayjs().date(1)
```
> ****注意****<br/>`dayjs().date()` 是该月的日期。`dayjs().day()` 是星期几。
#### 星期
<a id="getset_day"></a>
#### 星期
获取或设置星期几。<br/>
传入 number 从0(星期天)到6(星期六)。 如果超出这个范围,它会进位到其他周。
```ts
@@ -157,8 +216,8 @@ dayjs().day(0)
```
> ****注意****<br/>`dayjs().date()` 是该月的日期。`dayjs().day()` 是星期几。
#### 时间
<a id="getset_time"></a>
#### 时间
获取或设置时间。<br/>
传入一个整数,表示从 1970-1-1 00:00:00 UTC 开始计时的毫秒数。 传入参数就是设置操作,否则为获取操作。
```ts
@@ -166,8 +225,8 @@ dayjs().time()
dayjs().time(1)
```
#### 月
<a id="getset_month"></a>
#### 月
获取或设置月份。<br/>
传入0到11的 number。 如果超出这个范围,它会进位到年份。
```ts
@@ -176,24 +235,24 @@ dayjs().month(0)
```
> ****注意****<br/>月份是从 0 开始计算的,即 1 月是 0。
#### 年
<a id="getset_year"></a>
#### 年
获取或设置年份。<br/>
```ts
dayjs().year()
dayjs().year(2000)
```
### 操作
<a id="manipulate"></a>
### 操作
您可能需要一些方法来操作 `KuxDayjs` 对象。<br/>
`KuxDayjs` 支持像这样的链式调用。
```ts
dayjs('2019-01-25').add(1, 'day').subtract(1, 'year').year(2009);
```
#### 增加
<a id="manipulate_add"></a>
#### 增加
返回增加一定时间的复制的 `KuxDayjs` 对象。
```ts
dayjs().add(7, 'day')
@@ -208,8 +267,8 @@ dayjs().add(7, 'day')
+ second 秒,缩写 `s`
+ millisecond 毫秒,缩写 `ms`
#### 减去
<a id="manipulate_subtract"></a>
#### 减去
返回减去一定时间的复制的 `KuxDayjs` 对象。
```ts
dayjs().subtract(7, 'day')
@@ -224,15 +283,15 @@ dayjs().subtract(7, 'day')
+ second 秒,缩写 `s`
+ millisecond 毫秒,缩写 `ms`
#### 今天
<a id="manipulate_today"></a>
#### 今天
返回设置时间为今天的复制的 `KuxDayjs` 对象。
```ts
dayjs().today()
```
#### 时间的开始
<a id="manipulate_startOf"></a>
#### 时间的开始
返回复制的 `KuxDayjs` 对象,并设置到一个时间的开始。
```ts
dayjs().startOf('year')
@@ -249,8 +308,8 @@ dayjs().startOf('year')
>****注意****<br/>暂时不支持跨年操作。
#### 时间的结束
<a id="manipulate_endOf"></a>
#### 时间的结束
返回复制的 `KuxDayjs` 对象,并设置到一个时间的末尾。
```ts
dayjs().endOf('month')
@@ -267,12 +326,12 @@ dayjs().endOf('month')
>****注意****<br/>暂时不支持跨年操作。
### 显示
<a id="display"></a>
### 显示
当解析和操作完成后,您需要一些方式来展示 `KuxDayjs` 对象。
#### 格式化
<a id="display_format"></a>
#### 格式化
根据传入的占位符返回格式化后的日期。
```ts
dayjs().format('YYYY-MM-DD HH:mm:ss')
@@ -284,6 +343,7 @@ dayjs().format('YYYY-MM-DD HH:mm:ss A')
| 标识 | 示例 | 描述 |
| --- | --- | --- |
| YYYY | 2023 | 年份,四位数 |
| YY | 23 | 年份,两位数 |
| MM | 12 | 月份 |
| DD | 01 | 日,两位数 |
| HH | 22 | 小时,两位数 |
@@ -294,8 +354,8 @@ dayjs().format('YYYY-MM-DD HH:mm:ss A')
| a | am/pm | 上/下午,小写 |
| AA | 上/下午 | 上/下午 |
#### 相对当前时间(前)
<a id="display_fromNow"></a>
#### 相对当前时间(前)
返回现在到当前实例的相对时间。
```ts
dayjs('2021-12-12').fromNow(); // 1年前
@@ -308,22 +368,22 @@ dayjs('2021-12-12').fromNow(); // 1年前
| relativeTime | `{s: '', m: '', mm: '', h: '', hh: '', d: '', dd: '', mon: '', mons: '', y: '', yy: ''}` | 自定义格式,变量说明见下方说明 |
#### RelativeTime 说明
| 范围 | 键 | 使用变量 | 说明 | 示例 |
| 范围 | 键 | 使用变量 | 说明 | 示例 |
| --- | --- | --- | --- | --- |
| 0 to 44seconds | s | %s | 几秒前 | %s seconds ago |
| 45 to 89 seconds | m | %m | 1分钟前 | %m minute ago |
| 90 seconds to 44 minutes | mm | %mm | 几分钟前 | %mm minutes ago |
| 45 to 89 minutes | h | %h | 1小时前 | %h hour ago |
| 90 minutes to 21 hours | hh | %hh | 几小时前 | %hh hours ago |
| 22 to 35 hours | d | d | %d | 1天前 | %d day ago |
| 22 to 35 hours | d | %d | 1天前 | %d day ago |
| 36 hours to 25 days | dd | %dd | 几天前 | %dd days ago |
| 26 to 45 days | mon | %mon | 1个月前 | %mon month ago |
| 46 days to 10 months | mons | %mons | 几个月前 | %mons months ago |
| 11 months to 17 months | y | %y | 1年前 | %y year ago |
| 18 months + | yy | %yy | 几年前 | %yy years ago |
#### 相对指定时间(前)
<a id="display_from"></a>
#### 相对指定时间(前)
返回 X 到当前实例的相对时间。
```ts
const datetime = dayjs('2021-12-12 15:43:58');
@@ -338,22 +398,22 @@ datetime.from(a); // 1年前
| relativeTime | `{s: '', m: '', mm: '', h: '', hh: '', d: '', dd: '', mon: '', mons: '', y: '', yy: ''}` | 自定义格式,变量说明见下方说明 |
#### RelativeTime 说明
| 范围 | 键 | 使用变量 | 说明 | 示例 |
| 范围 | 键 | 使用变量 | 说明 | 示例 |
| --- | --- | --- | --- | --- |
| 0 to 44seconds | s | %s | 几秒前 | %s seconds ago |
| 45 to 89 seconds | m | %m | 1分钟前 | %m minute ago |
| 90 seconds to 44 minutes | mm | %mm | 几分钟前 | %mm minutes ago |
| 45 to 89 minutes | h | %h | 1小时前 | %h hour ago |
| 90 minutes to 21 hours | hh | %hh | 几小时前 | %hh hours ago |
| 22 to 35 hours | d | d | %d | 1天前 | %d day ago |
| 22 to 35 hours | d | %d | 1天前 | %d day ago |
| 36 hours to 25 days | dd | %dd | 几天前 | %dd days ago |
| 26 to 45 days | mon | %mon | 1个月前 | %mon month ago |
| 46 days to 10 months | mons | %mons | 几个月前 | %mons months ago |
| 11 months to 17 months | y | %y | 1年前 | %y year ago |
| 18 months + | yy | %yy | 几年前 | %yy years ago |
#### 相对当前时间(后)
<a id="display_toNow"></a>
#### 相对当前时间(后)
返回当前实例到现在的相对时间。
```ts
dayjs('2021-12-12').toNow(); // 1年后
@@ -366,22 +426,22 @@ dayjs('2021-12-12').toNow(); // 1年后
| relativeTime | `{s: '', m: '', mm: '', h: '', hh: '', d: '', dd: '', mon: '', mons: '', y: '', yy: ''}` | 自定义格式,变量说明见下方说明 |
#### RelativeTime 说明
| 范围 | 键 | 使用变量 | 说明 | 示例 |
| 范围 | 键 | 使用变量 | 说明 | 示例 |
| --- | --- | --- | --- | --- |
| 0 to 44seconds | s | %s | 几秒后 | %s seconds after |
| 45 to 89 seconds | m | %m | 1分钟后 | %m minute after |
| 90 seconds to 44 minutes | mm | %mm | 几分钟后 | %mm minutes after |
| 45 to 89 minutes | h | %h | 1小时后 | %h hour after |
| 90 minutes to 21 hours | hh | %hh | 几小时后 | %hh hours after |
| 22 to 35 hours | d | d | %d | 1天后 | %d day after |
| 22 to 35 hours | d | %d | 1天后 | %d day after |
| 36 hours to 25 days | dd | %dd | 几天后 | %dd days after |
| 26 to 45 days | mon | %mon | 1个月后 | %mon month after |
| 46 days to 10 months | mons | %mons | 几个月后 | %mons months after |
| 11 months to 17 months | y | %y | 1年后 | %y year after |
| 18 months + | yy | %yy | 几年后 | %yy years after |
#### 相对指定时间(后)
<a id="display_to"></a>
#### 相对指定时间(后)
返回当前实例到现在的相对时间。
```ts
const datetime = dayjs('2021-12-12 15:43:58');
@@ -396,22 +456,22 @@ console.log(datetime.to(a)); // 输出 1年后
| relativeTime | `{s: '', m: '', mm: '', h: '', hh: '', d: '', dd: '', mon: '', mons: '', y: '', yy: ''}` | 自定义格式,变量说明见下方说明 |
#### RelativeTime 说明
| 范围 | 键 | 使用变量 | 说明 | 示例 |
| 范围 | 键 | 使用变量 | 说明 | 示例 |
| --- | --- | --- | --- | --- |
| 0 to 44seconds | s | %s | 几秒后 | %s seconds after |
| 45 to 89 seconds | m | %m | 1分钟后 | %m minute after |
| 90 seconds to 44 minutes | mm | %mm | 几分钟后 | %mm minutes after |
| 45 to 89 minutes | h | %h | 1小时后 | %h hour after |
| 90 minutes to 21 hours | hh | %hh | 几小时后 | %hh hours after |
| 22 to 35 hours | d | d | %d | 1天后 | %d day after |
| 22 to 35 hours | d | %d | 1天后 | %d day after |
| 36 hours to 25 days | dd | %dd | 几天后 | %dd days after |
| 26 to 45 days | mon | %mon | 1个月后 | %mon month after |
| 46 days to 10 months | mons | %mons | 几个月后 | %mons months after |
| 11 months to 17 months | y | %y | 1年后 | %y year after |
| 18 months + | yy | %yy | 几年后 | %yy years after |
#### 日历时间
<a id="display_calendar"></a>
#### 日历时间
传入指定年月获取指定年月的日历面板数据,指定年月省略时默认获取当年年月的数据。返回 `DateFormat[]``DateFormat` 见下方说明。
```ts
dayjs().calendar();
@@ -458,8 +518,8 @@ dayjs().calendar();
| lunarD | `number` | 农历日期数字
| isLeap | `boolean` | 是否闰月
#### 差异Diff
<a id="display_diff"></a>
#### 差异Diff
返回指定单位下两个日期时间之间的差异。
```ts
const date1 = dayjs('2019-01-25');
@@ -486,70 +546,69 @@ date1.diff('2018-06-05', 'month', true) // 7.645161290322581;
+ second 秒,缩写 `s`
+ millisecond 毫秒,缩写 `ms`
#### Unix时间戳毫秒
<a id="display_valueOf"></a>
#### Unix时间戳毫秒
返回当前实例的 UNIX 时间戳13位数字毫秒
```ts
dayjs('2019-01-25').valueOf() // 1548381600000
```
#### Unix时间戳
<a id="display_unix"></a>
#### Unix时间戳
返回当前实例的 UNIX 时间戳10位数字
```ts
dayjs('2019-01-25').valueOf() // 1548381600
```
此值不包含毫秒信息,会进位到秒。
#### 获取月天数
<a id="display_daysInMonth"></a>
#### 获取月天数
获取当前月份包含的天数。
```ts
const date = dayjs('2023-12-12'); // 31
```
#### 转Date
<a id="display_toDate"></a>
#### 转Date
`KuxDayjs` 中获取原生的Date对象。
```ts
dayjs('2023-12-12').toDate();
```
#### 转数组
<a id="display_toArray"></a>
#### 转数组
返回一个包含各个时间信息的 Array。
```ts
const datetime = dayjs('2023-12-13 10:16:18');// [2023,12,13,10,16,18,0]
```
#### 转JSON
<a id="display_toJSON"></a>
#### 转JSON
序列化为 `ISO 8601` 格式的字符串。
```ts
dayjs('2023-12-13 10:16:18').toJSON(); // 2023-12-13T10:16:18.000Z
```
#### 转对象
<a id="display_toObject"></a>
#### 转对象
返回包含时间信息的 Object。
```ts
dayjs('2023-12-13 10:16:18').toObject(); // {"date":13,"hours":10,"milliseconds":0,"minutes":16,"months":12,"seconds":18,"years":2023}
```
#### 转字符串
<a id="display_toRFCString"></a>
#### 转字符串
返回包含时间信息的 `RFC 822``RFC 5322` 格式字符串。
```ts
dayjs('2023-12-13 10:16:18').toRFCString(); // Wed, 13 Dec 2023 10:16:18 GMT
```
### 查询
<a id="query"></a>
### 查询
`KuxDayjs` 对象还有很多查询的方法。
#### 是否之前
<a id="query_isBefore"></a>
#### 是否之前
表示 `KuxDayjs` 对象是否在另一个提供的日期时间之前。
```ts
dayjs('2023-12-13 10:16:18').isBefore('2024-12-12'); // true
@@ -567,8 +626,8 @@ dayjs('2023-12-13 10:16:18').isBefore('2024-12-12', 'year'); // true
+ second - 秒,缩写为 `s`
+ millisecond - 毫秒,缩写为 `ms`
#### 是否相同
<a id="query_isSame"></a>
#### 是否相同
表示 `KuxDayjs` 对象是否和另一个提供的日期时间相同。
```ts
dayjs('2023-12-13 10:16:18').isBefore('2023-12-12'); // false
@@ -586,8 +645,8 @@ dayjs('2023-12-13 10:16:18').isBefore('2023-12-12', 'year'); // true
+ second - 秒,缩写为 `s`
+ millisecond - 毫秒,缩写为 `ms`
#### 是否之后
<a id="query_isAfter"></a>
#### 是否之后
表示 `KuxDayjs` 对象是否在另一个提供的日期时间之后。
```ts
dayjs('2023-12-13 10:16:18').isAfter('2023-12-12'); // true
@@ -605,8 +664,8 @@ dayjs('2023-12-13 10:16:18').isAfter('2023-12-12', 'year'); // true
+ second - 秒,缩写为 `s`
+ millisecond - 毫秒,缩写为 `ms`
#### 是否相同或之前
<a id="query_isSameOrBefore"></a>
#### 是否相同或之前
表示 `KuxDayjs` 对象是和另一个提供的日期时间相同或在其之前。
```ts
dayjs('2023-12-13 10:16:18').isSameOrBefore('2023-12-12'); // false
@@ -624,8 +683,8 @@ dayjs('2023-12-13 10:16:18').isSameOrBefore('2023-12-12', 'year'); // true
+ second - 秒,缩写为 `s`
+ millisecond - 毫秒,缩写为 `ms`
#### 是否相同或之后
<a id="query_isSameOrAfter"></a>
#### 是否相同或之后
表示 `KuxDayjs` 对象是和另一个提供的日期时间相同或在其之前。
```ts
dayjs('2023-12-13 10:16:18').isSameOrAfter('2023-12-12'); // true
@@ -643,8 +702,8 @@ dayjs('2023-12-13 10:16:18').isSameOrAfter('2023-12-12', 'year'); // true
+ second - 秒,缩写为 `s`
+ millisecond - 毫秒,缩写为 `ms`
#### 是否两者之间
<a id="query_isBetween"></a>
#### 是否两者之间
表示 `KuxDayjs` 对象是否在其他两个的日期时间之间。
```ts
dayjs('2023-12-13').isBetween('2023-12-13', '2023-12-14'); // 默认毫秒
@@ -671,6 +730,7 @@ dayjs('2023-12-13').isBetween('2023-12-13', '2023-12-14', 'day', '[');
+ `]` - 向后包含,等同于 `>=`
+ `[]` - 前后都包含
<a id="display_isDayjs"></a>
#### 是否是KuxDayjs
这表示一个变量是否为 `KuxDayjs` 对象。
```ts
@@ -678,8 +738,155 @@ dayjs().isDayjs(dayjs()); // true
dayjs().isDayjs(new Date()); // false
```
<a id="display_isLeapYear"></a>
#### 是否闰年
查询 `KuxDayjs` 对象的年份是否是闰年。
```ts
dayjs('2000-01-01').isLeapYear(); // true
```
```
<a id="customType"></a>
### 自定义类型
因为 `uts` 强类型,所以有些 API 参数需要指定参数类型,以上所有 API 涉及的自定义类型都在下面列出,如果有需要可以自己手动导入类型使用。
<a id="customType_InfoType"></a>
#### InfoType
```ts
export type InfoType = {
lunarY : number;
lunarM : number;
lunarD : number;
isLeap : boolean;
}
```
<a id="customType_LunarType"></a>
#### LunarType
```ts
export type LunarType = {
month: string;
date: string;
};
```
<a id="customType_DatetimeUnit"></a>
#### DatetimeUnit
```ts
export type DatetimeUnit =
| 'day'
| 'd'
| 'month'
| 'M'
| 'year'
| 'y'
| 'hour'
| 'h'
| 'minute'
| 'm'
| 'second'
| 's'
| 'millisecond'
| 'ms'
```
<a id="customType_DiffUnit"></a>
#### DiffUnit
```ts
export type DiffUnit =
| 'week'
| 'w'
| 'day'
| 'd'
| 'month'
| 'M'
| 'year'
| 'y'
| 'hour'
| 'h'
| 'minute'
| 'm'
| 'second'
| 's'
| 'millisecond'
| 'ms'
```
<a id="customType_DateFormat"></a>
#### DateFormat
```ts
export type DateFormat = {
year: number;
month: number;
date: number;
render: any;
lunar: LunarType;
fullLunar: InfoType;
diffDays: number;
isToday: boolean;
fullDate: string;
};
```
<a id="customType_RelativeTime"></a>
#### RelativeTime
```ts
export type RelativeTime = {
s?: string;
m?: string;
mm?: string;
h?: string;
hh?: string;
d?: string;
dd?: string;
mon?: string;
mons?: string;
y?: string;
yy?: string;
};
```
<a id="customType_FromToOptions"></a>
#### FromToOptions
```ts
export type FromToOptions = {
isSuffix?: boolean;
relativeTime?: RelativeTime;
};
```
<a id="customType_DatetimeOptions"></a>
#### DatetimeOptions
```ts
export type DatetimeOptions = {
years: number;
months: number;
date: number;
hours: number;
minutes: number;
seconds: number;
milliseconds: number;
};
```
<a id="customType_IsBetweenContains"></a>
#### IsBetweenContains
```ts
export type IsBetweenContains =
| '['
| ']'
| '[]'
| ''
```
---
### 结语
#### kux 不生产代码只做代码的搬运工致力于提供uts 的 js 生态轮子实现,欢迎各位大佬在插件市场搜索使用 kux 生态插件:[https://ext.dcloud.net.cn/search?q=kux](https://ext.dcloud.net.cn/search?q=kux)
___
### 友情推荐
+ [GVIM即时通讯模版](https://ext.dcloud.net.cn/plugin?id=16419)GVIM即时通讯模版基于uni-app x开发的一款即时通讯模版
+ [t-uvue-ui](https://ext.dcloud.net.cn/plugin?id=15571)T-UVUE-UI是基于UNI-APP X开发的前端UI框架
+ [UxFrame 低代码高性能UI框架](https://ext.dcloud.net.cn/plugin?id=16148)【F2图表、双滑块slider、炫酷效果tabbar、拖拽排序、日历拖拽选择、签名...】UniAppX 高质量UI库
+ [wx-ui 基于uni-app x开发的高性能混合UI库](https://ext.dcloud.net.cn/plugin?id=15579)基于uni-app x开发的高性能混合UI库集成 uts api 和 uts component提供了一套完整、高效且易于使用的UI组件和API让您以更少的时间成本轻松完成高性能应用开发。
+ [firstui-uvue](https://ext.dcloud.net.cn/plugin?id=16294)FirstUIunix组件库一款适配 uni-app x 的轻量、简洁、高效、全面的移动端组件库。
+ [easyXUI 不仅仅是UI 更是为UniApp X设计的电商模板库](https://ext.dcloud.net.cn/plugin?id=15602)easyX 不仅仅是UI库更是一个轻量、可定制的UniAPP X电商业务模板库可作为官方组件库的补充,始终坚持简单好用、易上手

View File

@@ -0,0 +1 @@
export * from '../../common/index';

View File

@@ -0,0 +1 @@
export * from '../../common/index';

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1 @@
export * from '../../common/index';

View File

@@ -0,0 +1 @@
export * from '../../common/index';