forked from zuriby/Faker.js
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #807 from siwalikm/master
Adding support for fake Time Method()
- Loading branch information
Showing
3 changed files
with
66 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
/** | ||
* | ||
* @namespace faker.time | ||
*/ | ||
var _Time = function(faker) { | ||
var self = this; | ||
|
||
/** | ||
* recent | ||
* | ||
* @method faker.time.recent | ||
* @param {string} outputType - 'abbr' || 'wide' || 'unix' (default choice) | ||
*/ | ||
self.recent = function(outputType) { | ||
if (typeof outputType === "undefined") { | ||
outputType = 'unix'; | ||
} | ||
|
||
var date = new Date(); | ||
switch (outputType) { | ||
case "abbr": | ||
date = date.toLocaleTimeString(); | ||
break; | ||
case "wide": | ||
date = date.toTimeString(); | ||
break; | ||
case "unix": | ||
date = date.getTime(); | ||
break; | ||
} | ||
return date; | ||
}; | ||
|
||
return self; | ||
}; | ||
|
||
module["exports"] = _Time; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
if (typeof module !== 'undefined') { | ||
var assert = require('assert'); | ||
var sinon = require('sinon'); | ||
var faker = require('../index'); | ||
} | ||
|
||
describe("time.js", function () { | ||
describe("recent()", function () { | ||
it("returns the recent timestamp in Unix time format", function () { | ||
var date = faker.time.recent(); | ||
assert.ok(typeof date === 'number'); | ||
assert.ok(date == new Date().getTime()); | ||
}); | ||
|
||
it("returns the recent timestamp in full time string format", function () { | ||
var date = faker.time.recent('wide'); | ||
assert.ok(date == new Date().toTimeString()); | ||
}); | ||
|
||
it("returns the recent timestamp in abbreviated string format", function () { | ||
var date = faker.time.recent('abbr'); | ||
assert.ok(date == new Date().toLocaleTimeString()); | ||
}); | ||
}); | ||
|
||
}); |