Fluent chainable API for date operations

Import

import { ... } from 'ts-time-utils/chain';

Examples

Fluent Chain API

Chain multiple operations together

import { chain } from 'ts-time-utils/chain';

// Chain multiple operations
const result = chain(new Date())
  .startOf('day')
  .add(9, 'hours')
  .add(30, 'minutes')
  .toDate();

console.log('Today at 9:30am:', result);

// Complex chaining
const nextMeeting = chain(new Date())
  .add(1, 'week')
  .startOf('week')  // Monday
  .add(1, 'day')    // Tuesday
  .add(14, 'hours') // 2pm
  .toDate();

console.log('Next Tuesday 2pm:', nextMeeting);

// Get formatted output
const formatted = chain(new Date())
  .add(3, 'days')
  .format('YYYY-MM-DD');

console.log('3 days from now:', formatted);

// Check conditions in chain
const isWeekend = chain(new Date())
  .add(2, 'days')
  .isWeekend();

console.log('Is 2 days from now a weekend?', isWeekend);