Skip to content

feat: date v2#345

Merged
stefan-gorules merged 11 commits into
masterfrom
feat/date-v2
May 12, 2025
Merged

feat: date v2#345
stefan-gorules merged 11 commits into
masterfrom
feat/date-v2

Conversation

@stefan-gorules

@stefan-gorules stefan-gorules commented May 4, 2025

Copy link
Copy Markdown
Contributor

Date v2: Enhanced Date Manipulation Capabilities

This PR introduces a completely revamped date handling system that provides powerful, intuitive date manipulation capabilities to the expression engine.

Features

  • ✨ Modern date implementation with timezone support
  • 🛠️ Rich set of date manipulation methods (add, sub, set, format, etc.)
  • 🔍 Comparison operations (isBefore, isAfter, isSame, etc.)
  • 🌎 Timezone conversion with tz() method
  • 📆 Date range operations with startOf/endOf methods
  • 🧮 Date difference calculations with multiple granularity options
  • 🔄 Method chaining for complex date operations
  • ✅ Extensive test suite covering all features

Usage Examples

Creating Dates

// Current date and time
d()

// Parse from string (multiple formats supported)
d('2023-10-15')
d('2023-10-15 14:30')
d('2023-10-15 14:30:45')

// With specific timezone
d('2023-10-15', 'Europe/Berlin')

Date Manipulation

// Add time durations
d('2023-10-15').add('1d')       // Add 1 day
d('2023-10-15').add('1d 5h')    // Add 1 day and 5 hours
d('2023-10-15').add(1, 'd')     // Add 1 day (alternative syntax)

// Subtract time durations
d('2023-10-15').sub('2d')       // Subtract 2 days
d('2023-10-15').sub(1, 'M')     // Subtract 1 month

// Set specific components
d('2023-10-15').set(2024, 'year')  // Change year to 2024
d('2023-10-15').set(5, 'month')    // Change month to May

Date Comparisons

d('2023-10-15').isBefore(d('2023-10-16'))       // true
d('2023-10-15').isAfter(d('2023-10-14'))        // true
d('2023-10-15').isSame(d('2023-10-15'))         // true
d('2023-10-15').isSameOrBefore(d('2023-10-15')) // true
d('2023-10-15').isSameOrAfter(d('2023-10-15'))  // true

Date Information

d('2023-10-15').year()      // 2023
d('2023-10-15').month()     // 10
d('2023-10-15').day()       // 15
d('2023-10-15').weekday()   // 7 (Sunday)
d('2023-10-15').quarter()   // 4
d('2023-10-15').isLeapYear() // false

Start/End of Period

d('2023-10-15T14:30:45Z').startOf('day')   // 2023-10-15T00:00:00Z
d('2023-10-15T14:30:45Z').endOf('day')     // 2023-10-15T23:59:59Z
d('2023-10-15').startOf('month')           // 2023-10-01T00:00:00Z
d('2023-10-15').endOf('month')             // 2023-10-31T23:59:59Z

Formatting

d('2023-10-15').format('%Y-%m-%d')                          // 2023-10-15
d('2023-10-15T14:30:45Z').format('%A, %B %d %Y, %H:%M:%S')  // Sunday, October 15 2023, 14:30:45

Timezone Operations

d('2023-10-15T00:00:00Z').tz('America/New_York')  // 2023-10-14T20:00:00-04:00
d('2023-10-15T00:00:00Z').tz('Europe/London')     // 2023-10-15T01:00:00+01:00

Technical Implementation

  • Replaced the old date literal system with a new dynamic variable implementation (old date system is still available, but deprecated)
  • Added new DynamicVariable trait to support extensible type system
  • Implemented duration parsing with support for complex time expressions
  • Created comprehensive date method registry with method chaining
  • Added timezone support using chrono-tz
  • Integrated with existing VM infrastructure for seamless operation
  • Designed all date methods to return new instances, preserving immutability

@stefan-gorules stefan-gorules merged commit de6d13e into master May 12, 2025
43 checks passed
@stefan-gorules stefan-gorules deleted the feat/date-v2 branch May 12, 2025 20:39
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.

2 participants