ChronosChronos

Symbol Methods

Symbol.iterator

Enables iteration over date components, allowing destructuring and array spreading.

Signature

*[Symbol.iterator](): IterableIterator<[string, number]>

Return Type

IterableIterator<[string, number]> - Date components as key-value pairs

Behavior

  • Yields all date components as [property, value] pairs
  • Enables destructuring assignment and for...of loops
  • Compatible with array spread operator

Example

playground.ts

Symbol.toPrimitive

Provides primitive value conversion for mathematical operations and string interpolation.

Signature

[Symbol.toPrimitive](hint: string): string | number

Parameters

  • hint: Conversion hint ('number' or 'string')

Return Type

string | number - Primitive value

Behavior

  • number hint: Returns timestamp for mathematical operations
  • string hint: Returns ISO string based on instance origin
  • default hint: Returns ISO string for string interpolation

Info

  • This method is the basis for the String() constructor and the String.prototype.toString() method when hint is 'string'.

Example

playground.ts

Symbol.replace

Enables Chronos instances to be used as search patterns in String.prototype.replace().

Signature

[Symbol.replace](string: string, replacement: string): string

Parameters

  • string: The string to perform replacement on
  • replacement: The replacement string

Return Type

string - The modified string with replacements

Behavior

  • Replaces date patterns in strings based on Chronos instance format
  • Handles different ISO string formats depending on instance origin
  • Supports timezone-aware replacements

Example

playground.ts

Symbol.search

Enables Chronos instances to be used as search patterns in String.prototype.search().

Signature

[Symbol.search](string: string): number

Parameters

  • string: The string to search within

Return Type

number - Index of the first match or -1 if not found

Behavior

  • Searches for date patterns in strings
  • Returns the position of the matched date pattern
  • Handles different ISO formats based on instance origin

Example

playground.ts

Symbol.split

Enables Chronos instances to be used as separators in String.prototype.split().

Signature

[Symbol.split](string: string): string[]

Parameters

  • string: The string to split

Return Type

string[] - Array of substrings

Behavior

  • Splits strings using the Chronos instance's date pattern as delimiter
  • Handles different date formats based on instance origin
  • Useful for parsing text containing date separators

Example

playground.ts

Symbol.match

Enables Chronos instances to be used as regex patterns in string matching operations.

Signature

[Symbol.match](string: string): RegExpMatchArray | null

Parameters

  • string: The string to search for date patterns

Return Type

RegExpMatchArray | null - Match result or null if no match found

Behavior

  • Supports fuzzy matching of various date and time formats
  • Automatically handles both date-only and datetime patterns
  • Flexible separator matching (hyphens, slashes, dots, or no separators)

Supported Formats

Date Formats:

  • 2025-09-01 (standard hyphenated)
  • 2025/09/01 (slash separated)
  • 20250901 (compact)

Time Formats:

  • 13:26:00 (colon separated)
  • 13.26.00 (dot separated)
  • 132600 (compact)

Separators:

  • T (ISO standard)
  • Space
  • No separator

Example

playground.ts

Symbol.toStringTag

Customizes the default string description of the object.

Signature

get [Symbol.toStringTag](): string

Return Type

string - String tag representation

Behavior

  • Used by Object.prototype.toString() method
  • Returns different ISO string formats based on instance origin
  • Provides meaningful string representation for object inspection

Example

playground.ts

Symbol.isConcatSpreadable

Enables Chronos instances to be spread when used with array concatenation.

Signature

get [Symbol.isConcatSpreadable](): boolean

Return Type

boolean - Always returns true

Behavior

  • Allows Chronos objects to be spread into arrays using spread operator
  • Enables array concatenation with Chronos instances
  • Returns key-value pairs for each date component when spread

Example

playground.ts

Notes

  • Useful for extracting all date components into an array
  • Enables functional programming patterns with date data
  • Compatible with array methods like map, filter, and reduce

Last updated: Fri, Jun 19, 2026 06:06:59PM (UTC)

On this page