Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

tickbin-entry-parser

Package Overview
Dependencies
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

tickbin-entry-parser - npm Package Compare versions

Comparing version 0.0.3 to 0.0.4

build/test/timezone/index.test.tz.js

21

build/index.js

@@ -35,3 +35,3 @@ 'use strict';

var hashPattern = exports.hashPattern = /(#\w+[\w-]*)/g;
var version = exports.version = 4;
var version = exports.version = 5;

@@ -41,8 +41,14 @@ var Entry = function () {

var opts = arguments.length <= 2 || arguments[2] === undefined ? {} : arguments[2];
var timezoneOffset = arguments[3];
_classCallCheck(this, Entry);
var _opts$date = opts.date;
var date = _opts$date === undefined ? new Date() : _opts$date;
var date = opts.date;
if (timezoneOffset && !date) {
// ensure reference date is in users time and zone
date = (0, _moment2.default)().utcOffset(timezoneOffset);
} else if (!date) {
date = new Date();
}

@@ -55,4 +61,5 @@ if ((typeof message === 'undefined' ? 'undefined' : _typeof(message)) === 'object') return this._fromJSON(message);

this.message = message;
this.ref = date;
this.parse(message, date);
// ensure ref is a date and not a moment
this.ref = new Date(date);
this.parse(message, date, timezoneOffset);
this.parseTags(message);

@@ -74,4 +81,4 @@ }

key: 'parse',
value: function parse(msg, date) {
var d = (0, _parser2.default)(msg, date);
value: function parse(msg, date, timezoneOffset) {
var d = (0, _parser2.default)(msg, date, timezoneOffset);
if (d.isValid) this.setDates(d);

@@ -78,0 +85,0 @@ }

@@ -7,5 +7,12 @@ 'use strict';

exports.default = function (str, ref) {
exports.default = function (str, ref, timezoneOffset) {
var rslt = parser.parse(str, ref)[0];
var isValid = rslt && rslt.start && rslt.end;
// sets timezone to where user is located
if (timezoneOffset && isValid) {
rslt.start.assign('timezoneOffset', timezoneOffset);
rslt.end.assign('timezoneOffset', timezoneOffset);
}
var start = isValid ? rslt.start.date() : null;

@@ -12,0 +19,0 @@ var end = isValid ? rslt.end.date() : null;

@@ -110,2 +110,20 @@ 'use strict';

(0, _tape2.default)('set timezone offset', function (t) {
var date = new Date();
var msg = '8am-3pm worked on some things';
var timezoneOffset = -480;
var e = new _2.default(userId, msg, {}, timezoneOffset);
var _e$getDates6 = e.getDates();
var start = _e$getDates6.start;
var end = _e$getDates6.end;
t.equal((0, _moment2.default)(start).utc().hour(), 16, 'start is 8am in UTC-08:00');
t.equal((0, _moment2.default)(end).utc().hour(), 23, 'end is 3pm in UTC-08:00');
t.end();
});
(0, _tape2.default)('created date added to entry', function (t) {

@@ -112,0 +130,0 @@ var today = new Date();

@@ -11,5 +11,5 @@ 'use strict';

var _parser21 = require('../parser');
var _parser22 = require('../parser');
var _parser22 = _interopRequireDefault(_parser21);
var _parser23 = _interopRequireDefault(_parser22);

@@ -19,3 +19,3 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

(0, _tape2.default)('simple am times: 8am-10am', function (t) {
var _parser = (0, _parser22.default)('8am-10am');
var _parser = (0, _parser23.default)('8am-10am');

@@ -32,3 +32,3 @@ var start = _parser.start;

(0, _tape2.default)('simple am to pm times: 9am-2pm', function (t) {
var _parser2 = (0, _parser22.default)('9am-2pm');
var _parser2 = (0, _parser23.default)('9am-2pm');

@@ -45,3 +45,3 @@ var start = _parser2.start;

(0, _tape2.default)('simple pm times: 1pm-4pm', function (t) {
var _parser3 = (0, _parser22.default)('1pm-4pm');
var _parser3 = (0, _parser23.default)('1pm-4pm');

@@ -58,3 +58,3 @@ var start = _parser3.start;

(0, _tape2.default)('infer meridiem: 1-3pm', function (t) {
var _parser4 = (0, _parser22.default)('1-3pm');
var _parser4 = (0, _parser23.default)('1-3pm');

@@ -73,3 +73,3 @@ var start = _parser4.start;

var _parser5 = (0, _parser22.default)('1pm-3');
var _parser5 = (0, _parser23.default)('1pm-3');

@@ -90,3 +90,3 @@ var start = _parser5.start;

var _parser6 = (0, _parser22.default)('11pm-2');
var _parser6 = (0, _parser23.default)('11pm-2');

@@ -106,3 +106,3 @@ var start = _parser6.start;

(0, _tape2.default)('minutes: 9:15am-2:30pm', function (t) {
var _parser7 = (0, _parser22.default)('9:15am-2:30pm');
var _parser7 = (0, _parser23.default)('9:15am-2:30pm');

@@ -121,3 +121,3 @@ var start = _parser7.start;

(0, _tape2.default)('colon segmented 24 times: 08:00-13:00', function (t) {
var _parser8 = (0, _parser22.default)('0800-1330');
var _parser8 = (0, _parser23.default)('0800-1330');

@@ -135,3 +135,3 @@ var start = _parser8.start;

(0, _tape2.default)('proper 24h times: 0800-1330', function (t) {
var _parser9 = (0, _parser22.default)('0800-1330');
var _parser9 = (0, _parser23.default)('0800-1330');

@@ -150,3 +150,3 @@ var start = _parser9.start;

(0, _tape2.default)('no leading zero 24h times: 800-1300', function (t) {
var _parser10 = (0, _parser22.default)('800-1300');
var _parser10 = (0, _parser23.default)('800-1300');

@@ -166,3 +166,3 @@ var start = _parser10.start;

(0, _tape2.default)('anchored: dates relative to anchor', function (t) {
var _parser11 = (0, _parser22.default)('8am-1pm', anchor);
var _parser11 = (0, _parser23.default)('8am-1pm', anchor);

@@ -180,3 +180,3 @@ var start = _parser11.start;

(0, _tape2.default)('anchored: dates relative to anchor2', function (t) {
var _parser12 = (0, _parser22.default)('8am-1pm', anchor2);
var _parser12 = (0, _parser23.default)('8am-1pm', anchor2);

@@ -194,3 +194,3 @@ var start = _parser12.start;

(0, _tape2.default)('overlapping times: 11pm-2am', function (t) {
var _parser13 = (0, _parser22.default)('11pm-2am', anchor);
var _parser13 = (0, _parser23.default)('11pm-2am', anchor);

@@ -211,3 +211,3 @@ var start = _parser13.start;

var _parser14 = (0, _parser22.default)('11pm-2am');
var _parser14 = (0, _parser23.default)('11pm-2am');

@@ -227,3 +227,3 @@ var start = _parser14.start;

var _parser15 = (0, _parser22.default)('11pm-2am', refDate);
var _parser15 = (0, _parser23.default)('11pm-2am', refDate);

@@ -241,7 +241,7 @@ var start = _parser15.start;

(0, _tape2.default)('matching text is returned', function (t) {
var _parser16 = (0, _parser22.default)('1-3pm');
var _parser16 = (0, _parser23.default)('1-3pm');
var text = _parser16.text;
var _parser17 = (0, _parser22.default)('1-3pm did some things');
var _parser17 = (0, _parser23.default)('1-3pm did some things');

@@ -261,3 +261,3 @@ var only = _parser17.text;

var _parser18 = (0, _parser22.default)('10-4pm');
var _parser18 = (0, _parser23.default)('10-4pm');

@@ -280,3 +280,3 @@ var start = _parser18.start;

var _parser19 = (0, _parser22.default)('9:30-12pm');
var _parser19 = (0, _parser23.default)('9:30-12pm');

@@ -299,3 +299,3 @@ var start = _parser19.start;

var _parser20 = (0, _parser22.default)('8-4pm Good Friday #stat', today);
var _parser20 = (0, _parser23.default)('8-4pm Good Friday #stat', today);

@@ -310,2 +310,15 @@ var start = _parser20.start;

t.end();
});
(0, _tape2.default)('use timezone offset', function (t) {
var _parser21 = (0, _parser23.default)('8am-10am', undefined, -480);
var start = _parser21.start;
var end = _parser21.end;
t.equals((0, _moment2.default)(start).utc().hour(), 16, 'start is 8am in UTC-08:00');
t.equals((0, _moment2.default)(end).utc().hour(), 18, 'end is 10am in UTC-10:00');
t.end();
});
{
"name": "tickbin-entry-parser",
"version": "0.0.3",
"version": "0.0.4",
"description": "parse strings into entries",
"main": "build/index.js",
"scripts": {
"clean": "rm -rf build/*",
"build": "babel src -d build",
"watch": "npm run build -- -w",
"test": "tape 'build/test/**/*.js' | tap-spec"
"test": "tape 'build/test/**/*.test.js' | tap-spec && npm run tztest",
"tztest": "TZ='Pacific/Tongatapu' tape 'build/test/timezone/**/*.js' | tap-spec",
"prebuild": "npm run clean",
"prepublish": "npm run build && npm test"
},

@@ -11,0 +15,0 @@ "keywords": [],

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc