> For the complete documentation index, see [llms.txt](https://docs.nestjstools.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.nestjstools.com/clock/getting-started/calendar-value-object.md).

# Calendar value object

## 📅 CalendarDate Value Object

`CalendarDate` is an immutable date-only value object.

It represents a calendar date **without time and timezone**.

Perfect for:

* Birthdays
* Subscription periods
* Business deadlines
* Billing cycles
* Domain rules where time is irrelevant

***

### Features

* Immutable YYYY-MM-DD representation
* Creation from string or native Date
* Validation of invalid dates
* Safe add/subtract days
* Comparison helpers
* Conversion to native Date (00:00:00 time)

***

### Usage

```
import { CalendarDate } from '@nestjstools/clock';

// Create from string
const date1 = CalendarDate.fromString('2025-06-14');

// Create from native Date
const date2 = CalendarDate.fromDate(new Date());

// Get today
const today = CalendarDate.today();

// Manipulation
const nextWeek = today.addDays(7);
const yesterday = today.subtractDays(1);

// Comparison
if (date1.isBefore(nextWeek)) {
  console.log(`${date1.toString()} is before ${nextWeek.toString()}`);
}

// Convert to native Date
const nativeDate = date1.toDate();
```

***

## 🏗 Example: Using CalendarDate with IClock

```
import { Injectable } from '@nestjs/common';
import { IClock, Clock } from '@nestjstools/clock';

@Injectable()
export class ReturnToday {
  constructor(@Clock() private readonly clock: IClock) {}

  todayIs(): string {
    const today = this.clock.today();
    return today.toString(); // YYYY-MM-DD
  }
}
```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.nestjstools.com/clock/getting-started/calendar-value-object.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
