Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
// adjust by desc string
let descStr = match.groups('desc').value.toLowerCase();
if (RegExpUtility.getMatches(this.config.utilityConfiguration.amDescRegex, descStr).length > 0
|| RegExpUtility.getMatches(this.config.utilityConfiguration.amPmDescRegex, descStr).length > 0
|| !StringUtility.isNullOrEmpty(match.groups('iam').value)) {
if (hour >= 12) {
hour -= 12;
}
if (RegExpUtility.getMatches(this.config.utilityConfiguration.amPmDescRegex, descStr).length === 0) {
hasAm = true;
}
}
else if (RegExpUtility.getMatches(this.config.utilityConfiguration.pmDescRegex, descStr).length > 0
|| !StringUtility.isNullOrEmpty(match.groups('ipm').value)) {
if (hour < 12) {
hour += 12;
}
hasPm = true;
}
// adjust min by prefix
let timePrefix = match.groups('prefix').value.toLowerCase();
if (!StringUtility.isNullOrWhitespace(timePrefix)) {
let adjust = { hour: hour, min: min, hasMin: hasMin };
this.config.adjustByPrefix(timePrefix, adjust);
hour = adjust.hour; min = adjust.min; hasMin = adjust.hasMin;
}
private addPeriodToResolution(resolutions: StringMap, startType: string, endType: string, mod: string, result: StringMap) {
let start = resolutions[startType];
let end = resolutions[endType];
if (!StringUtility.isNullOrEmpty(mod)) {
// For the 'before' mod
// 1. Cases like "Before December", the start of the period should be the end of the new period, not the start
// 2. Cases like "More than 3 days before today", the date point should be the end of the new period
if (mod === TimeTypeConstants.beforeMod) {
if (!StringUtility.isNullOrEmpty(start) && !StringUtility.isNullOrEmpty(end)) {
result[TimeTypeConstants.END] = start;
}
else {
result[TimeTypeConstants.END] = end;
}
return;
}
// For the 'after' mod
// 1. Cases like "After January". the end of the period should be the start of the new period, not the end
// 2. Cases like "More than 3 days after today", the date point should be the start of the new period
if (mod === TimeTypeConstants.afterMod) {
if (!StringUtility.isNullOrEmpty(start) && !StringUtility.isNullOrEmpty(end)) {
result[TimeTypeConstants.START] = end;
}
else {
// 2. Cases like "More than 3 days before today", the date point should be the end of the new period
if (mod === TimeTypeConstants.beforeMod) {
if (!StringUtility.isNullOrEmpty(start) && !StringUtility.isNullOrEmpty(end)) {
result[TimeTypeConstants.END] = start;
}
else {
result[TimeTypeConstants.END] = end;
}
return;
}
// For the 'after' mod
// 1. Cases like "After January". the end of the period should be the start of the new period, not the end
// 2. Cases like "More than 3 days after today", the date point should be the start of the new period
if (mod === TimeTypeConstants.afterMod) {
if (!StringUtility.isNullOrEmpty(start) && !StringUtility.isNullOrEmpty(end)) {
result[TimeTypeConstants.START] = end;
}
else {
result[TimeTypeConstants.START] = start;
}
return;
}
if (mod === TimeTypeConstants.sinceMod) {
result[TimeTypeConstants.START] = start;
return;
}
}
if (StringUtility.isNullOrEmpty(start) || StringUtility.isNullOrEmpty(end)) {
return;
}
hasMin = true;
}
// get second
let secStr = match.groups('sec').value.toLowerCase();
if (!StringUtility.isNullOrWhitespace(secStr)) {
second = Number.parseInt(secStr, 10);
hasSec = true;
}
}
// adjust by desc string
let descStr = match.groups('desc').value.toLowerCase();
if (RegExpUtility.getMatches(this.config.utilityConfiguration.amDescRegex, descStr).length > 0
|| RegExpUtility.getMatches(this.config.utilityConfiguration.amPmDescRegex, descStr).length > 0
|| !StringUtility.isNullOrEmpty(match.groups('iam').value)) {
if (hour >= 12) {
hour -= 12;
}
if (RegExpUtility.getMatches(this.config.utilityConfiguration.amPmDescRegex, descStr).length === 0) {
hasAm = true;
}
}
else if (RegExpUtility.getMatches(this.config.utilityConfiguration.pmDescRegex, descStr).length > 0
|| !StringUtility.isNullOrEmpty(match.groups('ipm').value)) {
if (hour < 12) {
hour += 12;
}
protected addResolutionFields(dic: StringMap, key: string, value: string) {
if (!StringUtility.isNullOrEmpty(value)) {
dic[key] = value;
}
}
if (mod === TimeTypeConstants.afterMod) {
if (!StringUtility.isNullOrEmpty(start) && !StringUtility.isNullOrEmpty(end)) {
result[TimeTypeConstants.START] = end;
}
else {
result[TimeTypeConstants.START] = start;
}
return;
}
if (mod === TimeTypeConstants.sinceMod) {
result[TimeTypeConstants.START] = start;
return;
}
}
if (StringUtility.isNullOrEmpty(start) || StringUtility.isNullOrEmpty(end)) {
return;
}
result[TimeTypeConstants.START] = start;
result[TimeTypeConstants.END] = end;
}
protected addResolutionFieldsAny(dic: Map, key: string, value: any) {
if (value instanceof String) {
if (!StringUtility.isNullOrEmpty(value as string)) {
dic.set(key, value);
}
}
else {
dic.set(key, value);
}
}