Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>com.testsigma.addons</groupId>
<artifactId>add_minutes_to_the_specific_date_time_and_store_the_output_in_specific_format</artifactId>
<version>1.0.3</version>
<version>1.0.4</version>
<packaging>jar</packaging>

<properties>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
package com.testsigma.addons.android;

import com.testsigma.sdk.AndroidAction;
import com.testsigma.sdk.ApplicationType;
import com.testsigma.sdk.annotation.Action;
import com.testsigma.sdk.annotation.TestData;
import com.testsigma.sdk.annotation.RunTimeData;
import lombok.Data;
import org.apache.commons.lang3.exception.ExceptionUtils;
import org.openqa.selenium.NoSuchElementException;
import java.time.LocalDateTime;
import java.time.LocalTime;
import java.time.format.DateTimeFormatter;
import java.time.format.DateTimeParseException;

@Data
@Action(actionText = "Add minute minutes to the input-datetime with input-datetime-format, convert to output-datetime-format format, and store it in a runtime variable variable-name",
description = "Adds specified minutes to a given input datetime, converts the resulting datetime to a specified date-time format, and stores it in a runtime variable",
applicationType = ApplicationType.ANDROID,
useCustomScreenshot = false)
public class AddMinutesToDateTime extends AndroidAction {

@TestData(reference = "input-datetime")
private com.testsigma.sdk.TestData dateTime;
@TestData(reference = "input-datetime-format")
private com.testsigma.sdk.TestData inputFormat;
@TestData(reference = "output-datetime-format")
private com.testsigma.sdk.TestData outputFormat;
@TestData(reference = "minute")
private com.testsigma.sdk.TestData minutesToAdd;

@TestData(reference = "variable-name", isRuntimeVariable = true)
private com.testsigma.sdk.TestData variableName;

@RunTimeData
private com.testsigma.sdk.RunTimeData runTimeData;

@Override
public com.testsigma.sdk.Result execute() throws NoSuchElementException {
logger.info("Initiating execution");
com.testsigma.sdk.Result result = com.testsigma.sdk.Result.SUCCESS;
String dateTimeString = dateTime.getValue().toString();
String inputFormatString = inputFormat.getValue().toString();
String outputFormatString = outputFormat.getValue().toString();
String minutesToAddString = minutesToAdd.getValue().toString();
String variableNameString = variableName.getValue().toString();

try {
int minutes = Integer.parseInt(minutesToAddString);

if (minutes < 0) {
result = com.testsigma.sdk.Result.FAILED;
setErrorMessage("The 'minute' value must be a non-negative integer.");
logger.warn("Invalid input: 'minute' value is negative.");
return result;
}

String newDateTime = addMinutesToDateTime(dateTimeString, inputFormatString, outputFormatString, minutes);

logger.info("New date-time value: " + newDateTime);

if (newDateTime != null) {
runTimeData.setValue(newDateTime);
runTimeData.setKey(variableNameString);
logger.info("Final value stored in variable '" + variableNameString + "' with value '" + newDateTime + "'");
setSuccessMessage(String.format("Added %s minutes to %s and stored the output in '%s' format. %s : %s",
minutes, dateTimeString, outputFormatString, variableNameString, newDateTime));
} else {
result = com.testsigma.sdk.Result.FAILED;
setErrorMessage("Failed to add minutes. Please check the input datetime, input datetime format, and output datetime format.");
}

} catch (NumberFormatException e) {
result = com.testsigma.sdk.Result.FAILED;
setErrorMessage("Invalid number format for 'minutes': " + minutesToAddString);
logger.warn("NumberFormatException: " + e);

} catch (Exception e) {
result = com.testsigma.sdk.Result.FAILED;
setErrorMessage("An unexpected error occurred: " + ExceptionUtils.getMessage(e));
logger.warn("Exception during execution: " + ExceptionUtils.getStackTrace(e));
}
return result;
}

public String addMinutesToDateTime(String dateTimeString, String inputFormatString, String outputFormatString, int minutesToAdd) {
try {
DateTimeFormatter inputFormatter = DateTimeFormatter.ofPattern(inputFormatString);

if (inputFormatString.contains("HH") || inputFormatString.contains("mm") || inputFormatString.contains("ss")) {
DateTimeFormatter outputFormatter = DateTimeFormatter.ofPattern(outputFormatString);
LocalTime time = LocalTime.parse(dateTimeString, inputFormatter);
LocalTime newTime = time.plusMinutes(minutesToAdd);
logger.info("Successfully added minutes to the input time");

return newTime.format(outputFormatter);

} else {

DateTimeFormatter outputFormatter = DateTimeFormatter.ofPattern(outputFormatString);
LocalDateTime dateTime = LocalDateTime.parse(dateTimeString, inputFormatter);

LocalDateTime newDateTime = dateTime.plusMinutes(minutesToAdd);
logger.info("Successfully added minutes to the input datetime");

return newDateTime.format(outputFormatter);
}

} catch (DateTimeParseException e) {
String errorMessage = "Invalid date/time format. Please use the format: " + inputFormatString + ". Error: " + e.getMessage();
logger.warn(errorMessage);
setErrorMessage(errorMessage);
return null;
Comment on lines +87 to +113
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor

🧩 Analysis chain

🏁 Script executed:

# First, let's locate and examine the full method implementation
find . -type f -name "AddMinutesToDateTime.java" | head -5

Repository: testsigmahq/testsigma-addons

Length of output: 1887


🏁 Script executed:

# Check for any test files related to this class
find . -type f -name "*AddMinutesToDateTime*" | head -10

Repository: testsigmahq/testsigma-addons

Length of output: 1887


🏁 Script executed:

# Search for the execute method and error handling context
rg -A 20 "public.*execute" add_minutes_to_the_specific_date_time_and_store_the_output_in_specific_format/ || echo "Pattern not found in that path"

Repository: testsigmahq/testsigma-addons

Length of output: 1887


🏁 Script executed:

# List files in the repository to understand structure
git ls-files | grep -i addminutes | head -20

Repository: testsigmahq/testsigma-addons

Length of output: 1887


🏁 Script executed:

# Look for the java file directly
git ls-files | grep "\.java$" | grep -i datetime

Repository: testsigmahq/testsigma-addons

Length of output: 1887


🌐 Web query:

DateTimeFormatter.ofPattern IllegalArgumentException exceptions Java 8

💡 Result:

DateTimeFormatter.ofPattern(String pattern) in Java 8 throws IllegalArgumentException when the provided pattern string is invalid. This occurs during the parsing of the pattern by DateTimeFormatterBuilder.appendPattern(String), which internally processes the pattern letters and symbols. Common causes include: - Unknown or unsupported pattern letters (e.g., invalid characters not defined in the pattern letter table like 'O' in some contexts, though primarily seen in SimpleDateFormat; for DateTimeFormatter, any undefined letter). - Invalid counts of pattern letters for specific fields (e.g., more than allowed letters for certain zone formats, as noted: "Any other count of letters throws IllegalArgumentException"). - Malformed patterns, such as incorrect use of quotes for literals or adjacent fields causing parsing conflicts (e.g., patterns with digit literals after numeric fields like "yyyyMM'00'" may fail due to known bugs in Java 8, leading to parse exceptions but related to pattern validation). Valid pattern letters (A-Z, a-z) are reserved, and the count determines the format (e.g., 1-3 for short text, 4 for full). Use single quotes ' for literals (escape with ''). Examples of invalid patterns triggering IllegalArgumentException: - Undefined letters. - Excessive letters for fields like zone ID (e.g., more than 2 for ID). Note: Some parsing issues (e.g., adjacent digits) result in DateTimeParseException at runtime, not IllegalArgumentException at formatter creation. Known Java 8 bugs (JDK-8031085, JDK-8032491) affect certain patterns but were fixed in Java 9. To avoid: Consult the official pattern documentation and test patterns. Use DateTimeFormatterBuilder for complex cases.

Citations:


Catch IllegalArgumentException from invalid pattern strings alongside DateTimeParseException.

DateTimeFormatter.ofPattern() throws IllegalArgumentException when the pattern string is invalid (undefined letters, excessive letter counts, malformed syntax). This exception occurs before any parsing attempt and is currently uncaught, allowing invalid patterns to propagate unhandled instead of being caught and logged with actionable messaging.

Proposed fix
-    } catch (DateTimeParseException e) {
+    } catch (IllegalArgumentException | DateTimeParseException e) {
       String errorMessage = "Invalid date/time format. Please use the format: " + inputFormatString + ". Error: " + e.getMessage();
       logger.warn(errorMessage);
       setErrorMessage(errorMessage);
       return null;
     }
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In
`@add_minutes_to_the_specific_date_time_and_store_the_output_in_specific_format/src/main/java/com/testsigma/addons/android/AddMinutesToDateTime.java`
around lines 87 - 113, The try block around DateTimeFormatter.ofPattern(...) and
the parsing in AddMinutesToDateTime (the code that uses
inputFormatter/outputFormatter, LocalTime.parse/LocalDateTime.parse, plusMinutes
and format) must also handle IllegalArgumentException thrown for invalid pattern
strings; update the error handling by adding a catch for
IllegalArgumentException (or use a multi-catch: catch (DateTimeParseException |
IllegalArgumentException e)) and in that catch log a clear warning (logger.warn)
with the message, call setErrorMessage(...) with the same actionable text, and
return null—mirroring the existing DateTimeParseException handling so invalid
format patterns are caught and reported.

}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
package com.testsigma.addons.android;

import com.testsigma.sdk.AndroidAction;
import com.testsigma.sdk.ApplicationType;
import com.testsigma.sdk.annotation.Action;
import com.testsigma.sdk.annotation.TestData;
import com.testsigma.sdk.annotation.RunTimeData;
import lombok.Data;
import org.apache.commons.lang3.exception.ExceptionUtils;
import org.openqa.selenium.NoSuchElementException;
import java.time.LocalDateTime;
import java.time.LocalTime;
import java.time.format.DateTimeFormatter;
import java.time.format.DateTimeParseException;

@Data
@Action(actionText = "Subtract minute minutes to the input-datetime with input-datetime-format, convert to output-datetime-format format, and store it in a runtime variable variable-name",
description = "Subtracts specified minutes to a given input datetime, converts the resulting datetime to a specified date-time format, and stores it in a runtime variable",
Comment on lines +17 to +18
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor

Use "from" in the subtraction metadata.

These strings are user-facing, and both actionText and description currently read as "Subtract ... to" instead of "from".

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In
`@add_minutes_to_the_specific_date_time_and_store_the_output_in_specific_format/src/main/java/com/testsigma/addons/android/SubtractMinutesToDateTime.java`
around lines 17 - 18, The user-facing annotation text for
SubtractMinutesToDateTime incorrectly uses "to" instead of "from"; update the
`@Action` annotation on class SubtractMinutesToDateTime by changing the actionText
and description strings to use "from" (e.g., "Subtract minute minutes from the
input-datetime..." and "...Subtracts specified minutes from a given input
datetime...") and scan the class for any other user-facing strings or Javadoc in
SubtractMinutesToDateTime that repeat "to" so they are also changed to "from"
for consistency.

applicationType = ApplicationType.ANDROID,
useCustomScreenshot = false)
public class SubtractMinutesToDateTime extends AndroidAction {

@TestData(reference = "input-datetime")
private com.testsigma.sdk.TestData dateTime;
@TestData(reference = "input-datetime-format")
private com.testsigma.sdk.TestData inputFormat;
@TestData(reference = "output-datetime-format")
private com.testsigma.sdk.TestData outputFormat;
@TestData(reference = "minute")
private com.testsigma.sdk.TestData minutesToAdd;

@TestData(reference = "variable-name", isRuntimeVariable = true)
private com.testsigma.sdk.TestData variableName;

@RunTimeData
private com.testsigma.sdk.RunTimeData runTimeData;

@Override
public com.testsigma.sdk.Result execute() throws NoSuchElementException {
logger.info("Initiating execution");
com.testsigma.sdk.Result result = com.testsigma.sdk.Result.SUCCESS;
String dateTimeString = dateTime.getValue().toString();
String inputFormatString = inputFormat.getValue().toString();
String outputFormatString = outputFormat.getValue().toString();
String minutesToAddString = minutesToAdd.getValue().toString();
String variableNameString = variableName.getValue().toString();

try {
int minutes = Integer.parseInt(minutesToAddString);

if (minutes < 0) {
result = com.testsigma.sdk.Result.FAILED;
setErrorMessage("The 'minute' value must be a non-negative integer.");
logger.warn("Invalid input: 'minute' value is negative.");
return result;
}

String newDateTime = subtractMinutesToDateTime(dateTimeString, inputFormatString, outputFormatString, minutes);

logger.info("New date-time value: " + newDateTime);

if (newDateTime != null) {
runTimeData.setValue(newDateTime);
runTimeData.setKey(variableNameString);
logger.info("Final value stored in variable '" + variableNameString + "' with value '" + newDateTime + "'");
setSuccessMessage(String.format("Subtracted %s minutes from %s and stored the output in '%s' format. %s : %s",
minutes, dateTimeString, outputFormatString, variableNameString, newDateTime));
} else {
result = com.testsigma.sdk.Result.FAILED;
setErrorMessage("Failed to subtract minutes. Please check the input datetime, input datetime format, and output datetime format.");
}

} catch (NumberFormatException e) {
result = com.testsigma.sdk.Result.FAILED;
setErrorMessage("Invalid number format for 'minutes': " + minutesToAddString);
logger.warn("NumberFormatException: " + e);

} catch (Exception e) {
result = com.testsigma.sdk.Result.FAILED;
setErrorMessage("An unexpected error occurred: " + ExceptionUtils.getMessage(e));
logger.warn("Exception during execution: " + ExceptionUtils.getStackTrace(e));
}
return result;
}

public String subtractMinutesToDateTime(String dateTimeString, String inputFormatString, String outputFormatString, int minutesToSubtract) {
try {
DateTimeFormatter inputFormatter = DateTimeFormatter.ofPattern(inputFormatString);

if (inputFormatString.contains("HH") || inputFormatString.contains("mm") || inputFormatString.contains("ss")) {
DateTimeFormatter outputFormatter = DateTimeFormatter.ofPattern(outputFormatString);
LocalTime time = LocalTime.parse(dateTimeString, inputFormatter);
LocalTime newTime = time.minusMinutes(minutesToSubtract);
logger.info("Successfully subtracted minutes from the input time");

return newTime.format(outputFormatter);

} else {

DateTimeFormatter outputFormatter = DateTimeFormatter.ofPattern(outputFormatString);
LocalDateTime dateTime = LocalDateTime.parse(dateTimeString, inputFormatter);

LocalDateTime newDateTime = dateTime.minusMinutes(minutesToSubtract);
logger.info("Successfully subtracted minutes from the input datetime");

return newDateTime.format(outputFormatter);
Comment on lines +90 to +106
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🔴 Critical

🧩 Analysis chain

🏁 Script executed:

# First, let's find and read the full method context
find . -type f -name "SubtractMinutesToDateTime.java" | head -5

Repository: testsigmahq/testsigma-addons

Length of output: 1887


🏁 Script executed:

# Get the file size and read the relevant section with context
wc -l add_minutes_to_the_specific_date_time_and_store_the_output_in_specific_format/src/main/java/com/testsigma/addons/android/SubtractMinutesToDateTime.java

Repository: testsigmahq/testsigma-addons

Length of output: 1887


🏁 Script executed:

# Read the entire file to understand context
cat -n add_minutes_to_the_specific_date_time_and_store_the_output_in_specific_format/src/main/java/com/testsigma/addons/android/SubtractMinutesToDateTime.java

Repository: testsigmahq/testsigma-addons

Length of output: 1887


Use DateTimeFormatter.parseBest() instead of string matching to distinguish date+time from time-only formats.

The contains("HH") check is an unreliable discriminator that causes misrouting. Formats like yyyy-MM-dd HH:mm contain these tokens but represent full datetimes, not times—parsing them as LocalTime will fail. Time-only formats like hh a (12-hour with AM/PM) don't contain HH, so they incorrectly route to the LocalDateTime branch and also fail.

Replace the conditional logic with DateTimeFormatter.parseBest(dateTimeString, LocalDateTime::from, LocalTime::from), which safely attempts to parse as LocalDateTime first and falls back to LocalTime when date fields are absent.

Proposed fix
-            if (inputFormatString.contains("HH") || inputFormatString.contains("mm") || inputFormatString.contains("ss")) {
-                DateTimeFormatter outputFormatter = DateTimeFormatter.ofPattern(outputFormatString);
-                LocalTime time = LocalTime.parse(dateTimeString, inputFormatter);
-                LocalTime newTime = time.minusMinutes(minutesToSubtract);
-                logger.info("Successfully subtracted minutes from the input time");
-
-                return newTime.format(outputFormatter);
-
-            } else {
-
-                DateTimeFormatter outputFormatter = DateTimeFormatter.ofPattern(outputFormatString);
-                LocalDateTime dateTime = LocalDateTime.parse(dateTimeString, inputFormatter);
-
-                LocalDateTime newDateTime = dateTime.minusMinutes(minutesToSubtract);
-                logger.info("Successfully subtracted minutes from the input datetime");
-
-                return newDateTime.format(outputFormatter);
-            }
+            DateTimeFormatter outputFormatter = DateTimeFormatter.ofPattern(outputFormatString);
+            java.time.temporal.TemporalAccessor parsed =
+                    inputFormatter.parseBest(dateTimeString, LocalDateTime::from, LocalTime::from);
+
+            if (parsed instanceof LocalDateTime) {
+                LocalDateTime newDateTime = ((LocalDateTime) parsed).minusMinutes(minutesToSubtract);
+                logger.info("Successfully subtracted minutes from the input datetime");
+                return newDateTime.format(outputFormatter);
+            }
+
+            LocalTime newTime = ((LocalTime) parsed).minusMinutes(minutesToSubtract);
+            logger.info("Successfully subtracted minutes from the input time");
+            return newTime.format(outputFormatter);
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In
`@add_minutes_to_the_specific_date_time_and_store_the_output_in_specific_format/src/main/java/com/testsigma/addons/android/SubtractMinutesToDateTime.java`
around lines 90 - 106, The branch that checks inputFormatString.contains("HH")
is unreliable; replace it by parsing with the DateTimeFormatter.parseBest
approach: use inputFormatter.parseBest(dateTimeString, LocalDateTime::from,
LocalTime::from) to get a TemporalAccessor, test whether the parsed result is a
LocalTime or LocalDateTime, then subtract minutesToSubtract and format with
DateTimeFormatter.ofPattern(outputFormatString) as before; update the logic
inside the SubtractMinutesToDateTime class where inputFormatter,
outputFormatString, minutesToSubtract and logger are used so you call parseBest
on inputFormatter, cast to LocalDateTime or LocalTime accordingly, do
minusMinutes, log the appropriate message, and return the formatted string.

}

} catch (DateTimeParseException e) {
String errorMessage = "Invalid date/time format. Please use the format: " + inputFormatString + ". Error: " + e.getMessage();
logger.warn(errorMessage);
setErrorMessage(errorMessage);
return null;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
package com.testsigma.addons.ios;

import com.testsigma.sdk.IOSAction;
import com.testsigma.sdk.ApplicationType;
import com.testsigma.sdk.annotation.Action;
import com.testsigma.sdk.annotation.TestData;
import com.testsigma.sdk.annotation.RunTimeData;
import lombok.Data;
import org.apache.commons.lang3.exception.ExceptionUtils;
import org.openqa.selenium.NoSuchElementException;
import java.time.LocalDateTime;
import java.time.LocalTime;
import java.time.format.DateTimeFormatter;
import java.time.format.DateTimeParseException;

@Data
@Action(actionText = "Add minute minutes to the input-datetime with input-datetime-format, convert to output-datetime-format format, and store it in a runtime variable variable-name",
description = "Adds specified minutes to a given input datetime, converts the resulting datetime to a specified date-time format, and stores it in a runtime variable",
applicationType = ApplicationType.IOS,
useCustomScreenshot = false)
public class AddMinutesToDateTime extends IOSAction {

@TestData(reference = "input-datetime")
private com.testsigma.sdk.TestData dateTime;
@TestData(reference = "input-datetime-format")
private com.testsigma.sdk.TestData inputFormat;
@TestData(reference = "output-datetime-format")
private com.testsigma.sdk.TestData outputFormat;
@TestData(reference = "minute")
private com.testsigma.sdk.TestData minutesToAdd;

@TestData(reference = "variable-name", isRuntimeVariable = true)
private com.testsigma.sdk.TestData variableName;

@RunTimeData
private com.testsigma.sdk.RunTimeData runTimeData;

@Override
public com.testsigma.sdk.Result execute() throws NoSuchElementException {
logger.info("Initiating execution");
com.testsigma.sdk.Result result = com.testsigma.sdk.Result.SUCCESS;
String dateTimeString = dateTime.getValue().toString();
String inputFormatString = inputFormat.getValue().toString();
String outputFormatString = outputFormat.getValue().toString();
String minutesToAddString = minutesToAdd.getValue().toString();
String variableNameString = variableName.getValue().toString();

try {
int minutes = Integer.parseInt(minutesToAddString);

if (minutes < 0) {
result = com.testsigma.sdk.Result.FAILED;
setErrorMessage("The 'minute' value must be a non-negative integer.");
logger.warn("Invalid input: 'minute' value is negative.");
return result;
}

String newDateTime = addMinutesToDateTime(dateTimeString, inputFormatString, outputFormatString, minutes);

logger.info("New date-time value: " + newDateTime);

if (newDateTime != null) {
runTimeData.setValue(newDateTime);
runTimeData.setKey(variableNameString);
logger.info("Final value stored in variable '" + variableNameString + "' with value '" + newDateTime + "'");
setSuccessMessage(String.format("Added %s minutes to %s and stored the output in '%s' format. %s : %s",
minutes, dateTimeString, outputFormatString, variableNameString, newDateTime));
} else {
result = com.testsigma.sdk.Result.FAILED;
setErrorMessage("Failed to add minutes. Please check the input datetime, input datetime format, and output datetime format.");
}

} catch (NumberFormatException e) {
result = com.testsigma.sdk.Result.FAILED;
setErrorMessage("Invalid number format for 'minutes': " + minutesToAddString);
logger.warn("NumberFormatException: " + e);

} catch (Exception e) {
result = com.testsigma.sdk.Result.FAILED;
setErrorMessage("An unexpected error occurred: " + ExceptionUtils.getMessage(e));
logger.warn("Exception during execution: " + ExceptionUtils.getStackTrace(e));
}
return result;
}

public String addMinutesToDateTime(String dateTimeString, String inputFormatString, String outputFormatString, int minutesToAdd) {
try {
DateTimeFormatter inputFormatter = DateTimeFormatter.ofPattern(inputFormatString);

if (inputFormatString.contains("HH") || inputFormatString.contains("mm") || inputFormatString.contains("ss")) {
DateTimeFormatter outputFormatter = DateTimeFormatter.ofPattern(outputFormatString);
LocalTime time = LocalTime.parse(dateTimeString, inputFormatter);
LocalTime newTime = time.plusMinutes(minutesToAdd);
logger.info("Successfully added minutes to the input time");

return newTime.format(outputFormatter);

} else {

DateTimeFormatter outputFormatter = DateTimeFormatter.ofPattern(outputFormatString);
LocalDateTime dateTime = LocalDateTime.parse(dateTimeString, inputFormatter);

LocalDateTime newDateTime = dateTime.plusMinutes(minutesToAdd);
Comment on lines +90 to +103
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🔴 Critical

🧩 Analysis chain

🏁 Script executed:

git ls-files | grep -i "AddMinutesToDateTime"

Repository: testsigmahq/testsigma-addons

Length of output: 1887


🏁 Script executed:

cat -n add_minutes_to_the_specific_date_time_and_store_the_output_in_specific_format/src/main/java/com/testsigma/addons/ios/AddMinutesToDateTime.java

Repository: testsigmahq/testsigma-addons

Length of output: 1887


🏁 Script executed:

# Verify LocalTime.parse() behavior with different format patterns
python3 << 'EOF'
# LocalTime.parse() in Java only accepts time-only formats
# Let's document what would happen with different patterns:

formats_to_test = [
    "HH:mm",                    # time only - should work with LocalTime
    "HH:mm:ss",                 # time only - should work with LocalTime
    "yyyy-MM-dd HH:mm",         # has date - SHOULD FAIL with LocalTime
    "yyyy-MM-dd",               # date only - should fail with LocalTime
    "MM-dd HH:mm:ss",           # mixed - SHOULD FAIL with LocalTime
]

print("Format patterns analysis:")
print("-" * 60)
for fmt in formats_to_test:
    has_date_pattern = any(p in fmt for p in ["yyyy", "MM", "dd", "yy", "D", "d"])
    has_time_pattern = any(p in fmt for p in ["HH", "mm", "ss", "h"])
    
    print(f"\nFormat: {fmt}")
    print(f"  Has date pattern: {has_date_pattern}")
    print(f"  Has time pattern: {has_time_pattern}")
    print(f"  Safe for LocalTime.parse(): {has_time_pattern and not has_date_pattern}")

EOF

Repository: testsigmahq/testsigma-addons

Length of output: 1887


Line 90's condition is insufficient for routing time-only vs. datetime parsing.

The check only verifies presence of time tokens (HH, mm, ss) but ignores date tokens (yyyy, MM, dd, etc.). Formats like yyyy-MM-dd HH:mm pass this condition and incorrectly route to LocalTime.parse() at line 92, which fails because LocalTime cannot parse date components. Add a check to ensure the format contains no date tokens before using LocalTime.parse(), or rewrite the routing logic.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In
`@add_minutes_to_the_specific_date_time_and_store_the_output_in_specific_format/src/main/java/com/testsigma/addons/ios/AddMinutesToDateTime.java`
around lines 90 - 103, The routing logic using inputFormatString is too
permissive: before calling LocalTime.parse(dateTimeString, inputFormatter) (and
creating newTime), ensure the format contains no date tokens (e.g., "y", "yyyy",
"M", "MM", "d", "dd") so only pure time formats hit the LocalTime branch;
otherwise route to LocalDateTime.parse(dateTimeString, inputFormatter) (the
existing LocalDateTime/newDateTime branch). Update the condition around
inputFormatString (used with LocalTime.parse and LocalDateTime.parse) to check
for absence of date tokens or invert logic to detect date+time formats and
dispatch accordingly, keeping DateTimeFormatter outputFormatter and the
minutesToAdd logic intact.

logger.info("Successfully added minutes to the input datetime");

return newDateTime.format(outputFormatter);
}

} catch (DateTimeParseException e) {
String errorMessage = "Invalid date/time format. Please use the format: " + inputFormatString + ". Error: " + e.getMessage();
logger.warn(errorMessage);
setErrorMessage(errorMessage);
return null;
}
}
}
Loading