diff --git a/assets/core/utils/DeviceUtil.ts b/assets/core/utils/DeviceUtil.ts index 823b687..02d4826 100644 --- a/assets/core/utils/DeviceUtil.ts +++ b/assets/core/utils/DeviceUtil.ts @@ -40,9 +40,6 @@ export class DeviceUtil { /** 是否为字节小游戏 */ static get isByteDance() { return sys.platform === sys.Platform.BYTEDANCE_MINI_GAME; } - /** 是否为百度小游戏 */ - static get isBaidu() { return sys.platform === sys.Platform.BAIDU_MINI_GAME; } - /** 是否为 vivo 小游戏 */ static get isVivo() { return sys.platform === sys.Platform.VIVO_MINI_GAME; } diff --git a/assets/core/utils/TimeUtils.ts b/assets/core/utils/TimeUtils.ts index 11a2873..dfd2161 100644 --- a/assets/core/utils/TimeUtils.ts +++ b/assets/core/utils/TimeUtils.ts @@ -6,7 +6,7 @@ export class TimeUtil { * @param time2 结束时间 * @returns */ - public static daysBetween(time1: number | string | Date, time2: number | string | Date): number { + static daysBetween(time1: number | string | Date, time2: number | string | Date): number { if (time2 == undefined) { time2 = +new Date(); } @@ -18,7 +18,7 @@ export class TimeUtil { } /** 间隔秒数,时间顺序无要求,最后会获取绝对值 */ - public static secsBetween(time1: number, time2: number) { + static secsBetween(time1: number, time2: number) { let dates = Math.abs((time2 - time1)) / (1000); dates = Math.floor(dates) + 1; return dates; @@ -28,7 +28,7 @@ export class TimeUtil { * 代码休眠时间 * @param ms 毫秒 */ - public static async sleep(ms: number) { + static async sleep(ms: number) { return new Promise((resolve) => { setTimeout(() => { resolve(); diff --git a/assets/libs/extension/DateExt.ts b/assets/libs/extension/DateExt.ts index 4120fec..46d72a2 100644 --- a/assets/libs/extension/DateExt.ts +++ b/assets/libs/extension/DateExt.ts @@ -1,10 +1,14 @@ declare global { interface Date { + /** 时间格式化 */ format(format: string): string; + /** 时间加法 */ + addTime(addMillis: number): Date; + /** 验证时间是否在指定范围 */ + range(t1: number | Date, t2: number | Date): boolean; } } -/** 格式化时间字符串 */ Date.prototype.format = function (format: string): string { const year: number = this.getFullYear(); const month: number = this.getMonth() + 1; @@ -35,4 +39,27 @@ Date.prototype.format = function (format: string): string { return r; }; -export { }; +Date.prototype.addTime = function (addMillis: number) { + return new Date(this.getTime() + addMillis); +} + +Date.prototype.range = function (d1: number | Date, d2: number | Date) { + let t1: number = -1; + let t2: number = -1; + if (d1 instanceof Date) + t1 = d1.getTime(); + else + t1 = d1; + if (d2 instanceof Date) + t2 = d2.getTime(); + else + t2 = d2; + + let now = this.getTime(); + if (now >= t1 && now < t2) { + return true; + } + return false; +} + +export { }; \ No newline at end of file