Skip to content

[NAE-2425] Allowing using seconds in dateTime field#327

Open
machacjozef wants to merge 2 commits intorelease/6.4.3from
NAE-2425
Open

[NAE-2425] Allowing using seconds in dateTime field#327
machacjozef wants to merge 2 commits intorelease/6.4.3from
NAE-2425

Conversation

@machacjozef
Copy link
Copy Markdown
Member

@machacjozef machacjozef commented May 5, 2026

Description

  • Introduces DATE_TIME_SECONDS_FORMAT for finer-grained date-time representation.
  • Refactors FieldConverterService with a reusable resolveDateTime method.
  • Enhances DateTimeField with seconds display and configurable steps.
  • Updates datetime-picker to include seconds and toggle meridian mode.

new property:

public static readonly SHOW_SECONDS_PROPERTY = 'showSeconds';

public static readonly ENABLE_MERIDIAN_PROPERTY = 'enableMeridian';

public static readonly STEP_HOUR_PROPERTY = 'stepHour';
public static readonly STEP_MINUTE_PROPERTY = 'stepMinute';
public static readonly STEP_SECOND_PROPERTY = 'stepSecond';

Implements NAE-2425

Dependencies

Third party dependencies

No new dependencies were introduced

Blocking Pull requests

There are no dependencies on other PR

How Has Been This Tested?

  • <Name of a test [test file](link to the test file)>

Test Configuration

<Please describe configuration for tests to run if applicable, like program parameters, host OS, VM configuration etc. You can use >

Name Tested on
OS
Runtime
Dependency Manager
Framework version
Run parameters
Other configuration

Checklist:

  • My code follows the style guidelines of this project
  • I have performed a self-review of my own code
  • My changes have been checked, personally or remotely, with @RudeBoyxX
  • I have commented my code, particularly in hard-to-understand areas
  • I have resolved all conflicts with the target branch of the PR
  • I have updated and synced my code with the target branch
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing tests pass locally with my changes:
    • Lint test
    • Unit tests
    • Integration tests
  • I have checked my contribution with code analysis tools:
  • I have made corresponding changes to the documentation:
    • Developer documentation
    • User Guides
    • Migration Guides

Summary by CodeRabbit

Release Notes

  • New Features

    • Added seconds precision support to datetime fields for improved time tracking accuracy.
  • Enhancements

    • Datetime picker now offers configurable intervals for hour, minute, and second increments.
    • Enhanced datetime value comparison with second-level granularity.
    • Improved property parsing with stronger type safety and default value handling.

machacjozef and others added 2 commits May 5, 2026 17:49
- Introduces `DATE_TIME_SECONDS_FORMAT` for finer-grained date-time representation.
- Refactors `FieldConverterService` with a reusable `resolveDateTime` method.
- Enhances `DateTimeField` with seconds display and configurable steps.
- Updates datetime-picker to include seconds and toggle meridian mode.
@machacjozef machacjozef self-assigned this May 5, 2026
@sonarqubecloud
Copy link
Copy Markdown

sonarqubecloud Bot commented May 5, 2026

Quality Gate Failed Quality Gate failed

Failed conditions
18.5% Coverage on New Code (required ≥ 50%)

See analysis details on SonarQube Cloud

@netgrif netgrif deleted a comment from coderabbitai Bot May 5, 2026
@netgrif netgrif deleted a comment from coderabbitai Bot May 5, 2026
@machacjozef
Copy link
Copy Markdown
Member Author

@coderabbitai Hey, check out my PR :)

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 5, 2026

Hey @machacjozef! 👋 Happy to take a look at your PR! I'll kick off a full review of your changes for NAE-2425 — the datetime seconds support looks interesting. Hang tight!

✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 5, 2026

Walkthrough

This PR adds seconds-level precision support to datetime fields by introducing configurable property keys, parsing utilities, and a new date format. Changes span base component helpers, datetime field models, format definitions, service consolidation, and template/provider updates to enable dynamic seconds visibility and step configuration.

Changes

Datetime Seconds Precision Feature

