Skip to content

Conversation

@ManojTestsigma
Copy link
Contributor

@ManojTestsigma ManojTestsigma commented Nov 6, 2025

please review these addons and publish as PUBLIC

Addon name : date_time_utilities
Addon accont: https://jarvis.testsigma.com/ui/tenants/3072/addons
Jira: https://testsigma.atlassian.net/browse/CUS-8390

fix

Added 2 NLP's

  1. generates time in given format
  2. it will add minutes,seconds,hours to the given time and converts it into expected time format.

Summary by CodeRabbit

  • New Features
    • Added time calculation capabilities: automatically add a specified duration (seconds through years) to an input time with intelligent format detection and conversion support.
    • Added current UTC time capture: store the current UTC timestamp in your preferred format for use in test scenarios.

@coderabbitai
Copy link

coderabbitai bot commented Nov 6, 2025

Walkthrough

This pull request introduces comprehensive date/time utilities for the Testsigma testing framework. It adds a core TimeUtil class with automatic format detection and parsing/formatting capabilities, along with four new classes: two data generators and two web actions for manipulating and storing UTC times.

Changes

Cohort / File(s) Summary
Core Time Utility
date_time_utilities/src/main/java/com/testsigma/addons/util/TimeUtil.java
New utility class providing format auto-detection, type categorization (TIME_ONLY, DATE_ONLY, DATETIME), input parsing to LocalDateTime, output formatting, and conversion validation between format types. Supports multiple format patterns and handles edge cases like ISO-8601 strings with Z suffix.
Data Generators
date_time_utilities/src/main/java/com/testsigma/addons/DataGenerators/AddTimeToGivenTime.java, date_time_utilities/src/main/java/com/testsigma/addons/DataGenerators/StoreCurrentUTCTime.java
Two new TestDataFunction implementations: AddTimeToGivenTime accepts input time, duration (amount + unit), and format, returning time with duration added; StoreCurrentUTCTime retrieves current UTC time and formats it. Both include input validation, error handling, and detailed logging.
Web Actions
date_time_utilities/src/main/java/com/testsigma/addons/web/AddTimeToGivenTime.java, date_time_utilities/src/main/java/com/testsigma/addons/web/StoreCurrentUTCTime.java
Two new WebAction classes mirroring the data generators but storing results in runtime variables. AddTimeToGivenTime adds time durations to input times; StoreCurrentUTCTime captures current UTC time. Both handle exceptions and provide detailed feedback via result messages.

Sequence Diagram(s)

sequenceDiagram
    actor User
    participant AddTimeAction as AddTimeToGivenTime<br/>(Web Action)
    participant TimeUtil
    participant Runtime as Runtime<br/>Variables
    
    User->>AddTimeAction: execute(inputTime, amount, unit, outputFormat)
    AddTimeAction->>TimeUtil: detectInputFormat(inputTime)
    TimeUtil-->>AddTimeAction: DetectedFormat (type, formatter)
    AddTimeAction->>TimeUtil: getFormatType(outputFormat)
    TimeUtil-->>AddTimeAction: FormatType
    AddTimeAction->>TimeUtil: validateConversion(inputType, outputType)
    TimeUtil-->>AddTimeAction: OK or IllegalArgumentException
    AddTimeAction->>TimeUtil: parseTime(inputTime)
    TimeUtil-->>AddTimeAction: LocalDateTime
    Note over AddTimeAction: Add duration<br/>(amount + unit)
    AddTimeAction->>TimeUtil: formatTime(resultTime, outputFormat)
    TimeUtil-->>AddTimeAction: formatted string
    AddTimeAction->>Runtime: Store result in variable
    Runtime-->>AddTimeAction: Success
    AddTimeAction-->>User: Result with message
