-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(datestr): Support basic datestr
- Loading branch information
Showing
8 changed files
with
75 additions
and
3 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,17 @@ | ||
var hash = require('./hash') | ||
var fit = require('./internal/fit') | ||
|
||
var MIN_YEAR = 1980 | ||
var MAX_YEAR = 2019 | ||
|
||
module.exports = function datestr(inputs) { | ||
var id = hash(inputs) | ||
// for simplicity, use 28d as max regardless of month/year | ||
var year = fit(id, MIN_YEAR, MAX_YEAR) | ||
var monthIndex = fit(id, 0, 11) | ||
var day = fit(id, 1, 28) | ||
var hour = fit(id, 0, 23) | ||
var min = fit(id, 0, 59) | ||
var millisec = fit(id, 0, 1000) | ||
return new Date(year, monthIndex, day, hour, min, millisec).toISOString() | ||
} |
File renamed without changes.
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 |
---|---|---|
@@ -1,3 +1,4 @@ | ||
exports.int = require('./int') | ||
exports.word = require('./word') | ||
exports.bool = require('./bool') | ||
exports.datestr = require('./datestr') |
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 |
---|---|---|
@@ -1,3 +1,3 @@ | ||
var hash = require('./internal/hash') | ||
var hash = require('./hash') | ||
|
||
module.exports = hash |
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,4 @@ | ||
module.exports = function fit(v, lo, hi) { | ||
lo = lo || 0 | ||
return hi == null ? v + lo : (v % (hi - lo)) + lo | ||
} |
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