Layer / File(s) Summary
Core Parsing Utilities
projects/netgrif-components-core/src/lib/data-fields/base-component/abstract-base-data-field.component.ts
Added static TRUE_VALUES and FALSE_VALUES lookup arrays, plus resolveBooleanProperty(...) and resolveNumberProperty(...) static methods for typed property parsing with defaults. Added instance helpers getBooleanComponentProperty(...) and getNumberComponentProperty(...) that delegate to the static methods.
Data Model Enrichment
projects/netgrif-components-core/src/lib/data-fields/date-time-field/models/date-time-field.ts
Exposed static property-key constants for showSeconds, enableMeridian, and step increments. Added public getters resolving these values from component properties with appropriate defaults. Changed equality logic to compare Moment objects at 'second' granularity instead of 'minute'.
DateTime Component Accessors
projects/netgrif-components-core/src/lib/data-fields/date-time-field/date-time-default-field/abstract-date-time-default-field.component.ts
Exposed new public getters (showSeconds, stepHour, stepMinute, stepSecond, enableMeridian) that read from this.dataField with typed defaults.
Time Format Definitions
projects/netgrif-components-core/src/lib/moment/time-formats.ts
Added DATE_TIME_SECONDS_FORMAT_STRING constant and new DATE_TIME_SECONDS_FORMAT formatter supporting both seconds and minute-level parsing with corresponding display labels.
Service DateTime Resolution
projects/netgrif-components-core/src/lib/task-content/services/field-converter.service.ts
Centralized DATE_TIME parsing by introducing a new protected resolveDateTime(...) helper that handles Moment, Date, array-like date parts, and fallback values. Updated imports and replaced inline moment(...) construction with calls to this helper.
Template & Provider Configuration
projects/netgrif-components/src/lib/data-fields/date-time-field/date-time-default-field/date-time-default-field.component.html, projects/netgrif-components/src/lib/data-fields/date-time-field/date-time-default-field/date-time-default-field.component.ts
Template now binds datetime picker inputs to component properties instead of hardcoded values. Component provides NGX_MAT_DATE_FORMATS via a factory that conditionally selects DATE_TIME_SECONDS_FORMAT when showSeconds is enabled, otherwise uses DATE_TIME_FORMAT.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~22 minutes

Suggested labels

new feature, Medium

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'NAE-2425 Allowing using seconds in dateTime field' clearly and specifically summarizes the main feature addition—enabling seconds-level support in the datetime field component.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.


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
Copy Markdown

@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: 3

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In
`@projects/netgrif-components-core/src/lib/data-fields/date-time-field/models/date-time-field.ts`:
- Line 7: DateTimeField currently imports AbstractBaseDataFieldComponent for
static parsing helpers; remove that dependency by extracting the parsing logic
into a neutral utility (e.g., FieldPropertyParser or date-time specific parser
util) and have DateTimeField use the new util instead; update the static parser
helpers referenced on the DateTimeField model (and any usages in
AbstractBaseDataFieldComponent) to import from the new util so the model no
longer imports the UI component class.
- Around line 31-51: The getters stepHour, stepMinute, and stepSecond should
validate the resolved number to ensure it is a positive integer (>0) and
otherwise fall back to their defaults (1, 5, 1); change each getter to call
AbstractBaseDataFieldComponent.resolveNumberProperty as now, then
coerce/validate the result from DateTimeField.STEP_HOUR_PROPERTY /
STEP_MINUTE_PROPERTY / STEP_SECOND_PROPERTY into a positive integer (e.g.,
Math.floor or equivalent) and if the value is not a finite integer > 0 return
the respective default.

In
`@projects/netgrif-components-core/src/lib/task-content/services/field-converter.service.ts`:
- Around line 317-340: In resolveDateTime, avoid treating falsy-but-valid inputs
like 0 as empty and guard against invalid Moment results: replace the initial if
(!value) with a nullish/empty-string check (e.g. if (value == null || value ===
'') return undefined), keep the existing branches for moment, Date and Array,
but after creating a Moment from Array or generic moment(value) verify the
result is valid (use moment.isMoment(...) || result.isValid()) and return
undefined if invalid; reference the resolveDateTime function, the Array
destructuring branch, and the final return moment(value) conversion when adding
these validity checks.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro

Run ID: f6025c83-2cfa-49ad-9a2b-b4da0adcc245

📥 Commits

Reviewing files that changed from the base of the PR and between 3c5c073 and 848b38d.

