mirror of
https://gitee.com/dgflash/oops-plugin-framework.git
synced 2026-05-08 19:37:07 +08:00
2. 存储模块性能提升,添加LRU缓存、批量操作支持,优化内存使用 3. 多语言模块性能与内存管理优化,组件查询性能提升 4. 时间模块类型安全与性能优化,使用泛型替代any,对象池机制减少内存分配 5. 事件系统修复双重注册、重复注册等严重问题,实现EventData对象池减少GC压力 6. RandomManager修复4个逻辑BUG,包括边界问题和越界问题 7. 音频模块内存与性能优化,避免重复加载,优化数据结构,添加完整清理机制 8. CCView与CCViewVM合并,支持按需启用MVVM 9. Collection模块优化,AsyncQueue添加队列容量限制,Collection查询性能提升 10. ECS系统全面优化,对象池复用减少内存分配,循环性能提升 11. 优化MVVM组件性能
68 lines
2.0 KiB
TypeScript
68 lines
2.0 KiB
TypeScript
declare global {
|
||
interface Date {
|
||
/**
|
||
* 时间格式化
|
||
* @param format 时间格式,例如:yy-mm-dd hh:mm:ss
|
||
*/
|
||
format(format: string): string;
|
||
|
||
/**
|
||
* 时间加法
|
||
* @param addMillis 时间加法,单位毫秒
|
||
*/
|
||
addTime(addMillis: number): Date;
|
||
|
||
/**
|
||
* 验证时间是否在指定范围
|
||
* @param t1 范围开始时间
|
||
* @param t2 范围结束时间
|
||
*/
|
||
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;
|
||
const day: number = this.getDate();
|
||
const hours: number = this.getHours();
|
||
const minutes: number = this.getMinutes();
|
||
const seconds: number = this.getSeconds();
|
||
const milliseconds: number = this.getMilliseconds();
|
||
|
||
// 优化:预格式化数字,减少字符串拼接
|
||
const pad = (n: number): string => n < 10 ? '0' + n : '' + n;
|
||
|
||
let r = format
|
||
.replace('yy', year.toString())
|
||
.replace('MM', pad(month))
|
||
.replace('dd', pad(day))
|
||
.replace('hh', pad(hours))
|
||
.replace('mm', pad(minutes))
|
||
.replace('ss', pad(seconds));
|
||
|
||
// 优化:简化毫秒格式化逻辑
|
||
if (r.includes('ms')) {
|
||
const ms = milliseconds < 10 ? '00' + milliseconds :
|
||
milliseconds < 100 ? '0' + milliseconds :
|
||
milliseconds.toString();
|
||
r = r.replace('ms', ms);
|
||
}
|
||
|
||
return r;
|
||
};
|
||
|
||
Date.prototype.addTime = function (addMillis: number): Date {
|
||
return new Date(this.getTime() + addMillis);
|
||
};
|
||
|
||
Date.prototype.range = function (d1: number | Date, d2: number | Date): boolean {
|
||
// 优化:简化逻辑,减少变量声明
|
||
const t1 = d1 instanceof Date ? d1.getTime() : d1;
|
||
const t2 = d2 instanceof Date ? d2.getTime() : d2;
|
||
const now = this.getTime();
|
||
return now >= t1 && now < t2;
|
||
};
|
||
|
||
export { };
|