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

chrono-node

Package Overview
Dependencies
Maintainers
1
Versions
107
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

chrono-node - npm Package Compare versions

Comparing version 2.1.11 to 2.2.0

1

dist/common/parsers/AbstractTimeExpressionParser.d.ts

@@ -12,2 +12,3 @@ import { Parser, ParsingContext } from "../../chrono";

extractFollowingTimeComponents(context: ParsingContext, match: RegExpMatchArray, result: ParsingResult): null | ParsingComponents;
private static checkAndReturnStartTime;
}

17

dist/common/parsers/AbstractTimeExpressionParser.js

@@ -63,8 +63,6 @@ "use strict";

match = followingPattern.exec(remainingText);
if (!match) {
return result;
if (!match ||
match[0].match(/^\s*([+-])\s*\d{3,4}$/)) {
return AbstractTimeExpressionParser.checkAndReturnStartTime(result);
}
if (match[0].match(/^\s*([+-])\s*\d{3,4}$/)) {
return result;
}
result.end = this.extractFollowingTimeComponents(context, match, result);

@@ -85,2 +83,5 @@ if (result.end) {

if (match[MINUTE_GROUP] != null) {
if (match[MINUTE_GROUP].length == 1 && !match[AM_PM_HOUR_GROUP]) {
return null;
}
minute = parseInt(match[MINUTE_GROUP]);

@@ -234,3 +235,9 @@ }

}
static checkAndReturnStartTime(result) {
if (result.text.match(/^\d$/)) {
return null;
}
return result;
}
}
exports.AbstractTimeExpressionParser = AbstractTimeExpressionParser;

@@ -5,13 +5,5 @@ "use strict";

function assignTheNextDay(component, targetDayJs) {
if (targetDayJs.hour() > 1) {
targetDayJs = targetDayJs.add(1, "day");
assignSimilarDate(component, targetDayJs);
implySimilarTime(component, targetDayJs);
}
else {
assignSimilarDate(component, targetDayJs);
component.imply("hour", 12);
component.imply("minute", 0);
component.imply("second", 0);
}
targetDayJs = targetDayJs.add(1, "day");
assignSimilarDate(component, targetDayJs);
implySimilarTime(component, targetDayJs);
}

@@ -18,0 +10,0 @@ exports.assignTheNextDay = assignTheNextDay;

@@ -18,3 +18,3 @@ {

"license": "MIT",
"version": "2.1.11",
"version": "2.2.0",
"directories": {

@@ -21,0 +21,0 @@ "source": "./src",

@@ -78,11 +78,10 @@ import { Parser, ParsingContext } from "../../chrono";

match = followingPattern.exec(remainingText);
if (!match) {
return result;
if (
!match ||
// Pattern "YY.YY -XXXX" is more like timezone offset
match[0].match(/^\s*([+-])\s*\d{3,4}$/)
) {
return AbstractTimeExpressionParser.checkAndReturnStartTime(result);
}
// Pattern "YY.YY -XXXX" is more like timezone offset
if (match[0].match(/^\s*([+-])\s*\d{3,4}$/)) {
return result;
}
result.end = this.extractFollowingTimeComponents(context, match, result);

@@ -109,2 +108,7 @@ if (result.end) {

if (match[MINUTE_GROUP] != null) {
if (match[MINUTE_GROUP].length == 1 && !match[AM_PM_HOUR_GROUP]) {
// Skip single digit minute e.g. "at 1.1 xx"
return null;
}
minute = parseInt(match[MINUTE_GROUP]);

@@ -285,2 +289,11 @@ } else if (hour > 100) {

}
private static checkAndReturnStartTime(result) {
// Single digit (e.g "1") should not be counted as time expression
if (result.text.match(/^\d$/)) {
return null;
}
return result;
}
}
import { ParsingComponents } from "../results";
import dayjs from "dayjs";
/**
* Assign the next day or 'tomorrow'.
* This includes checking for edge cases e.g. mentioned 'tomorrow' after midnight
*/
export function assignTheNextDay(component: ParsingComponents, targetDayJs: dayjs.Dayjs) {
if (targetDayJs.hour() > 1) {
targetDayJs = targetDayJs.add(1, "day");
assignSimilarDate(component, targetDayJs);
implySimilarTime(component, targetDayJs);
} else {
assignSimilarDate(component, targetDayJs);
component.imply("hour", 12);
component.imply("minute", 0);
component.imply("second", 0);
}
targetDayJs = targetDayJs.add(1, "day");
assignSimilarDate(component, targetDayJs);
implySimilarTime(component, targetDayJs);
}

@@ -20,0 +9,0 @@

@@ -43,8 +43,7 @@ import * as chrono from "../../src/";

// Say.."Tomorrow" in the late night (1 AM)
testSingleCase(chrono.de, "Die Deadline ist morgen", new Date(2012, 7, 10, 1), (result) => {
testSingleCase(chrono.de, "Die Deadline ist morgen", new Date(2012, 8 - 1, 10, 1), (result) => {
expect(result.start.get("year")).toBe(2012);
expect(result.start.get("month")).toBe(8);
expect(result.start.get("day")).toBe(10);
//expect(result.start.get("hour")).toBe(8);
expect(result.start.get("day")).toBe(11);
expect(result.start.get("hour")).toBe(1);
});

@@ -51,0 +50,0 @@

@@ -48,5 +48,4 @@ import * as chrono from "../../src/";

// Say.."Tomorrow" in the late night (1 AM)
testSingleCase(chrono.casual, "The Deadline is Tomorrow", new Date(2012, 7, 10, 1), (result) => {
expect(result.start).toBeDate(new Date(2012, 7, 10, 12));
expect(result.start).toBeDate(new Date(2012, 7, 11, 1));
});

@@ -126,2 +125,4 @@

// "Midnight" at 0~1AM, assume it's the coming midnight of following day
// This is similar to "Tomorrow" at 0~1AM
testSingleCase(chrono.casual, "The Deadline was midnight ", new Date(2012, 7, 10, 1), (result) => {

@@ -131,3 +132,3 @@ expect(result.text).toBe("midnight");

expect(result.start.get("month")).toBe(8);
expect(result.start.get("day")).toBe(10);
expect(result.start.get("day")).toBe(11);
expect(result.start.get("hour")).toBe(0);

@@ -134,0 +135,0 @@ });

@@ -106,2 +106,4 @@ import * as chrono from "../../src";

testUnexpectedResult(chrono, "Version: 1.10.30");
testUnexpectedResult(chrono, "at 6.5 kilograms");
});

@@ -108,0 +110,0 @@

@@ -45,5 +45,4 @@ import * as chrono from "../../src";

// Say.."Demain" in the late night (1 AM)
testSingleCase(chrono.fr, "La deadline est demain", new Date(2012, 7, 10, 1), (result) => {
expect(result.start).toBeDate(new Date(2012, 7, 10, 12));
expect(result.start).toBeDate(new Date(2012, 7, 11, 1));
});

@@ -50,0 +49,0 @@

@@ -46,3 +46,3 @@ import * as chrono from "../../src/";

testSingleCase(chrono.pt, "O prazo é Amanhã", new Date(2012, 7, 10, 1), (result) => {
expect(result.start).toBeDate(new Date(2012, 7, 10, 12));
expect(result.start).toBeDate(new Date(2012, 7, 11, 1));
});

@@ -49,0 +49,0 @@

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