Loading
sequenceDiagram
    actor User
    participant StoreUTCAction as StoreCurrentUTCTime<br/>(Web Action)
    participant TimeUtil
    participant Runtime as Runtime<br/>Variables
    
    User->>StoreUTCAction: execute(timeFormat, runtimeVariable)
    StoreUTCAction->>TimeUtil: Get current UTC time
    TimeUtil-->>StoreUTCAction: ZonedDateTime (UTC)
    StoreUTCAction->>TimeUtil: formatTime(utcTime, timeFormat)
    TimeUtil-->>StoreUTCAction: formatted string
    StoreUTCAction->>Runtime: Store formatted time in variable
    Runtime-->>StoreUTCAction: Success
    StoreUTCAction-->>User: Result with success message
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

  • TimeUtil.java requires careful review of the auto-detection logic, format pattern matching, ISO-8601 edge cases, and validation rules. The multiple format patterns and parsing strategies warrant thorough testing consideration.
  • Time arithmetic in AddTimeToGivenTime classes (both web action and data generator) should be validated for correctness across all supported time units (SECONDS, MINUTES, HOURS, DAYS, WEEKS, MONTHS, YEARS).
  • Format conversion and validation flow spans multiple files and classes; ensure consistency across data generators and web actions.
  • Exception handling patterns should be verified for completeness and user-facing error message clarity across all four new action/generator classes.

Suggested reviewers

  • vigneshtestsigma
  • Ganesh-Testsigma

Poem

🐰 A hopping through time, precise and divine,
AddTime and StoreUTC in harmony align,
Format detection springs forth with delight,
As minutes and hours take flight, bright and bright!
TimeUtil's magic makes testing just fine!

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 53.85% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main changes: two new NLP actions were added—one generates time in a given format (StoreCurrentUTCTime) and another adds time to a given time (AddTimeToGivenTime).
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch CUS-8390

Warning

Review ran into problems

🔥 Problems

Git: Failed to clone repository. Please run the @coderabbitai full review command to re-trigger a full review. If the issue persists, set path_filters to include or exclude specific files.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 5

🧹 Nitpick comments (7)
date_time_utilities/src/main/java/com/testsigma/addons/util/TimeUtil.java (2)

130-139: Improve error messages to be more user-friendly.

The validation error messages are too generic and don't clearly explain the constraint to users.

Apply this diff to improve error messages:

 public static void validateConversion(FormatType inputType, FormatType outputType) throws IllegalArgumentException {
     // Time-only to date-only is not allowed
     if (inputType == FormatType.TIME_ONLY && outputType == FormatType.DATE_ONLY) {
-        throw new IllegalArgumentException("can't convert to this format");
+        throw new IllegalArgumentException("Cannot convert time-only format to date-only format. Please use a datetime output format instead.");
     }
     // Date-only to time-only is not allowed
     if (inputType == FormatType.DATE_ONLY && outputType == FormatType.TIME_ONLY) {
-        throw new IllegalArgumentException("can't convert to this format");
+        throw new IllegalArgumentException("Cannot convert date-only format to time-only format. Please use a datetime output format instead.");
     }
 }

169-270: Refactor the large switch statement to reduce duplication.

The switch statement spans over 100 lines with highly repetitive code. Each case follows the same pattern: create formatter, format time, return result. This violates the DRY principle and makes the code harder to maintain.

Consider refactoring to use a Map-based approach:

private static final Map<String, String> FORMAT_PATTERNS = new HashMap<>();
static {
    // Time-only formats
    FORMAT_PATTERNS.put("HH:MM", "HH:mm");
    FORMAT_PATTERNS.put("HH:MM:SS", "HH:mm:ss");
    FORMAT_PATTERNS.put("hh:mm AM/PM", "hh:mm a");
    FORMAT_PATTERNS.put("hh:mm:ss AM/PM", "hh:mm:ss a");
    // Date-only formats
    FORMAT_PATTERNS.put("YYYY-MM-DD", "yyyy-MM-dd");
    FORMAT_PATTERNS.put("DD-MM-YYYY", "dd-MM-yyyy");
    FORMAT_PATTERNS.put("MM/DD/YYYY", "MM/dd/yyyy");
    FORMAT_PATTERNS.put("DD/MM/YYYY", "dd/MM/yyyy");
    // Datetime formats
    FORMAT_PATTERNS.put("YYYY-MM-DD HH:MM", "yyyy-MM-dd HH:mm");
    FORMAT_PATTERNS.put("YYYY-MM-DD HH:MM:SS", "yyyy-MM-dd HH:mm:ss");
    // ... add remaining formats
    FORMAT_PATTERNS.put("YYYY-MM-DDTHH:MM:SS", "yyyy-MM-dd'T'HH:mm:ss");
    FORMAT_PATTERNS.put("YYYY-MM-DDTHH:MM:SSZ", "yyyy-MM-dd'T'HH:mm:ss'Z'");
}

