Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
return ret;
}
}
}
// get minute
let minStr = match.groups('min').value.toLowerCase();
if (StringUtility.isNullOrWhitespace(minStr)) {
minStr = match.groups('minnum').value;
if (!StringUtility.isNullOrWhitespace(minStr)) {
min = this.config.numbers.get(minStr);
hasMin = true;
}
let tensStr = match.groups('tens').value;
if (!StringUtility.isNullOrWhitespace(tensStr)) {
min += this.config.numbers.get(tensStr);
hasMin = true;
}
}
else {
min = Number.parseInt(minStr, 10);
hasMin = true;
}
// get second
let secStr = match.groups('sec').value.toLowerCase();
if (!StringUtility.isNullOrWhitespace(secStr)) {
second = Number.parseInt(secStr, 10);
hasSec = true;
}
}
}
else {
hour = Number.parseInt(hourStr, 10);
if (!hour) {
hour = this.config.numbers.get(hourStr);
if (!hour) {
return ret;
}
}
}
// get minute
let minStr = match.groups('min').value.toLowerCase();
if (StringUtility.isNullOrWhitespace(minStr)) {
minStr = match.groups('minnum').value;
if (!StringUtility.isNullOrWhitespace(minStr)) {
min = this.config.numbers.get(minStr);
hasMin = true;
}
let tensStr = match.groups('tens').value;
if (!StringUtility.isNullOrWhitespace(tensStr)) {
min += this.config.numbers.get(tensStr);
hasMin = true;
}
}
else {
min = Number.parseInt(minStr, 10);
hasMin = true;
}
// get second
}
else if (!StringUtility.isNullOrWhitespace(match.groups('midafternoon').value)) {
hour = 14;
min = 0;
second = 0;
}
else if (!StringUtility.isNullOrWhitespace(match.groups('midday').value)) {
hour = 12;
min = 0;
second = 0;
}
}
else {
// get hour
let hourStr = match.groups('hour').value;
if (StringUtility.isNullOrWhitespace(hourStr)) {
hourStr = match.groups('hournum').value.toLowerCase();
hour = this.config.numbers.get(hourStr);
if (!hour) {
return ret;
}
}
else {
hour = Number.parseInt(hourStr, 10);
if (!hour) {
hour = this.config.numbers.get(hourStr);
if (!hour) {
return ret;
}
}
}
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;
}
// adjust hour by suffix
let timeSuffix = match.groups('suffix').value.toLowerCase();
if (!StringUtility.isNullOrWhitespace(timeSuffix)) {
let adjust = { hour: hour, min: min, hasMin: hasMin, hasAm: hasAm, hasPm: hasPm };
this.config.adjustBySuffix(timeSuffix, adjust);
hour = adjust.hour; min = adjust.min; hasMin = adjust.hasMin; hasAm = adjust.hasAm; hasPm = adjust.hasPm;
}
if (hour === 24) {
hour = 0;
}
}
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;
}
// adjust hour by suffix
let timeSuffix = match.groups('suffix').value.toLowerCase();
if (!StringUtility.isNullOrWhitespace(timeSuffix)) {
let adjust = { hour: hour, min: min, hasMin: hasMin, hasAm: hasAm, hasPm: hasPm };
this.config.adjustBySuffix(timeSuffix, adjust);
hour = adjust.hour; min = adjust.min; hasMin = adjust.hasMin; hasAm = adjust.hasAm; hasPm = adjust.hasPm;
}
if (hour === 24) {
hour = 0;
}
ret.timex = "T" + DateTimeFormatUtil.toString(hour, 2);
if (hasMin) {
ret.timex += ":" + DateTimeFormatUtil.toString(min, 2);
}
if (hasSec) {
ret.timex += ":" + DateTimeFormatUtil.toString(second, 2);
}
let tensStr = match.groups('tens').value;
if (!StringUtility.isNullOrWhitespace(tensStr)) {
min += this.config.numbers.get(tensStr);
hasMin = true;
}
}
else {
min = Number.parseInt(minStr, 10);
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) {
return ret;
}
}
else {
hour = Number.parseInt(hourStr, 10);
if (!hour) {
hour = this.config.numbers.get(hourStr);
if (!hour) {
return ret;
}
}
}
// get minute
let minStr = match.groups('min').value.toLowerCase();
if (StringUtility.isNullOrWhitespace(minStr)) {
minStr = match.groups('minnum').value;
if (!StringUtility.isNullOrWhitespace(minStr)) {
min = this.config.numbers.get(minStr);
hasMin = true;
}
let tensStr = match.groups('tens').value;
if (!StringUtility.isNullOrWhitespace(tensStr)) {
min += this.config.numbers.get(tensStr);
hasMin = true;
}
}
else {
min = Number.parseInt(minStr, 10);
hasMin = true;
}
// get minute
let minStr = match.groups('minnum').value;
let tensStr = match.groups('tens').value;
if (!StringUtility.isNullOrWhitespace(minStr)) {
min = this.config.numbers.get(minStr);
if (tensStr) {
min += this.config.numbers.get(tensStr);
}
hasMin = true;
}
}
else if (!StringUtility.isNullOrWhitespace(match.groups('mid').value)) {
hasMid = true;
if (!StringUtility.isNullOrWhitespace(match.groups('midnight').value)) {
hour = 0;
min = 0;
second = 0;
}
else if (!StringUtility.isNullOrWhitespace(match.groups('midmorning').value)) {
hour = 10;
min = 0;
second = 0;
}
else if (!StringUtility.isNullOrWhitespace(match.groups('midafternoon').value)) {
hour = 14;
min = 0;
second = 0;
}
else if (!StringUtility.isNullOrWhitespace(match.groups('midday').value)) {
hour = 12;