Skip to content

Commit

Permalink
add DateTime module (#3296)
Browse files Browse the repository at this point in the history
Co-authored-by: Tim Smart <tim.smart@arisechurch.com>
  • Loading branch information
tim-smart and Tim Smart committed Jul 30, 2024
1 parent fd965db commit 22608f8
Show file tree
Hide file tree
Showing 7 changed files with 2,801 additions and 0 deletions.
34 changes: 34 additions & 0 deletions .changeset/clean-trainers-tap.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
---
"effect": minor
---

add DateTime module

The `DateTime` module provides functionality for working with time, including
support for time zones and daylight saving time.

It has two main data types: `DateTime.Utc` and `DateTime.Zoned`.

A `DateTime.Utc` represents a time in Coordinated Universal Time (UTC), and
a `DateTime.Zoned` contains both a UTC timestamp and a time zone.

There is also a `CurrentTimeZone` service, for setting a time zone contextually.

```ts
import { DateTime, Effect } from "effect";

Effect.gen(function* () {
// Get the current time in the current time zone
const now = yield* DateTime.nowInCurrentZone;

// Math functions are included
const tomorrow = DateTime.add(now, 1, "day");

// Convert to a different time zone
// The UTC portion of the `DateTime` is preserved and only the time zone is
// changed
const sydneyTime = tomorrow.pipe(
DateTime.unsafeSetZoneNamed("Australia/Sydney"),
);
}).pipe(DateTime.withCurrentZoneNamed("America/New_York"));
```
5 changes: 5 additions & 0 deletions .changeset/red-bottles-cough.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@effect/schema": patch
---

add schemas for working with the DateTime module
Loading

0 comments on commit 22608f8

Please sign in to comment.