📒 Files selected for processing (7)
  • projects/netgrif-components-core/src/lib/data-fields/base-component/abstract-base-data-field.component.ts
  • projects/netgrif-components-core/src/lib/data-fields/date-time-field/date-time-default-field/abstract-date-time-default-field.component.ts
  • projects/netgrif-components-core/src/lib/data-fields/date-time-field/models/date-time-field.ts
  • projects/netgrif-components-core/src/lib/moment/time-formats.ts
  • projects/netgrif-components-core/src/lib/task-content/services/field-converter.service.ts
  • projects/netgrif-components/src/lib/data-fields/date-time-field/date-time-default-field/date-time-default-field.component.html
  • projects/netgrif-components/src/lib/data-fields/date-time-field/date-time-default-field/date-time-default-field.component.ts

import {Layout} from '../../models/layout';
import {Validation} from '../../models/validation';
import {Component, ComponentPrefixes} from '../../models/component';
import {AbstractBaseDataFieldComponent} from '../../base-component/abstract-base-data-field.component';
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion | 🟠 Major | 🏗️ Heavy lift

Decouple DateTimeField model from AbstractBaseDataFieldComponent.

Importing a UI component class into a model for static parsing helpers couples layers unnecessarily. Move these parsers into a neutral utility (e.g., field-property parser util) and reuse from both model/component layers.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In
`@projects/netgrif-components-core/src/lib/data-fields/date-time-field/models/date-time-field.ts`
at line 7, DateTimeField currently imports AbstractBaseDataFieldComponent for
static parsing helpers; remove that dependency by extracting the parsing logic
into a neutral utility (e.g., FieldPropertyParser or date-time specific parser
util) and have DateTimeField use the new util instead; update the static parser
helpers referenced on the DateTimeField model (and any usages in
AbstractBaseDataFieldComponent) to import from the new util so the model no
longer imports the UI component class.

Comment on lines +31 to +51
public get stepHour(): number {
return AbstractBaseDataFieldComponent.resolveNumberProperty(
this.component?.properties?.[DateTimeField.STEP_HOUR_PROPERTY],
1
);
}

public get stepMinute(): number {
return AbstractBaseDataFieldComponent.resolveNumberProperty(
this.component?.properties?.[DateTimeField.STEP_MINUTE_PROPERTY],
5
);
}


public get stepSecond(): number {
return AbstractBaseDataFieldComponent.resolveNumberProperty(
this.component?.properties?.[DateTimeField.STEP_SECOND_PROPERTY],
1
);
}
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 | 🟠 Major | ⚡ Quick win

Constrain step properties to positive integers before exposing them.

stepHour, stepMinute, and stepSecond currently pass through any finite number (including 0, negative, or decimal). Add a > 0 integer guard and fallback defaults.