public static String formatTime(LocalDateTime localTime, String format) throws IllegalArgumentException {
    if (localTime == null) {
        throw new IllegalArgumentException("LocalDateTime cannot be null");
    }
    
    String pattern = FORMAT_PATTERNS.get(format);
    if (pattern == null) {
        throw new IllegalArgumentException("Invalid time format: " + format);
    }
    
    DateTimeFormatter formatter = DateTimeFormatter.ofPattern(pattern);
    return localTime.format(formatter);
}

This approach is more maintainable and makes it easier to add new formats.

date_time_utilities/src/main/java/com/testsigma/addons/web/StoreCurrentUTCTime.java (1)

37-57: Consider adding null checks for defensive programming.

While the Testsigma SDK may guarantee that getValue() doesn't return null, adding explicit null checks would make the code more defensive and provide clearer error messages if assumptions change.

Consider adding validation at the start of the method:

 public com.testsigma.sdk.Result execute() {
     try {
+        if (timeFormat == null || timeFormat.getValue() == null) {
+            throw new IllegalArgumentException("time-format parameter is required");
+        }
+        if (runtimeVariable == null || runtimeVariable.getValue() == null) {
+            throw new IllegalArgumentException("runtime-variable parameter is required");
+        }
+        
         // Get the current UTC time
         java.time.ZonedDateTime utcTime = java.time.ZonedDateTime.now(java.time.ZoneOffset.UTC);
date_time_utilities/src/main/java/com/testsigma/addons/DataGenerators/StoreCurrentUTCTime.java (1)

21-39: Consider adding null checks for defensive programming.

Similar to the web action version, adding explicit null validation would improve robustness.

Consider adding validation:

 public TestData generate() throws Exception {
     try {
+        if (timeFormat == null || timeFormat.getValue() == null) {
+            throw new IllegalArgumentException("time-format parameter is required");
+        }
+        
         // Get the current UTC time
         java.time.ZonedDateTime utcTime = java.time.ZonedDateTime.now(java.time.ZoneOffset.UTC);
date_time_utilities/src/main/java/com/testsigma/addons/web/AddTimeToGivenTime.java (2)

47-65: Add specific handling for NumberFormatException.

Line 50 calls Long.parseLong() which can throw NumberFormatException if the user provides invalid input. Currently this would be caught by the generic Exception handler (line 112), but providing a specific error message would improve user experience.

Consider adding a specific catch block:

     } catch (IllegalArgumentException e) {
         // Handle conversion errors specifically
         String errorMessage = e.getMessage();
         logger.warn(errorMessage);
         setErrorMessage(errorMessage);
         return com.testsigma.sdk.Result.FAILED;
+    } catch (NumberFormatException e) {
+        String errorMessage = "Invalid time-amount: must be a valid number";
+        logger.warn(errorMessage);
+        setErrorMessage(errorMessage);
+        return com.testsigma.sdk.Result.FAILED;
     } catch (Exception e) {

68-92: Consider simplifying the time unit switch statement.

The switch statement is readable but could be more maintainable using a functional approach. This is an optional improvement.

Consider using a map-based approach:

private static final Map<String, BiFunction<LocalDateTime, Long, LocalDateTime>> TIME_OPERATIONS = new HashMap<>();
static {
    TIME_OPERATIONS.put("SECONDS", LocalDateTime::plusSeconds);
    TIME_OPERATIONS.put("MINUTES", LocalDateTime::plusMinutes);
    TIME_OPERATIONS.put("HOURS", LocalDateTime::plusHours);
    TIME_OPERATIONS.put("DAYS", LocalDateTime::plusDays);
    TIME_OPERATIONS.put("WEEKS", LocalDateTime::plusWeeks);
    TIME_OPERATIONS.put("MONTHS", LocalDateTime::plusMonths);
    TIME_OPERATIONS.put("YEARS", LocalDateTime::plusYears);
}

// In execute():
BiFunction<LocalDateTime, Long, LocalDateTime> operation = TIME_OPERATIONS.get(unitStr);
if (operation == null) {
    throw new IllegalArgumentException("Invalid time unit: " + unitStr);
}
LocalDateTime resultTime = operation.apply(inputTime, amount);

This approach makes it easier to maintain and test.

date_time_utilities/src/main/java/com/testsigma/addons/DataGenerators/AddTimeToGivenTime.java (1)

29-93: Add specific handling for NumberFormatException.

Similar to the web action, line 32 calls Long.parseLong() which can throw NumberFormatException. Providing a specific error message would improve the user experience.

Consider adding a specific catch block:

     } catch (IllegalArgumentException e) {
         // Handle conversion errors specifically
         String errorMessage = e.getMessage();
         logger.warn(errorMessage);
         throw new Exception("Failed to add time to given time: " + errorMessage);
+    } catch (NumberFormatException e) {
+        String errorMessage = "Invalid time-amount: must be a valid number";
+        logger.warn(errorMessage);
+        throw new Exception("Failed to add time to given time: " + errorMessage);
     } catch (Exception e) {
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 2b8eb04 and fcdbf84.

📒 Files selected for processing (5)
  • date_time_utilities/src/main/java/com/testsigma/addons/DataGenerators/AddTimeToGivenTime.java (1 hunks)
  • date_time_utilities/src/main/java/com/testsigma/addons/DataGenerators/StoreCurrentUTCTime.java (1 hunks)
  • date_time_utilities/src/main/java/com/testsigma/addons/util/TimeUtil.java (1 hunks)
  • date_time_utilities/src/main/java/com/testsigma/addons/web/AddTimeToGivenTime.java (1 hunks)
  • date_time_utilities/src/main/java/com/testsigma/addons/web/StoreCurrentUTCTime.java (1 hunks)
🔇 Additional comments (3)
date_time_utilities/src/main/java/com/testsigma/addons/web/StoreCurrentUTCTime.java (1)

22-34: Good design: Proper format support for UTC and ISO_8601.

The allowed values include "UTC" and "ISO_8601" formats, and the implementation correctly uses ZonedDateTime (line 40) with the formatTime(ZonedDateTime, String) overload (line 43), which properly supports these formats. This is the right approach for handling UTC time.

date_time_utilities/src/main/java/com/testsigma/addons/web/AddTimeToGivenTime.java (1)

26-37: Correct format restrictions for AddTimeToGivenTime.

The timeFormat allowedValues appropriately excludes "UTC" and "ISO_8601" formats. Unlike StoreCurrentUTCTime which works with ZonedDateTime, this action uses LocalDateTime (line 64) for time arithmetic, so those formats wouldn't be appropriate here.

date_time_utilities/src/main/java/com/testsigma/addons/util/TimeUtil.java (1)

305-308: Clarify the purpose or remove the legacy formatTime method.

The comment indicates this method is for backward compatibility, but the implementation seems problematic. It attempts to parse the input string directly as a LocalDateTime without format detection, which will fail for most real-world time strings (like "14:30" or "2025-11-06").

Please verify:

  1. Is this method actually used anywhere in the codebase?
  2. What is the expected input format for this method?
  3. If it's truly legacy and unused, consider removing it to reduce confusion.

Run this script to check for usages:

Comment on lines +18 to +25
@TestDataFunctionParameter(reference = "test-data")
private com.testsigma.sdk.TestDataParameter testData;
@TestDataFunctionParameter(reference = "time-amount")
private com.testsigma.sdk.TestDataParameter timeAmount;
@TestDataFunctionParameter(reference = "time-unit")
private com.testsigma.sdk.TestDataParameter timeUnit;
@TestDataFunctionParameter(reference = "time-format")
private com.testsigma.sdk.TestDataParameter timeFormat;
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major

Add allowedValues annotations to guide users.

Unlike the web action version, the data generator doesn't specify allowedValues for time-unit and time-format parameters. Users need to see what options are available.

Apply this diff to add allowedValues:

 @TestDataFunctionParameter(reference = "test-data")
 private com.testsigma.sdk.TestDataParameter testData;
 @TestDataFunctionParameter(reference = "time-amount")
 private com.testsigma.sdk.TestDataParameter timeAmount;
-@TestDataFunctionParameter(reference = "time-unit")
+@TestDataFunctionParameter(reference = "time-unit", allowedValues = {"SECONDS", "MINUTES", "HOURS", "DAYS", "WEEKS", "MONTHS", "YEARS"})
 private com.testsigma.sdk.TestDataParameter timeUnit;
-@TestDataFunctionParameter(reference = "time-format")
+@TestDataFunctionParameter(reference = "time-format", allowedValues = {
+        "HH:MM", "HH:MM:SS",
+        "YYYY-MM-DD", "DD-MM-YYYY", "MM/DD/YYYY", "DD/MM/YYYY",
+        "YYYY-MM-DD HH:MM", "YYYY-MM-DD HH:MM:SS",
+        "DD-MM-YYYY HH:MM", "DD-MM-YYYY HH:MM:SS",
+        "MM/DD/YYYY HH:MM", "MM/DD/YYYY HH:MM:SS",
+        "DD/MM/YYYY HH:MM", "DD/MM/YYYY HH:MM:SS",
+        "hh:mm AM/PM", "hh:mm:ss AM/PM",
+        "YYYY-MM-DD hh:mm AM/PM", "YYYY-MM-DD hh:mm:ss AM/PM",
+        "YYYY-MM-DDTHH:MM:SS", "YYYY-MM-DDTHH:MM:SSZ"
+})
 private com.testsigma.sdk.TestDataParameter timeFormat;
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
@TestDataFunctionParameter(reference = "test-data")
private com.testsigma.sdk.TestDataParameter testData;
@TestDataFunctionParameter(reference = "time-amount")
private com.testsigma.sdk.TestDataParameter timeAmount;
@TestDataFunctionParameter(reference = "time-unit")
private com.testsigma.sdk.TestDataParameter timeUnit;
@TestDataFunctionParameter(reference = "time-format")
private com.testsigma.sdk.TestDataParameter timeFormat;
@TestDataFunctionParameter(reference = "test-data")
private com.testsigma.sdk.TestDataParameter testData;
@TestDataFunctionParameter(reference = "time-amount")
private com.testsigma.sdk.TestDataParameter timeAmount;
@TestDataFunctionParameter(reference = "time-unit", allowedValues = {"SECONDS", "MINUTES", "HOURS", "DAYS", "WEEKS", "MONTHS", "YEARS"})
private com.testsigma.sdk.TestDataParameter timeUnit;
@TestDataFunctionParameter(reference = "time-format", allowedValues = {
"HH:MM", "HH:MM:SS",
"YYYY-MM-DD", "DD-MM-YYYY", "MM/DD/YYYY", "DD/MM/YYYY",
"YYYY-MM-DD HH:MM", "YYYY-MM-DD HH:MM:SS",
"DD-MM-YYYY HH:MM", "DD-MM-YYYY HH:MM:SS",
"MM/DD/YYYY HH:MM", "MM/DD/YYYY HH:MM:SS",
"DD/MM/YYYY HH:MM", "DD/MM/YYYY HH:MM:SS",
"hh:mm AM/PM", "hh:mm:ss AM/PM",
"YYYY-MM-DD hh:mm AM/PM", "YYYY-MM-DD hh:mm:ss AM/PM",
"YYYY-MM-DDTHH:MM:SS", "YYYY-MM-DDTHH:MM:SSZ"
})
private com.testsigma.sdk.TestDataParameter timeFormat;
🤖 Prompt for AI Agents
In
date_time_utilities/src/main/java/com/testsigma/addons/DataGenerators/AddTimeToGivenTime.java
around lines 18 to 25, the TestDataFunctionParameter annotations for time-unit
and time-format lack allowedValues which leaves users guessing; add
allowedValues arrays to both parameters to mirror the web action options (e.g.
for time-unit: {"SECONDS","MINUTES","HOURS","DAYS"} and for time-format:
{"HH:mm","hh:mm a","HH:mm:ss","ISO_LOCAL_TIME"} or the exact format list used by
the corresponding web action). Update the two @TestDataFunctionParameter
annotations to include the allowedValues property so the UI shows the available
choices.

Comment on lines +17 to +18
@TestDataFunctionParameter(reference = "time-format")
private com.testsigma.sdk.TestDataParameter timeFormat;
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major

Add allowedValues annotation to guide users on supported formats.

Unlike the web action version, this data generator doesn't specify allowedValues for the time-format parameter. This means users won't see a dropdown of valid format options in the UI, making it harder to use correctly.

Apply this diff to add the allowedValues annotation:

-@TestDataFunctionParameter(reference = "time-format")
+@TestDataFunctionParameter(reference = "time-format", allowedValues = {
+        "UTC",
+        "ISO_8601",
+        "HH:MM", "HH:MM:SS", "hh:mm AM/PM", "hh:mm:ss AM/PM",
+        "YYYY-MM-DD", "DD-MM-YYYY", "MM/DD/YYYY", "DD/MM/YYYY",
+        "YYYY-MM-DD HH:MM", "YYYY-MM-DD HH:MM:SS",
+        "DD-MM-YYYY HH:MM", "DD-MM-YYYY HH:MM:SS",
+        "MM/DD/YYYY HH:MM", "MM/DD/YYYY HH:MM:SS",
+        "DD/MM/YYYY HH:MM", "DD/MM/YYYY HH:MM:SS",
+        "YYYY-MM-DD hh:mm AM/PM", "YYYY-MM-DD hh:mm:ss AM/PM",
+        "YYYY-MM-DDTHH:MM:SS", "YYYY-MM-DDTHH:MM:SSZ"
+})
 private com.testsigma.sdk.TestDataParameter timeFormat;
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
@TestDataFunctionParameter(reference = "time-format")
private com.testsigma.sdk.TestDataParameter timeFormat;
@TestDataFunctionParameter(reference = "time-format", allowedValues = {
"UTC",
"ISO_8601",
"HH:MM", "HH:MM:SS", "hh:mm AM/PM", "hh:mm:ss AM/PM",
"YYYY-MM-DD", "DD-MM-YYYY", "MM/DD/YYYY", "DD/MM/YYYY",
"YYYY-MM-DD HH:MM", "YYYY-MM-DD HH:MM:SS",
"DD-MM-YYYY HH:MM", "DD-MM-YYYY HH:MM:SS",
"MM/DD/YYYY HH:MM", "MM/DD/YYYY HH:MM:SS",
"DD/MM/YYYY HH:MM", "DD/MM/YYYY HH:MM:SS",
"YYYY-MM-DD hh:mm AM/PM", "YYYY-MM-DD hh:mm:ss AM/PM",
"YYYY-MM-DDTHH:MM:SS", "YYYY-MM-DDTHH:MM:SSZ"
})
private com.testsigma.sdk.TestDataParameter timeFormat;
🤖 Prompt for AI Agents
In
date_time_utilities/src/main/java/com/testsigma/addons/DataGenerators/StoreCurrentUTCTime.java
around lines 17 to 18, the TestDataFunctionParameter for time-format lacks an
allowedValues annotation so users don't get a dropdown of supported formats; add
an allowedValues attribute to the annotation listing the valid format strings
(e.g., "ISO8601", "RFC1123", "yyyy-MM-dd'T'HH:mm:ss'Z'", "yyyy-MM-dd HH:mm:ss",
"HH:mm:ss") or the actual set of supported formats used by the generator so the
UI shows those options.

Comment on lines +22 to +32
public static class DetectedFormat {
public String formatStr;
public FormatType type;
public DateTimeFormatter formatter;

public DetectedFormat(String formatStr, FormatType type, DateTimeFormatter formatter) {
this.formatStr = formatStr;
this.type = type;
this.formatter = formatter;
}
}
Copy link

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion | 🟠 Major

Add proper encapsulation to DetectedFormat class.

The DetectedFormat class exposes public mutable fields, which breaks encapsulation and allows external code to modify the internal state. This can lead to unexpected behavior and makes the class harder to maintain.

Apply this diff to add proper getters and make fields private:

 public static class DetectedFormat {
-    public String formatStr;
-    public FormatType type;
-    public DateTimeFormatter formatter;
+    private final String formatStr;
+    private final FormatType type;
+    private final DateTimeFormatter formatter;

     public DetectedFormat(String formatStr, FormatType type, DateTimeFormatter formatter) {
         this.formatStr = formatStr;
         this.type = type;
         this.formatter = formatter;
     }
+
+    public String getFormatStr() {
+        return formatStr;
+    }
+
+    public FormatType getType() {
+        return type;
+    }
+
+    public DateTimeFormatter getFormatter() {
+        return formatter;
+    }
 }

Note: This will require updating all usages of DetectedFormat to use getters instead of direct field access.

📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
public static class DetectedFormat {
public String formatStr;
public FormatType type;
public DateTimeFormatter formatter;
public DetectedFormat(String formatStr, FormatType type, DateTimeFormatter formatter) {
this.formatStr = formatStr;
this.type = type;
this.formatter = formatter;
}
}
public static class DetectedFormat {
private final String formatStr;
private final FormatType type;
private final DateTimeFormatter formatter;
public DetectedFormat(String formatStr, FormatType type, DateTimeFormatter formatter) {
this.formatStr = formatStr;
this.type = type;
this.formatter = formatter;
}
public String getFormatStr() {
return formatStr;
}
public FormatType getType() {
return type;
}
public DateTimeFormatter getFormatter() {
return formatter;
}
}
🤖 Prompt for AI Agents
In date_time_utilities/src/main/java/com/testsigma/addons/util/TimeUtil.java
around lines 22 to 32, the DetectedFormat inner class currently exposes public
mutable fields which breaks encapsulation; make the fields private (preferably
private final), add public getter methods for each field (getFormatStr(),
getType(), getFormatter()), keep the constructor to initialize the fields, and
optionally mark the class final; after this change, update all call sites to use
the getters instead of direct field access.

Comment on lines +50 to +60
public static FormatType getFormatType(String formatStr) {
if (formatStr.equals("HH:MM") || formatStr.equals("HH:MM:SS") ||
formatStr.equals("hh:mm AM/PM") || formatStr.equals("hh:mm:ss AM/PM")) {
return FormatType.TIME_ONLY;
} else if (formatStr.equals("YYYY-MM-DD") || formatStr.equals("DD-MM-YYYY") ||
formatStr.equals("MM/DD/YYYY") || formatStr.equals("DD/MM/YYYY")) {
return FormatType.DATE_ONLY;
} else {
return FormatType.DATETIME;
}
}
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major

Add support for "UTC" and "ISO_8601" formats.

The getFormatType() method doesn't recognize "UTC" and "ISO_8601" formats, yet these are included in the allowedValues for StoreCurrentUTCTime classes. This inconsistency will cause runtime failures when users select these formats in actions that call getFormatType().

Apply this diff to add support for these formats:

 public static FormatType getFormatType(String formatStr) {
+    if (formatStr.equals("UTC") || formatStr.equals("ISO_8601")) {
+        return FormatType.DATETIME;
+    } else if (formatStr.equals("HH:MM") || formatStr.equals("HH:MM:SS") || 
-    if (formatStr.equals("HH:MM") || formatStr.equals("HH:MM:SS") || 
         formatStr.equals("hh:mm AM/PM") || formatStr.equals("hh:mm:ss AM/PM")) {
         return FormatType.TIME_ONLY;
     } else if (formatStr.equals("YYYY-MM-DD") || formatStr.equals("DD-MM-YYYY") || 
                formatStr.equals("MM/DD/YYYY") || formatStr.equals("DD/MM/YYYY")) {
         return FormatType.DATE_ONLY;
     } else {
         return FormatType.DATETIME;
     }
 }
🤖 Prompt for AI Agents
In date_time_utilities/src/main/java/com/testsigma/addons/util/TimeUtil.java
around lines 50 to 60, getFormatType currently doesn't recognize the "UTC" and
"ISO_8601" format strings which causes runtime failures; update the conditional
checks to treat "UTC" and "ISO_8601" as FormatType.DATETIME (add them to the
else-if branch that returns DATETIME or add an explicit check returning
DATETIME), and also make the method null-safe by guarding against a null
formatStr (e.g., return DATETIME or throw a clear exception if formatStr is
null) so callers selecting those allowedValues won't fail at runtime.

Comment on lines +144 to +164
public static LocalDateTime parseTime(String inputTimeStr) throws IllegalArgumentException {
DetectedFormat detectedInput = detectInputFormat(inputTimeStr);
String detectedInputFormatStr = detectedInput.formatStr;

// Parse the input time based on the detected format
if (detectedInput.type == FormatType.TIME_ONLY) {
LocalTime timeOnly = LocalTime.parse(inputTimeStr, detectedInput.formatter);
return LocalDateTime.of(LocalDate.now(), timeOnly);
} else if (detectedInput.type == FormatType.DATE_ONLY) {
LocalDate dateOnly = LocalDate.parse(inputTimeStr, detectedInput.formatter);
return dateOnly.atStartOfDay();
} else {
// Handle ISO format with Z
if (detectedInputFormatStr.equals("YYYY-MM-DDTHH:MM:SSZ")) {
String withoutZ = inputTimeStr.replace("Z", "");
return LocalDateTime.parse(withoutZ, detectedInput.formatter);
} else {
return LocalDateTime.parse(inputTimeStr, detectedInput.formatter);
}
}
}
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major

Add input validation to prevent null or empty string inputs.

The method doesn't validate the input parameter before processing, which can lead to unclear error messages or NullPointerException.

Apply this diff to add input validation:

 public static LocalDateTime parseTime(String inputTimeStr) throws IllegalArgumentException {
+    if (inputTimeStr == null || inputTimeStr.trim().isEmpty()) {
+        throw new IllegalArgumentException("Input time string cannot be null or empty");
+    }
+    
     DetectedFormat detectedInput = detectInputFormat(inputTimeStr);
     String detectedInputFormatStr = detectedInput.formatStr;
🤖 Prompt for AI Agents
In date_time_utilities/src/main/java/com/testsigma/addons/util/TimeUtil.java
around lines 144 to 164, the parseTime method does not validate the input string
and may throw NullPointerException or produce unclear errors; add a defensive
check at the start to ensure inputTimeStr is not null or blank (use trim() to
detect whitespace-only), and if it is, throw an IllegalArgumentException with a
clear message like "inputTimeStr must not be null or empty"; then proceed to
call detectInputFormat and the existing parsing logic using the validated (and
possibly trimmed) string.

@ManojTestsigma ManojTestsigma merged commit 5638007 into dev Nov 12, 2025
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants