Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
DCloud
Hello UTS
提交
c1689373
H
Hello UTS
项目概览
DCloud
/
Hello UTS
通知
1594
Star
27
Fork
9
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
2
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
H
Hello UTS
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
2
Issue
2
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
提交
c1689373
编写于
9月 13, 2024
作者:
M
mahaifeng
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
[date]去除文档中手动生成的代码,添加注释
上级
203ba591
变更
1
显示空白变更内容
内联
并排
Showing
1 changed file
with
543 addition
and
306 deletion
+543
-306
uni_modules/uts-tests/utssdk/Date.uts
uni_modules/uts-tests/utssdk/Date.uts
+543
-306
未找到文件。
uni_modules/uts-tests/utssdk/Date.uts
浏览文件 @
c1689373
...
...
@@ -4,17 +4,28 @@ export function testDate() : Result {
return describe("Date", () => {
test('now', () => {
// #ifdef APP-ANDROID
UTSAndroid.getDispatcher("io").async(function(_)
{
UTSAndroid.getDispatcher("io").async(function (_)
{
const start = Date.now()
setTimeout(() => {
const millis = Date.now() - start
const secondsElapsed = Math.floor(millis / 1000)
expect(secondsElapsed).toEqual(2);
}, 2000)
},
null)
},
null)
// #endif
// #ifndef APP-ANDROID
// #TEST Date.now
const start = Date.now()
// this example takes 2 seconds to run
console.log('starting timer...')
// expected output: starting timer...
setTimeout(() => {
const millis = Date.now() - start
console.log(`seconds elapsed = ${Math.floor(millis / 1000)}`)
// expected output: seconds elapsed = 2
}, 2000)
// #END
setTimeout(() => {
const millis = Date.now() - start
const secondsElapsed = Math.floor(millis / 1000)
...
...
@@ -24,10 +35,30 @@ export function testDate() : Result {
})
test('new Date', () => {
// #TEST Date.Constructor
const futureDate = new Date();
console.log(futureDate)//日期和时间
// #END
// #TEST Date.Constructor_1
let date1 = new Date('1992-02-02');
console.log(date1.getTime()) // 696988800000
// #END
// #TEST Date.Constructor_2
let date7 = new Date(2016, 6, 6, 14, 6, 59, 1000)
console.log(date7.getMinutes()) //7
// #END
expect(date7.getMinutes()).toEqual(7);
expect(date1.getTime()).toEqual(696988800000);
// #ifdef APP-ANDROID
let date2 = new Date('Sun Feb 03 1991 08:00:00 GMT+0800');
expect(date2.getTime()).toEqual(665539200000);
let date3 = new Date('Sun Feb 03 1991');
expect(date3.getTime()).toEqual(665510400000);
/**
* iso 8601 相关
*/
...
...
@@ -45,7 +76,7 @@ export function testDate() : Result {
];
let timeStr = ""
for(let i = 0; i < isoCaseArr.length; i++)
{
for (let i = 0; i < isoCaseArr.length; i++)
{
let perDate = new Date(isoCaseArr[i])
timeStr += perDate.getTime()
}
...
...
@@ -61,7 +92,7 @@ export function testDate() : Result {
"December 17, 95 03:24:00 GMT+11:00",
"December 17, 1995, 03:24:00 GMT+11:00",
];
for(let i = 0; i < rfcCaseArr.length; i++)
{
for (let i = 0; i < rfcCaseArr.length; i++)
{
let perDate = new Date(rfcCaseArr[i])
timeStr += perDate.getTime()
}
...
...
@@ -78,7 +109,7 @@ export function testDate() : Result {
"2024/5/1 22:00",
"2024/5/1"
];
for(let i = 0; i < otherCaseArr.length; i++)
{
for (let i = 0; i < otherCaseArr.length; i++)
{
let perDate = new Date(otherCaseArr[i])
timeStr += perDate.getTime()
}
...
...
@@ -88,21 +119,38 @@ export function testDate() : Result {
})
test('valueOf', () => {
// #TEST Date.valueOf
const date1 = new Date('December 17, 1995 03:24:00');
console.log(date1.valueOf())//819141840000
// #END
expect(date1.valueOf()).toEqual(819141840000);
const date2 = new Date('1995-12-17T03:24:00');
expect(date2.valueOf()).toEqual(819141840000);
})
test('parse', () => {
// #TEST Date.parse
const unixTimeZero = Date.parse('01 Jan 1970 00:00:00 GMT');
console.log('Unix time zero:', unixTimeZero); // 0
const javaScriptRelease = Date.parse('04 Dec 1995 00:12:00 GMT');
console.log('JavaScript release:', javaScriptRelease); // 818035920000
// #END
expect(unixTimeZero).toEqual(0);
expect(javaScriptRelease).toEqual(818035920000);
})
});
test('toTimeString', () => {
const date1 = new Date('01 Jan 1970 00:00:00 GMT');
const date2 = new Date('December 17, 1995 03:24:00');
// #ifdef APP-IOS
console.log(date1.toTimeString())//"08:00:00 GMT+0800 (中国标准时间)"
// #endif
// #ifdef APP-ANDROID
console.log(date1.toTimeString())//"08:00:00 GMT+0800"
// #endif
// #ifdef APP-IOS
expect(date1.toTimeString()).toEqual("08:00:00 GMT+0800 (中国标准时间)");
...
...
@@ -116,14 +164,43 @@ export function testDate() : Result {
test('toXString', () => {
// #ifdef APP-ANDROID
const event = new Date('1995-12-17T03:24:00');
expect(event.toString()).toEqual("Sun Dec 17 1995 03:24:00 GMT+0800");
expect(event.toTimeString()).toEqual("03:24:00 GMT+0800");
// #TEST Date.toString
let event = new Date('1995-12-17T03:24:00');
let ret = event.toString()
console.log(ret)//"Sun Dec 17 1995 03:24:00 GMT+0800"
// #END
expect(ret).toEqual("Sun Dec 17 1995 03:24:00 GMT+0800");
// #TEST Date.toTimeString
event = new Date('1995-12-17T03:24:00');
let ret2 = event.toTimeString() // "03:24:00 GMT+0800"
// #END
expect(ret2).toEqual("03:24:00 GMT+0800");
// #TEST Date.toISOString
event = new Date('1995-12-17T03:24:00');
console.log(event.toISOString())//"1995-12-16T19:24:00.000Z"
// #END
expect(event.toISOString()).toEqual("1995-12-16T19:24:00.000Z");
// #TEST Date.toJSON
event = new Date('1995-12-17T03:24:00');
console.log(event.toJSON()) //"1995-12-16T19:24:00.000Z"
// #END
expect(event.toJSON()).toEqual("1995-12-16T19:24:00.000Z");
expect(event.toDateString()).toEqual("Sun Dec 17 1995");
// #TEST Date.toDateString
event = new Date('1995-12-17T03:24:00');
let ret1 = event.toDateString() //"Sun Dec 17 1995"
// #END
expect(ret1).toEqual("Sun Dec 17 1995");
const event2 = new Date('2014-01-09 22:00:00');
expect(event2.toString()).toEqual("Thu Jan 09 2014 22:00:00 GMT+0800");
expect(event2.toTimeString()).toEqual("22:00:00 GMT+0800");
expect(event2.toISOString()).toEqual("2014-01-09T14:00:00.000Z");
...
...
@@ -145,81 +222,145 @@ export function testDate() : Result {
// #endif
})
test('getDate', () => {
// #TEST Date.getDate
// Common variables
const birthday = new Date('August 19, 1975 23:15:30');
const date1 = birthday.getDate();
expect(date1).toEqual(19);
// first millisecond
expect(new Date(2016, 6, 6).getDate()).toEqual(6);
// previous millisecond
expect(new Date(2016, 6, 6, 0, 0, 0, -1).getDate()).toEqual(5);
// final millisecond
expect(new Date(2016, 6, 6, 23, 59, 59, 999).getDate()).toEqual(6);
// subsequent millisecond
expect(new Date(2016, 6, 6, 23, 59, 59, 1000).getDate()).toEqual(7);
const firstMillisecondDate = new Date(2016, 6, 6);
const previousMillisecondDate = new Date(2016, 6, 6, 0, 0, 0, -1);
const finalMillisecondDate = new Date(2016, 6, 6, 23, 59, 59, 999);
const subsequentMillisecondDate = new Date(2016, 6, 6, 23, 59, 59, 1000);
const firstMonthBoundaryDate = new Date(2016, 1, 29);
const previousMonthBoundaryDate = new Date(2016, 1, 29, 0, 0, 0, -1);
const finalMonthBoundaryDate = new Date(2016, 1, 29, 23, 59, 59, 999);
const subsequentMonthBoundaryDate = new Date(2016, 1, 29, 23, 59, 59, 1000);
console.log('Birthday date:', birthday.getDate()); // 19
console.log('First millisecond date:', firstMillisecondDate.getDate()); // 6
console.log('Previous millisecond date:', previousMillisecondDate.getDate()); // 5
console.log('Final millisecond date:', finalMillisecondDate.getDate()); // 6
console.log('Subsequent millisecond date:', subsequentMillisecondDate.getDate()); // 7
// first millisecond (month boundary)
expect(new Date(2016, 1, 29).getDate()).toEqual(29);
// previous millisecond (month boundary)
expect(new Date(2016, 1, 29, 0, 0, 0, -1).getDate()).toEqual(28);
// final millisecond (month boundary)
expect(new Date(2016, 1, 29, 23, 59, 59, 999).getDate()).toEqual(29);
// subsequent millisecond (month boundary)
expect(new Date(2016, 1, 29, 23, 59, 59, 1000).getDate()).toEqual(1);
console.log('First millisecond (month boundary) date:', firstMonthBoundaryDate.getDate()); // 29
console.log('Previous millisecond (month boundary) date:', previousMonthBoundaryDate.getDate()); // 28
console.log('Final millisecond (month boundary) date:', finalMonthBoundaryDate.getDate()); // 29
console.log('Subsequent millisecond (month boundary) date:', subsequentMonthBoundaryDate.getDate()); // 1
// #ifndef WEB
// safari 15不支持此格式的日期字符串
expect(Date.parse("2024-01-09 22:00:00")).toEqual(1704808800000);
const parsedDate = Date.parse("2024-01-09 22:00:00");
console.log('Parsed date:', parsedDate); // 1704808800000
// #endif
})
// #END
expect(birthday.getDate()).toEqual(19);
expect(firstMillisecondDate.getDate()).toEqual(6);
expect(previousMillisecondDate.getDate()).toEqual(5);
expect(finalMillisecondDate.getDate()).toEqual(6);
expect(subsequentMillisecondDate.getDate()).toEqual(7);
expect(firstMonthBoundaryDate.getDate()).toEqual(29);
expect(previousMonthBoundaryDate.getDate()).toEqual(28);
expect(finalMonthBoundaryDate.getDate()).toEqual(29);
expect(subsequentMonthBoundaryDate.getDate()).toEqual(1);
// #ifndef WEB
expect(parsedDate).toEqual(1704808800000);
// #endif
});
test('getDay', () => {
// #TEST Date.getDay
const birthday = new Date('August 19, 1975 23:15:30');
const day1 = birthday.getDay();
expect(day1).toEqual(2);
// first millisecond
expect(new Date(2016, 6, 6).getDay()).toEqual(3);
// previous millisecond
expect(new Date(2016, 6, 6, 0, 0, 0, -1).getDay()).toEqual(2);
// final millisecond
expect(new Date(2016, 6, 6, 23, 59, 59, 999).getDay()).toEqual(3);
// subsequent millisecond
expect(new Date(2016, 6, 6, 23, 59, 59, 1000).getDay()).toEqual(4);
// first millisecond (week boundary)
expect(new Date(2016, 6, 9).getDay()).toEqual(6);
// previous millisecond (week boundary)
expect(new Date(2016, 6, 9, 0, 0, 0, -1).getDay()).toEqual(5);
// final millisecond (week boundary)
expect(new Date(2016, 6, 9, 23, 59, 59, 999).getDay()).toEqual(6);
// subsequent millisecond (week boundary)
expect(new Date(2016, 6, 9, 23, 59, 59, 1000).getDay()).toEqual(0);
})
const firstMillisecondDay = new Date(2016, 6, 6);
const previousMillisecondDay = new Date(2016, 6, 6, 0, 0, 0, -1);
const finalMillisecondDay = new Date(2016, 6, 6, 23, 59, 59, 999);
const subsequentMillisecondDay = new Date(2016, 6, 6, 23, 59, 59, 1000);
const firstWeekBoundaryDay = new Date(2016, 6, 9);
const previousWeekBoundaryDay = new Date(2016, 6, 9, 0, 0, 0, -1);
const finalWeekBoundaryDay = new Date(2016, 6, 9, 23, 59, 59, 999);
const subsequentWeekBoundaryDay = new Date(2016, 6, 9, 23, 59, 59, 1000);
console.log('Birthday day:', birthday.getDay()); // 2 (Tuesday)
console.log('First millisecond day:', firstMillisecondDay.getDay()); // 3 (Wednesday)
console.log('Previous millisecond day:', previousMillisecondDay.getDay()); // 2 (Tuesday)
console.log('Final millisecond day:', finalMillisecondDay.getDay()); // 3 (Wednesday)
console.log('Subsequent millisecond day:', subsequentMillisecondDay.getDay()); // 4 (Thursday)
console.log('First millisecond (week boundary) day:', firstWeekBoundaryDay.getDay()); // 6 (Saturday)
console.log('Previous millisecond (week boundary) day:', previousWeekBoundaryDay.getDay()); // 5 (Friday)
console.log('Final millisecond (week boundary) day:', finalWeekBoundaryDay.getDay()); // 6 (Saturday)
console.log('Subsequent millisecond (week boundary) day:', subsequentWeekBoundaryDay.getDay()); // 0 (Sunday)
// #END
expect(birthday.getDay()).toEqual(2);
expect(firstMillisecondDay.getDay()).toEqual(3);
expect(previousMillisecondDay.getDay()).toEqual(2);
expect(finalMillisecondDay.getDay()).toEqual(3);
expect(subsequentMillisecondDay.getDay()).toEqual(4);
expect(firstWeekBoundaryDay.getDay()).toEqual(6);
expect(previousWeekBoundaryDay.getDay()).toEqual(5);
expect(finalWeekBoundaryDay.getDay()).toEqual(6);
expect(subsequentWeekBoundaryDay.getDay()).toEqual(0);
});
test('getFullYear', () => {
// #TEST Date.getFullYear
const moonLanding = new Date('July 20, 69 00:20:18');
const firstMillisecondYear = new Date(2016, 0);
const previousMillisecondYear = new Date(2016, 0, 1, 0, 0, 0, -1);
const finalMillisecondYear = new Date(2016, 11, 31, 23, 59, 59, 999);
const subsequentMillisecondYear = new Date(2016, 11, 31, 23, 59, 59, 1000);
console.log('Moon landing year:', moonLanding.getFullYear()); // 1969
console.log('First millisecond year:', firstMillisecondYear.getFullYear()); // 2016
console.log('Previous millisecond year:', previousMillisecondYear.getFullYear()); // 2015
console.log('Final millisecond year:', finalMillisecondYear.getFullYear()); // 2016
console.log('Subsequent millisecond year:', subsequentMillisecondYear.getFullYear()); // 2017
// #END
expect(moonLanding.getFullYear()).toEqual(1969);
// first millisecond
expect(new Date(2016, 0).getFullYear()).toEqual(2016);
// previous millisecond
expect(new Date(2016, 0, 1, 0, 0, 0, -1).getFullYear()).toEqual(2015);
// final millisecond
expect(new Date(2016, 11, 31, 23, 59, 59, 999).getFullYear()).toEqual(2016);
// subsequent millisecond
expect(new Date(2016, 11, 31, 23, 59, 59, 1000).getFullYear()).toEqual(2017);
})
expect(firstMillisecondYear.getFullYear()).toEqual(2016);
expect(previousMillisecondYear.getFullYear()).toEqual(2015);
expect(finalMillisecondYear.getFullYear()).toEqual(2016);
expect(subsequentMillisecondYear.getFullYear()).toEqual(2017);
});
test('getHours', () => {
// #TEST Date.getHours
const birthday = new Date('March 13, 08 04:20');
console.log('Birthday hours:', birthday.getHours()); // 4
const date1 = new Date(2016, 6, 6, 13);
const date2 = new Date(2016, 6, 6, 13, 0, 0, -1);
const date3 = new Date(2016, 6, 6, 13, 59, 59, 999);
const date4 = new Date(2016, 6, 6, 13, 59, 59, 1000);
console.log('First millisecond hours:', date1.getHours()); // 13
console.log('Previous millisecond hours:', date2.getHours()); // 12
console.log('Final millisecond hours:', date3.getHours()); // 13
console.log('Subsequent millisecond hours:', date4.getHours()); // 14
// #END
expect(birthday.getHours()).toEqual(4);
// first millisecond
expect(new Date(2016, 6, 6, 13).getHours()).toEqual(13);
// previous millisecond
expect(new Date(2016, 6, 6, 13, 0, 0, -1).getHours()).toEqual(12);
// final millisecond
expect(new Date(2016, 6, 6, 13, 59, 59, 999).getHours()).toEqual(13);
// subsequent millisecond
expect(new Date(2016, 6, 6, 13, 59, 59, 1000).getHours()).toEqual(14);
})
expect(date1.getHours()).toEqual(13);
expect(date2.getHours()).toEqual(12);
expect(date3.getHours()).toEqual(13);
expect(date4.getHours()).toEqual(14);
});
test('getMilliseconds', () => {
const moonLanding = new Date('July 20, 69 00:20:18');
...
...
@@ -236,95 +377,191 @@ export function testDate() : Result {
expect(new Date(2016, 6, 6, 23, 59, 59, 1000).getMilliseconds()).toEqual(0);
})
test('getMinutes', () => {
// #TEST Date.getMinutes
const birthday = new Date('March 13, 08 04:20');
console.log('Birthday minutes:', birthday.getMinutes()); // 20
const date1 = new Date(2016, 6, 6, 14, 6);
const date2 = new Date(2016, 6, 6, 14, 6, 0, -1);
const date3 = new Date(2016, 6, 6, 14, 6, 59, 999);
const date4 = new Date(2016, 6, 6, 14, 6, 59, 1000);
console.log('First millisecond minutes:', date1.getMinutes()); // 6
console.log('Previous millisecond minutes:', date2.getMinutes()); // 5
console.log('Final millisecond minutes:', date3.getMinutes()); // 6
console.log('Subsequent millisecond minutes:', date4.getMinutes()); // 7
// #END
expect(birthday.getMinutes()).toEqual(20);
// first millisecond
expect(new Date(2016, 6, 6, 14, 6).getMinutes()).toEqual(6);
// previous millisecond
expect(new Date(2016, 6, 6, 14, 6, 0, -1).getMinutes()).toEqual(5);
// final millisecond
expect(new Date(2016, 6, 6, 14, 6, 59, 999).getMinutes()).toEqual(6);
// subsequent millisecond
expect(new Date(2016, 6, 6, 14, 6, 59, 1000).getMinutes()).toEqual(7);
})
expect(date1.getMinutes()).toEqual(6);
expect(date2.getMinutes()).toEqual(5);
expect(date3.getMinutes()).toEqual(6);
expect(date4.getMinutes()).toEqual(7);
});
test('getMonth', () => {
// #TEST Date.getMonth
const moonLanding = new Date('July 20, 69 00:20:18');
const firstMillisecondMonth = new Date(2016, 6);
const previousMillisecondMonth = new Date(2016, 6, 0, 0, 0, 0, -1);
const finalMillisecondMonth = new Date(2016, 6, 31, 23, 59, 59, 999);
const subsequentMillisecondMonth = new Date(2016, 6, 31, 23, 59, 59, 1000);
console.log('Moon landing month:', moonLanding.getMonth()); // 6
console.log('First millisecond month:', firstMillisecondMonth.getMonth()); // 6
console.log('Previous millisecond month:', previousMillisecondMonth.getMonth()); // 5
console.log('Final millisecond month:', finalMillisecondMonth.getMonth()); // 6
console.log('Subsequent millisecond month:', subsequentMillisecondMonth.getMonth()); // 7
// #END
expect(moonLanding.getMonth()).toEqual(6);
// first millisecond
expect(new Date(2016, 6).getMonth()).toEqual(6);
// previous millisecond
expect(new Date(2016, 6, 0, 0, 0, 0, -1).getMonth()).toEqual(5);
// final millisecond
expect(new Date(2016, 6, 31, 23, 59, 59, 999).getMonth()).toEqual(6);
// subsequent millisecond
expect(new Date(2016, 6, 31, 23, 59, 59, 1000).getMonth()).toEqual(7);
})
expect(firstMillisecondMonth.getMonth()).toEqual(6);
expect(previousMillisecondMonth.getMonth()).toEqual(5);
expect(finalMillisecondMonth.getMonth()).toEqual(6);
expect(subsequentMillisecondMonth.getMonth()).toEqual(7);
});
test('getSeconds', () => {
// #TEST Date.getSeconds
const moonLanding = new Date('July 20, 69 00:20:18');
console.log('Moon landing seconds:', moonLanding.getSeconds()); // 18
const date1 = new Date(2016, 6, 6, 14, 16, 30);
const date2 = new Date(2016, 6, 6, 14, 16, 30, -1);
const date3 = new Date(2016, 6, 6, 14, 16, 30, 999);
const date4 = new Date(2016, 6, 6, 14, 16, 30, 1000);
console.log('First millisecond seconds:', date1.getSeconds()); // 30
console.log('Previous millisecond seconds:', date2.getSeconds()); // 29
console.log('Final millisecond seconds:', date3.getSeconds()); // 30
console.log('Subsequent millisecond seconds:', date4.getSeconds()); // 31
// #END
expect(moonLanding.getSeconds()).toEqual(18);
// first millisecond
expect(new Date(2016, 6, 6, 14, 16, 30).getSeconds()).toEqual(30);
// previous millisecond
expect(new Date(2016, 6, 6, 14, 16, 30, -1).getSeconds()).toEqual(29);
// final millisecond
expect(new Date(2016, 6, 6, 14, 16, 30, 999).getSeconds()).toEqual(30);
// subsequent millisecond
expect(new Date(2016, 6, 6, 14, 16, 30, 1000).getSeconds()).toEqual(31);
})
expect(date1.getSeconds()).toEqual(30);
expect(date2.getSeconds()).toEqual(29);
expect(date3.getSeconds()).toEqual(30);
expect(date4.getSeconds()).toEqual(31);
});
test('getTime', () => {
// #TEST Date.getTime
const moonLanding = new Date('July 20, 69 20:17:40 GMT+00:00');
console.log(moonLanding.getTime()); // -14182940000
const dateEpoch = new Date(0);
console.log(dateEpoch.getTime()); // 0
const dateOneMillisecond = new Date(1);
console.log(dateOneMillisecond.getTime()); // 1
// #END
expect(moonLanding.getTime()).toEqual(-14182940000);
expect(new Date(0).getTime()).toEqual(0);
expect(new Date(1).getTime()).toEqual(1);
})
});
test('setDate', () => {
// #TEST Date.setDate
const event = new Date('August 19, 1975 23:15:30');
console.log('Original date:', event.getDate()); // 19
event.setDate(24);
expect(event.getDate()).toEqual(24);
console.log('Updated date (24):', event.getDate()); // 24
event.setDate(32);
console.log('Updated date (32):', event.getDate()); // 1
// #END
expect(event.getDate()).toEqual(1);
});
// var date = new Date(2016, 6);
// let returnValue = date.setDate(6);
// let expected = new Date(2016, 6, 6).getTime();
// expect(returnValue).toEqual(expected);
})
test('setFullYear', () => {
// #TEST Date.setFullYear
const event = new Date('August 19, 1975 23:15:30');
event.setFullYear(1969);
console.log('Updated year:', event.getFullYear()); // 1969
// #END
expect(event.getFullYear()).toEqual(1969);
})
});
test('setHours', () => {
// #TEST Date.setHours
const event = new Date('August 19, 1975 23:15:30');
console.log('Original hours:', event.getHours()); // 23
event.setHours(20);
console.log('Updated hours:', event.getHours()); // 20
// #END
expect(event.getHours()).toEqual(20);
})
});
test('setMilliseconds', () => {
// #TEST Date.setMilliseconds
const event = new Date('August 19, 1975 23:15:30');
expect(event.getMilliseconds()).toEqual(0);
console.log('Original milliseconds:', event.getMilliseconds()); // 0
event.setMilliseconds(456);
console.log('Updated milliseconds:', event.getMilliseconds()); // 456
// #END
expect(event.getMilliseconds()).toEqual(456);
})
});
test('setMinutes', () => {
// #TEST Date.setMinutes
const event = new Date('August 19, 1975 23:15:30');
console.log('Original minutes:', event.getMinutes()); // 15
event.setMinutes(45);
console.log('Updated minutes:', event.getMinutes()); // 45
// #END
expect(event.getMinutes()).toEqual(45);
})
});
test('setMonth', () => {
// #TEST Date.setMonth
const event = new Date('August 19, 1975 23:15:30');
console.log('Original month:', event.getMonth()); // 7 (August)
event.setMonth(3);
console.log('Updated month:', event.getMonth()); // 3 (April)
// #END
expect(event.getMonth()).toEqual(3);
})
});
test('setSeconds', () => {
// #TEST Date.setSeconds
const event = new Date('August 19, 1975 23:15:30');
console.log('Original seconds:', event.getSeconds()); // 30
event.setSeconds(42);
console.log('Updated seconds:', event.getSeconds()); // 42
// #END
expect(event.getSeconds()).toEqual(42);
})
});
test('setTime', () => {
// #TEST Date.setTime
const launchDate = new Date('July 1, 1999, 12:00:00');
const futureDate = new Date();
futureDate.setTime(launchDate.getTime());
console.log('Future date time:', futureDate.getTime()); // Should match launchDate.getTime()
// #END
expect(futureDate.getTime()).toEqual(launchDate.getTime());
})
});
})
}
\ No newline at end of file
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录