Class

TimestampValidator

TimestampValidator(value, oldValue, messageopt)

Constructor

# new TimestampValidator(value, oldValue, messageopt)

Validates the update of a timestamp by comparing the new timestamp with the old one, ensuring the new timestamp is more recent.

A validator that ensures timestamp values are only updated with newer timestamps.

Parameters:
Name Type Attributes Description
value Date | string | number

The timestamp value to validate

oldValue Date | string | number

The previous timestamp to compare against

message string <optional>

Optional custom error message

View Source validation/validators/TimestampValidator.ts, line 10

Example
// Using TimestampValidator with a timestamp property
class Document {
  

Methods

# hasErrors(value, args) → {string|undefined}

This method is required by the Validator interface but not used in this validator as validation only happens during updates.

Implementation of the base validator's hasErrors method.

Parameters:
Name Type Description
value any

The timestamp value to validate

args Array.<any>

Additional arguments

View Source validation/validators/TimestampValidator.ts, line 91

Always returns undefined as this validator only works during updates

string | undefined

# updateHasErrors(value, oldValue, messageopt) → {string|undefined}

Checks if a timestamp has been updated with a more recent value by converting both values to Date objects and comparing them.

Validates that a timestamp is newer than its previous value.

Parameters:
Name Type Attributes Description
value Date | string | number

The new timestamp value to validate

oldValue Date | string | number

The original timestamp to compare against

message string <optional>

Optional custom error message to override the default

View Source validation/validators/TimestampValidator.ts, line 102

An error message if validation fails (new timestamp is not newer), undefined otherwise

string | undefined