3.1 KiB
3.1 KiB
id | title | localeTitle | challengeType | isRequired |
---|---|---|---|---|
bd7158d8c443edefaeb5bdef | Timestamp Microservice | 时间戳微服务 | 4 | true |
Description
Instructions
Tests
tests:
- text: '它应该处理一个有效的日期,并返回正确的unix时间戳'
testString: 'getUserInput => $.get(getUserInput(''url'') + ''/api/timestamp/2016-12-25'').then(data => { assert.equal(data.unix, 1482624000000, ''Should be a valid unix timestamp''); }, xhr => { throw new Error(xhr.responseText); })'
- text: '它应该处理一个有效的日期,并返回正确的UTC字符串'
testString: 'getUserInput => $.get(getUserInput(''url'')+ ''/api/timestamp/2016-12-25'').then(data => { assert.equal(data.utc, ''Sun, 25 Dec 2016 00:00:00 GMT'', ''Should be a valid UTC date string''); }, xhr => { throw new Error(xhr.responseText); })'
- text: '它应该处理一个有效的unix日期,并返回正确的unix时间戳'
testString: 'getUserInput => $.get(getUserInput(''url'') + ''/api/timestamp/1482624000000'').then(data => { assert.equal(data.unix, 1482624000000) ; }, xhr => { throw new Error(xhr.responseText); })'
- text: 它应返回无效日期的预期错误消息
testString: 'getUserInput => $.get(getUserInput(''url'') + ''/api/timestamp/this-is-not-a-date'').then(data => { assert.equal(data.error.toLowerCase(), ''invalid date'');}, xhr => { throw new Error(xhr.responseText); })'
- text: '它应该处理一个空的日期参数,并以unix格式返回当前时间'
testString: 'getUserInput => $.get(getUserInput(''url'') + ''/api/timestamp'').then(data => { var now = Date.now(); assert.approximately(data.unix, now, 20000) ;}, xhr => { throw new Error(xhr.responseText); })'
- text: '它应该处理一个空日期参数,并以UTC格式返回当前时间'
testString: 'getUserInput => $.get(getUserInput(''url'') + ''/api/timestamp'').then(data => { var now = Date.now(); var serverTime = (new Date(data.utc)).getTime(); assert.approximately(serverTime, now, 20000) ;}, xhr => { throw new Error(xhr.responseText); })'
Challenge Seed
Solution
// solution required