Skip to content

Commit

Permalink
feat(datestr): Support basic datestr
Browse files Browse the repository at this point in the history
  • Loading branch information
justinvdm committed Apr 24, 2020
1 parent 8562404 commit ea385be
Show file tree
Hide file tree
Showing 8 changed files with 75 additions and 3 deletions.
2 changes: 1 addition & 1 deletion bool.js
@@ -1,4 +1,4 @@
var hash = require('./internal/hash')
var hash = require('./hash')

module.exports = function bool(inputs) {
return !!(hash(inputs) % 2)
Expand Down
17 changes: 17 additions & 0 deletions datestr.js
@@ -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.
1 change: 1 addition & 0 deletions index.js
@@ -1,3 +1,4 @@
exports.int = require('./int')
exports.word = require('./word')
exports.bool = require('./bool')
exports.datestr = require('./datestr')
2 changes: 1 addition & 1 deletion int.js
@@ -1,3 +1,3 @@
var hash = require('./internal/hash')
var hash = require('./hash')

module.exports = hash
4 changes: 4 additions & 0 deletions internal/fit.js
@@ -0,0 +1,4 @@
module.exports = function fit(v, lo, hi) {
lo = lo || 0
return hi == null ? v + lo : (v % (hi - lo)) + lo
}
50 changes: 50 additions & 0 deletions tap-snapshots/tests-fictional.test.js-TAP.test.js
Expand Up @@ -9,251 +9,301 @@ exports[`tests/fictional.test.js TAP generated values > must match snapshot 1`]
Array [
Object {
"bool": true,
"datestr": "2009-07-06T18:35:17.000Z",
"int": 177557,
"word": "qakojiz",
},
Object {
"bool": false,
"datestr": "2008-06-05T17:34:16.000Z",
"int": 177556,
"word": "mogefa",
},
Object {
"bool": true,
"datestr": "2011-09-08T20:37:19.000Z",
"int": 177559,
"word": "vupinexum",
},
Object {
"bool": false,
"datestr": "2010-08-07T19:36:18.000Z",
"int": 177558,
"word": "rilakude",
},
Object {
"bool": true,
"datestr": "2005-03-02T15:31:13.000Z",
"int": 177553,
"word": "giza",
},
Object {
"bool": false,
"datestr": "2004-02-01T14:30:12.000Z",
"int": 177552,
"word": "cawo",
},
Object {
"bool": true,
"datestr": "2007-05-04T16:33:15.000Z",
"int": 177555,
"word": "lefud",
},
Object {
"bool": false,
"datestr": "2006-04-03T15:32:14.000Z",
"int": 177554,
"word": "hubi",
},
Object {
"bool": true,
"datestr": "2017-04-14T03:43:25.000Z",
"int": 177565,
"word": "xiraq",
},
Object {
"bool": false,
"datestr": "2016-03-13T03:42:24.000Z",
"int": 177564,
"word": "tano",
},
Object {
"bool": false,
"datestr": "1991-07-09T11:47:32.000Z",
"int": 5859332,
"word": "boqe",
},
Object {
"bool": true,
"datestr": "1985-07-14T22:22:05.000Z",
"int": 5859365,
"word": "vimal",
},
Object {
"bool": false,
"datestr": "2018-07-21T08:55:38.000Z",
"int": 5859398,
"word": "mejuhoda",
},
Object {
"bool": true,
"datestr": "2012-07-27T18:30:11.000Z",
"int": 5859431,
"word": "teja",
},
Object {
"bool": false,
"datestr": "2015-07-12T17:31:20.000Z",
"int": 5859200,
"word": "reyo",
},
Object {
"bool": true,
"datestr": "2009-07-18T04:05:53.000Z",
"int": 5859233,
"word": "laxi",
},
Object {
"bool": false,
"datestr": "2003-07-24T14:39:26.000Z",
"int": 5859266,
"word": "cureqa",
},
Object {
"bool": true,
"datestr": "1997-07-03T01:13:59.000Z",
"int": 5859299,
"word": "woqapuliz",
},
Object {
"bool": false,
"datestr": "1982-07-02T23:20:56.000Z",
"int": 5859596,
"word": "vitise",
},
Object {
"bool": true,
"datestr": "2015-07-09T09:54:29.000Z",
"int": 5859629,
"word": "pediceyeq",
},
Object {
"bool": true,
"datestr": "1994-10-12T15:50:35.000Z",
"int": 5859335,
"word": "kuyix",
},
Object {
"bool": false,
"datestr": "1986-08-15T23:23:06.000Z",
"int": 5859366,
"word": "wunime",
},
Object {
"bool": true,
"datestr": "2017-06-20T07:54:37.000Z",
"int": 5859397,
"word": "luhigec",
},
Object {
"bool": false,
"datestr": "2009-04-24T15:27:08.000Z",
"int": 5859428,
"word": "xukojifo",
},
Object {
"bool": true,
"datestr": "2018-10-15T20:34:23.000Z",
"int": 5859203,
"word": "zihu",
},
Object {
"bool": false,
"datestr": "2010-08-19T05:06:54.000Z",
"int": 5859234,
"word": "miyu",
},
Object {
"bool": true,
"datestr": "2002-06-23T13:38:25.000Z",
"int": 5859265,
"word": "biqup",
},
Object {
"bool": false,
"datestr": "1994-04-26T22:10:56.000Z",
"int": 5859296,
"word": "nihugo",
},
Object {
"bool": true,
"datestr": "1985-10-06T03:23:59.000Z",
"int": 5859599,
"word": "docobixop",
},
Object {
"bool": false,
"datestr": "2016-08-10T10:55:30.000Z",
"int": 5859630,
"word": "duva",
},
Object {
"bool": false,
"datestr": "1993-09-11T13:49:34.000Z",
"int": 5859334,
"word": "giva",
},
Object {
"bool": true,
"datestr": "1987-09-17T00:24:07.000Z",
"int": 5859367,
"word": "zeruqom",
},
Object {
"bool": false,
"datestr": "2016-05-19T06:53:36.000Z",
"int": 5859396,
"word": "hidacu",
},
Object {
"bool": true,
"datestr": "2010-05-25T16:28:09.000Z",
"int": 5859429,
"word": "benamujix",
},
Object {
"bool": false,
"datestr": "2017-09-14T19:33:22.000Z",
"int": 5859202,
"word": "wadi",
},
Object {
"bool": true,
"datestr": "2011-09-20T06:07:55.000Z",
"int": 5859235,
"word": "quceb",
},
Object {
"bool": false,
"datestr": "2001-05-22T12:37:24.000Z",
"int": 5859264,
"word": "xami",
},
Object {
"bool": true,
"datestr": "1995-04-30T23:11:57.000Z",
"int": 5859297,
"word": "rulekag",
},
Object {
"bool": false,
"datestr": "1984-09-05T01:22:58.000Z",
"int": 5859598,
"word": "zeyexatu",
},
Object {
"bool": true,
"datestr": "2017-09-11T11:56:31.000Z",
"int": 5859631,
"word": "heyi",
},
Object {
"bool": true,
"datestr": "1988-04-06T08:44:29.000Z",
"int": 5859329,
"word": "hetusopab",
},
Object {
"bool": false,
"datestr": "1980-02-10T17:17:00.000Z",
"int": 5859360,
"word": "hiya",
},
Object {
"bool": true,
"datestr": "2015-04-18T05:52:35.000Z",
"int": 5859395,
"word": "gacob",
},
Object {
"bool": false,
"datestr": "2007-02-22T14:25:06.000Z",
"int": 5859426,
"word": "safudo",
},
Object {
"bool": true,
"datestr": "1981-01-17T00:36:25.000Z",
"int": 5859205,
"word": "femol",
},
Object {
"bool": false,
"datestr": "2012-10-21T07:08:56.000Z",
"int": 5859236,
"word": "redoci",
},
Object {
"bool": true,
"datestr": "2008-01-02T20:44:31.000Z",
"int": 5859271,
"word": "davi",
},
Object {
"bool": false,
"datestr": "2000-10-06T04:17:02.000Z",
"int": 5859302,
"word": "qazo",
},
Object {
"bool": true,
"datestr": "2018-04-27T19:17:53.000Z",
"int": 5859593,
"word": "pene",
},
Object {
"bool": false,
"datestr": "2010-02-04T05:49:24.000Z",
"int": 5859624,
"word": "beqi",
},
Expand Down
2 changes: 1 addition & 1 deletion word.js
@@ -1,5 +1,5 @@
var Seq = require('./internal/Seq')
var hash = require('./internal/hash')
var hash = require('./hash')

var VOWELS = 'aeiou'
var CONSONANT = 'bcdfghjklmnpqrstvwxyz'
Expand Down

0 comments on commit ea385be

Please sign in to comment.