Proposed fix
 public get stepHour(): number {
-    return AbstractBaseDataFieldComponent.resolveNumberProperty(
+    const value = AbstractBaseDataFieldComponent.resolveNumberProperty(
         this.component?.properties?.[DateTimeField.STEP_HOUR_PROPERTY],
         1
     );
+    return Number.isInteger(value) && value > 0 ? value : 1;
 }

 public get stepMinute(): number {
-    return AbstractBaseDataFieldComponent.resolveNumberProperty(
+    const value = AbstractBaseDataFieldComponent.resolveNumberProperty(
         this.component?.properties?.[DateTimeField.STEP_MINUTE_PROPERTY],
         5
     );
+    return Number.isInteger(value) && value > 0 ? value : 5;
 }

 public get stepSecond(): number {
-    return AbstractBaseDataFieldComponent.resolveNumberProperty(
+    const value = AbstractBaseDataFieldComponent.resolveNumberProperty(
         this.component?.properties?.[DateTimeField.STEP_SECOND_PROPERTY],
         1
     );
+    return Number.isInteger(value) && value > 0 ? value : 1;
 }
📝 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 get stepHour(): number {
return AbstractBaseDataFieldComponent.resolveNumberProperty(
this.component?.properties?.[DateTimeField.STEP_HOUR_PROPERTY],
1
);
}
public get stepMinute(): number {
return AbstractBaseDataFieldComponent.resolveNumberProperty(
this.component?.properties?.[DateTimeField.STEP_MINUTE_PROPERTY],
5
);
}
public get stepSecond(): number {
return AbstractBaseDataFieldComponent.resolveNumberProperty(
this.component?.properties?.[DateTimeField.STEP_SECOND_PROPERTY],
1
);
}
public get stepHour(): number {
const value = AbstractBaseDataFieldComponent.resolveNumberProperty(
this.component?.properties?.[DateTimeField.STEP_HOUR_PROPERTY],
1
);
return Number.isInteger(value) && value > 0 ? value : 1;
}
public get stepMinute(): number {
const value = AbstractBaseDataFieldComponent.resolveNumberProperty(
this.component?.properties?.[DateTimeField.STEP_MINUTE_PROPERTY],
5
);
return Number.isInteger(value) && value > 0 ? value : 5;
}
public get stepSecond(): number {
const value = AbstractBaseDataFieldComponent.resolveNumberProperty(
this.component?.properties?.[DateTimeField.STEP_SECOND_PROPERTY],
1
);
return Number.isInteger(value) && value > 0 ? value : 1;
}
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In
`@projects/netgrif-components-core/src/lib/data-fields/date-time-field/models/date-time-field.ts`
around lines 31 - 51, The getters stepHour, stepMinute, and stepSecond should
validate the resolved number to ensure it is a positive integer (>0) and
otherwise fall back to their defaults (1, 5, 1); change each getter to call
AbstractBaseDataFieldComponent.resolveNumberProperty as now, then
coerce/validate the result from DateTimeField.STEP_HOUR_PROPERTY /
STEP_MINUTE_PROPERTY / STEP_SECOND_PROPERTY into a positive integer (e.g.,
Math.floor or equivalent) and if the value is not a finite integer > 0 return
the respective default.

Comment on lines +317 to +340
protected resolveDateTime(value: any): Moment | undefined {
if (!value) {
return undefined;
}
if (moment.isMoment(value)) {
return value;
}
if (value instanceof Date) {
return moment(value);
}
if (Array.isArray(value)) {
const [year, month, day, hour = 0, minute = 0, second = 0, millisecond = 0] = value;
return moment({
year,
month: month - 1,
date: day,
hour,
minute,
second,
millisecond
});
}
return moment(value);
}
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 | ⚡ Quick win

Handle falsy-but-valid input and invalid parse output in resolveDateTime.

Line 318 currently treats 0 as empty, and invalid parsed values are returned unguarded. Use a nullish/empty-string check and return undefined for invalid parse results.

Proposed fix
 protected resolveDateTime(value: any): Moment | undefined {
-    if (!value) {
+    if (value === undefined || value === null || value === '') {
         return undefined;
     }
+    let parsed: Moment;
     if (moment.isMoment(value)) {
-        return value;
+        parsed = value;
+    } else if (value instanceof Date) {
+        parsed = moment(value);
+    } else if (Array.isArray(value)) {
+        const [year, month, day, hour = 0, minute = 0, second = 0, millisecond = 0] = value;
+        parsed = moment({
+            year,
+            month: month - 1,
+            date: day,
+            hour,
+            minute,
+            second,
+            millisecond
+        });
+    } else {
+        parsed = moment(value);
     }
-    if (value instanceof Date) {
-        return moment(value);
-    }
-    if (Array.isArray(value)) {
-        const [year, month, day, hour = 0, minute = 0, second = 0, millisecond = 0] = value;
-        return moment({
-            year,
-            month: month - 1,
-            date: day,
-            hour,
-            minute,
-            second,
-            millisecond
-        });
-    }
-    return moment(value);
+    return parsed.isValid() ? parsed : undefined;
 }
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In
`@projects/netgrif-components-core/src/lib/task-content/services/field-converter.service.ts`
around lines 317 - 340, In resolveDateTime, avoid treating falsy-but-valid
inputs like 0 as empty and guard against invalid Moment results: replace the
initial if (!value) with a nullish/empty-string check (e.g. if (value == null ||
value === '') return undefined), keep the existing branches for moment, Date and
Array, but after creating a Moment from Array or generic moment(value) verify
the result is valid (use moment.isMoment(...) || result.isValid()) and return
undefined if invalid; reference the resolveDateTime function, the Array
destructuring branch, and the final return moment(value) conversion when adding
these validity checks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants