Skip to content

DateTime

Working with dates and times in JavaScript can be challenging. The built-in Date object mutates its internal state, and time zone handling can be confusing. These design choices can lead to errors when working on applications that rely on date-time accuracy, such as scheduling systems, timestamping services, or logging utilities.

The DateTime module aims to address these limitations by offering:

  • Immutable Data: Each DateTime is an immutable structure, reducing mistakes related to in-place mutations.
  • Time Zone Support: DateTime provides robust support for time zones, including automatic daylight saving time adjustments.
  • Arithmetic Operations: You can perform arithmetic operations on DateTime instances, such as adding or subtracting durations.

A DateTime represents a moment in time. It can be stored as either a simple UTC value or as a value with an associated time zone. Storing time this way helps you manage both precise timestamps and the context for how that time should be displayed or interpreted.

There are two main variants of DateTime:

  1. Utc: An immutable structure that uses epochMillis (milliseconds since the Unix epoch) to represent a point in time in Coordinated Universal Time (UTC).

  2. Zoned: Includes epochMillis along with a TimeZone, allowing you to attach an offset or a named region (like “America/New_York”) to the timestamp.

  • Utc is straightforward if you only need a universal reference without relying on local time zones.
  • Zoned is helpful when you need to keep track of time zone information for tasks such as converting to local times or adjusting for daylight saving time.

A TimeZone can be either:

  • Offset: Represents a fixed offset from UTC (for example, UTC+2 or UTC-5).
  • Named: Uses a named region (e.g., “Europe/London” or “America/New_York”) that automatically accounts for region-specific rules like daylight saving time changes.

Below is the TypeScript definition for the DateTime type:

type DateTime = Utc | Zoned
interface Utc {
readonly _tag: "Utc"
readonly epochMillis: number
}
interface Zoned {
readonly _tag: "Zoned"
readonly epochMillis: number
readonly zone: TimeZone
}
type TimeZone = TimeZone.Offset | TimeZone.Named
declare namespace TimeZone {
interface Offset {
readonly _tag: "Offset"
readonly offset: number
}
interface Named {
readonly _tag: "Named"
readonly id: string
}
}

The DateTime.Parts type defines the main components of a date, such as the year, month, day, hours, minutes, and seconds.

namespace DateTime {
interface Parts {
readonly millis: number
readonly seconds: number
readonly minutes: number
readonly hours: number
readonly day: number
readonly month: number
readonly year: number
}
interface PartsWithWeekday extends Parts {
readonly weekDay: number
}
}

The DateTime.Input type is a flexible input type that can be used to create a DateTime instance. It can be one of the following:

  • A DateTime instance
  • A JavaScript Date object
  • A numeric value representing milliseconds since the Unix epoch
  • An object with partial date parts (e.g., { year: 2024, month: 1, day: 1 })
  • A string that can be parsed by JavaScript’s Date.parse
namespace DateTime {
type Input = DateTime | Partial<Parts> | Date | number | string
}

Utc is an immutable structure that uses epochMillis (milliseconds since the Unix epoch) to represent a point in time in Coordinated Universal Time (UTC).

Creates a Utc from a JavaScript Date. Throws an IllegalArgumentException if the provided Date is invalid.

When a Date object is passed, it is converted to a Utc instance. The time is interpreted as the local time of the system executing the code and then adjusted to UTC. This ensures a consistent, timezone-independent representation of the date and time.

Example (Converting Local Time to UTC in Italy)

The following example assumes the code is executed on a system in Italy (CET timezone):

import {
import DateTime
DateTime
} from "effect"
// Create a Utc instance from a local JavaScript Date
//
// ┌─── Utc
// ▼
const
const utc: DateTime.Utc
utc
=
import DateTime
DateTime
.
const unsafeFromDate: (date: Date) => DateTime.Utc

Create a DateTime from a Date.

If the Date is invalid, an IllegalArgumentException will be thrown.

@since3.6.0

unsafeFromDate
(new
var Date: DateConstructor
new (value: number | string | Date) => Date (+3 overloads)
Date
("2025-01-01 04:00:00"))
var console: Console

The console module provides a simple debugging console that is similar to the JavaScript console mechanism provided by web browsers.

The module exports two specific components:

  • A Console class with methods such as console.log(), console.error() and console.warn() that can be used to write to any Node.js stream.
  • A global console instance configured to write to process.stdout and process.stderr. The global console can be used without importing the node:console module.

Warning: The global console object's methods are neither consistently synchronous like the browser APIs they resemble, nor are they consistently asynchronous like all other Node.js streams. See the note on process I/O for more information.

Example using the global console:

console.log('hello world');
// Prints: hello world, to stdout
console.log('hello %s', 'world');
// Prints: hello world, to stdout
console.error(new Error('Whoops, something bad happened'));
// Prints error message and stack trace to stderr:
// Error: Whoops, something bad happened
// at [eval]:5:15
// at Script.runInThisContext (node:vm:132:18)
// at Object.runInThisContext (node:vm:309:38)
// at node:internal/process/execution:77:19
// at [eval]-wrapper:6:22
// at evalScript (node:internal/process/execution:76:60)
// at node:internal/main/eval_string:23:3
const name = 'Will Robinson';
console.warn(`Danger ${name}! Danger!`);
// Prints: Danger Will Robinson! Danger!, to stderr

Example using the Console class:

const out = getStreamSomehow();
const err = getStreamSomehow();
const myConsole = new console.Console(out, err);
myConsole.log('hello world');
// Prints: hello world, to out
myConsole.log('hello %s', 'world');
// Prints: hello world, to out
myConsole.error(new Error('Whoops, something bad happened'));
// Prints: [Error: Whoops, something bad happened], to err
const name = 'Will Robinson';
myConsole.warn(`Danger ${name}! Danger!`);
// Prints: Danger Will Robinson! Danger!, to err

@seesource

console
.
Console.log(message?: any, ...optionalParams: any[]): void

Prints to stdout with newline. Multiple arguments can be passed, with the first used as the primary message and all additional used as substitution values similar to printf(3) (the arguments are all passed to util.format()).

const count = 5;
console.log('count: %d', count);
// Prints: count: 5, to stdout
console.log('count:', count);
// Prints: count: 5, to stdout

See util.format() for more information.

@sincev0.1.100

log
(
const utc: DateTime.Utc
utc
)
// Output: DateTime.Utc(2025-01-01T03:00:00.000Z)
var console: Console

The console module provides a simple debugging console that is similar to the JavaScript console mechanism provided by web browsers.

The module exports two specific components:

  • A Console class with methods such as console.log(), console.error() and console.warn() that can be used to write to any Node.js stream.
  • A global console instance configured to write to process.stdout and process.stderr. The global console can be used without importing the node:console module.

Warning: The global console object's methods are neither consistently synchronous like the browser APIs they resemble, nor are they consistently asynchronous like all other Node.js streams. See the note on process I/O for more information.

Example using the global console:

console.log('hello world');
// Prints: hello world, to stdout
console.log('hello %s', 'world');
// Prints: hello world, to stdout
console.error(new Error('Whoops, something bad happened'));
// Prints error message and stack trace to stderr:
// Error: Whoops, something bad happened
// at [eval]:5:15
// at Script.runInThisContext (node:vm:132:18)
// at Object.runInThisContext (node:vm:309:38)
// at node:internal/process/execution:77:19
// at [eval]-wrapper:6:22
// at evalScript (node:internal/process/execution:76:60)
// at node:internal/main/eval_string:23:3
const name = 'Will Robinson';
console.warn(`Danger ${name}! Danger!`);
// Prints: Danger Will Robinson! Danger!, to stderr

Example using the Console class:

const out = getStreamSomehow();
const err = getStreamSomehow();
const myConsole = new console.Console(out, err);
myConsole.log('hello world');
// Prints: hello world, to out
myConsole.log('hello %s', 'world');
// Prints: hello world, to out
myConsole.error(new Error('Whoops, something bad happened'));
// Prints: [Error: Whoops, something bad happened], to err
const name = 'Will Robinson';
myConsole.warn(`Danger ${name}! Danger!`);
// Prints: Danger Will Robinson! Danger!, to err

@seesource

console
.
Console.log(message?: any, ...optionalParams: any[]): void

Prints to stdout with newline. Multiple arguments can be passed, with the first used as the primary message and all additional used as substitution values similar to printf(3) (the arguments are all passed to util.format()).

const count = 5;
console.log('count: %d', count);
// Prints: count: 5, to stdout
console.log('count:', count);
// Prints: count: 5, to stdout

See util.format() for more information.

@sincev0.1.100

log
(
const utc: DateTime.Utc
utc
.
Utc.epochMillis: number
epochMillis
)
// Output: 1735700400000

Explanation:

  • The local time 2025-01-01 04:00:00 (in Italy, CET) is converted to UTC by subtracting the timezone offset (UTC+1 in January).
  • As a result, the UTC time becomes 2025-01-01 03:00:00.000Z.
  • epochMillis provides the same time as milliseconds since the Unix Epoch, ensuring a precise numeric representation of the UTC timestamp.

Creates a Utc from a DateTime.Input.

Example (Creating a DateTime with unsafeMake)

The following example assumes the code is executed on a system in Italy (CET timezone):

import {
import DateTime
DateTime
} from "effect"
// From a JavaScript Date
const
const utc1: DateTime.Utc
utc1
=
import DateTime
DateTime
.
const unsafeMake: <Date>(input: Date) => DateTime.Utc

Create a DateTime from one of the following:

  • A DateTime
  • A Date instance (invalid dates will throw an IllegalArgumentException)
  • The number of milliseconds since the Unix epoch
  • An object with the parts of a date
  • A string that can be parsed by Date.parse

@since3.6.0

@example

import { DateTime } from "effect"
// from Date
DateTime.unsafeMake(new Date())
// from parts
DateTime.unsafeMake({ year: 2024 })
// from string
DateTime.unsafeMake("2024-01-01")

unsafeMake
(new
var Date: DateConstructor
new (value: number | string | Date) => Date (+3 overloads)
Date
("2025-01-01 04:00:00"))
var console: Console

The console module provides a simple debugging console that is similar to the JavaScript console mechanism provided by web browsers.

The module exports two specific components:

  • A Console class with methods such as console.log(), console.error() and console.warn() that can be used to write to any Node.js stream.
  • A global console instance configured to write to process.stdout and process.stderr. The global console can be used without importing the node:console module.

Warning: The global console object's methods are neither consistently synchronous like the browser APIs they resemble, nor are they consistently asynchronous like all other Node.js streams. See the note on process I/O for more information.

Example using the global console:

console.log('hello world');
// Prints: hello world, to stdout
console.log('hello %s', 'world');
// Prints: hello world, to stdout
console.error(new Error('Whoops, something bad happened'));
// Prints error message and stack trace to stderr:
// Error: Whoops, something bad happened
// at [eval]:5:15
// at Script.runInThisContext (node:vm:132:18)
// at Object.runInThisContext (node:vm:309:38)
// at node:internal/process/execution:77:19
// at [eval]-wrapper:6:22
// at evalScript (node:internal/process/execution:76:60)
// at node:internal/main/eval_string:23:3
const name = 'Will Robinson';
console.warn(`Danger ${name}! Danger!`);
// Prints: Danger Will Robinson! Danger!, to stderr

Example using the Console class:

const out = getStreamSomehow();
const err = getStreamSomehow();
const myConsole = new console.Console(out, err);
myConsole.log('hello world');
// Prints: hello world, to out
myConsole.log('hello %s', 'world');
// Prints: hello world, to out
myConsole.error(new Error('Whoops, something bad happened'));
// Prints: [Error: Whoops, something bad happened], to err
const name = 'Will Robinson';
myConsole.warn(`Danger ${name}! Danger!`);
// Prints: Danger Will Robinson! Danger!, to err

@seesource

console
.
Console.log(message?: any, ...optionalParams: any[]): void

Prints to stdout with newline. Multiple arguments can be passed, with the first used as the primary message and all additional used as substitution values similar to printf(3) (the arguments are all passed to util.format()).

const count = 5;
console.log('count: %d', count);
// Prints: count: 5, to stdout
console.log('count:', count);
// Prints: count: 5, to stdout

See util.format() for more information.

@sincev0.1.100

log
(
const utc1: DateTime.Utc
utc1
)
// Output: DateTime.Utc(2025-01-01T03:00:00.000Z)
// From partial date parts
const
const utc2: DateTime.Utc
utc2
=
import DateTime
DateTime
.
const unsafeMake: <{
year: number;
}>(input: {
year: number;
}) => DateTime.Utc

Create a DateTime from one of the following:

  • A DateTime
  • A Date instance (invalid dates will throw an IllegalArgumentException)
  • The number of milliseconds since the Unix epoch
  • An object with the parts of a date
  • A string that can be parsed by Date.parse

@since3.6.0

@example

import { DateTime } from "effect"
// from Date
DateTime.unsafeMake(new Date())
// from parts
DateTime.unsafeMake({ year: 2024 })
// from string
DateTime.unsafeMake("2024-01-01")

unsafeMake
({
year: number
year
: 2025 })
var console: Console

The console module provides a simple debugging console that is similar to the JavaScript console mechanism provided by web browsers.

The module exports two specific components:

  • A Console class with methods such as console.log(), console.error() and console.warn() that can be used to write to any Node.js stream.
  • A global console instance configured to write to process.stdout and process.stderr. The global console can be used without importing the node:console module.

Warning: The global console object's methods are neither consistently synchronous like the browser APIs they resemble, nor are they consistently asynchronous like all other Node.js streams. See the note on process I/O for more information.

Example using the global console:

console.log('hello world');
// Prints: hello world, to stdout
console.log('hello %s', 'world');
// Prints: hello world, to stdout
console.error(new Error('Whoops, something bad happened'));
// Prints error message and stack trace to stderr:
// Error: Whoops, something bad happened
// at [eval]:5:15
// at Script.runInThisContext (node:vm:132:18)
// at Object.runInThisContext (node:vm:309:38)
// at node:internal/process/execution:77:19
// at [eval]-wrapper:6:22
// at evalScript (node:internal/process/execution:76:60)
// at node:internal/main/eval_string:23:3
const name = 'Will Robinson';
console.warn(`Danger ${name}! Danger!`);
// Prints: Danger Will Robinson! Danger!, to stderr

Example using the Console class:

const out = getStreamSomehow();
const err = getStreamSomehow();
const myConsole = new console.Console(out, err);
myConsole.log('hello world');
// Prints: hello world, to out
myConsole.log('hello %s', 'world');
// Prints: hello world, to out
myConsole.error(new Error('Whoops, something bad happened'));
// Prints: [Error: Whoops, something bad happened], to err
const name = 'Will Robinson';
myConsole.warn(`Danger ${name}! Danger!`);
// Prints: Danger Will Robinson! Danger!, to err

@seesource

console
.
Console.log(message?: any, ...optionalParams: any[]): void

Prints to stdout with newline. Multiple arguments can be passed, with the first used as the primary message and all additional used as substitution values similar to printf(3) (the arguments are all passed to util.format()).

const count = 5;
console.log('count: %d', count);
// Prints: count: 5, to stdout
console.log('count:', count);
// Prints: count: 5, to stdout

See util.format() for more information.

@sincev0.1.100

log
(
const utc2: DateTime.Utc
utc2
)
// Output: DateTime.Utc(2025-01-01T00:00:00.000Z)
// From a string
const
const utc3: DateTime.Utc
utc3
=
import DateTime
DateTime
.
const unsafeMake: <"2025-01-01">(input: "2025-01-01") => DateTime.Utc

Create a DateTime from one of the following:

  • A DateTime
  • A Date instance (invalid dates will throw an IllegalArgumentException)
  • The number of milliseconds since the Unix epoch
  • An object with the parts of a date
  • A string that can be parsed by Date.parse

@since3.6.0

@example

import { DateTime } from "effect"
// from Date
DateTime.unsafeMake(new Date())
// from parts
DateTime.unsafeMake({ year: 2024 })
// from string
DateTime.unsafeMake("2024-01-01")

unsafeMake
("2025-01-01")
var console: Console

The console module provides a simple debugging console that is similar to the JavaScript console mechanism provided by web browsers.

The module exports two specific components:

  • A Console class with methods such as console.log(), console.error() and console.warn() that can be used to write to any Node.js stream.
  • A global console instance configured to write to process.stdout and process.stderr. The global console can be used without importing the node:console module.

Warning: The global console object's methods are neither consistently synchronous like the browser APIs they resemble, nor are they consistently asynchronous like all other Node.js streams. See the note on process I/O for more information.

Example using the global console:

console.log('hello world');
// Prints: hello world, to stdout
console.log('hello %s', 'world');
// Prints: hello world, to stdout
console.error(new Error('Whoops, something bad happened'));
// Prints error message and stack trace to stderr:
// Error: Whoops, something bad happened
// at [eval]:5:15
// at Script.runInThisContext (node:vm:132:18)
// at Object.runInThisContext (node:vm:309:38)
// at node:internal/process/execution:77:19
// at [eval]-wrapper:6:22
// at evalScript (node:internal/process/execution:76:60)
// at node:internal/main/eval_string:23:3
const name = 'Will Robinson';
console.warn(`Danger ${name}! Danger!`);
// Prints: Danger Will Robinson! Danger!, to stderr

Example using the Console class:

const out = getStreamSomehow();
const err = getStreamSomehow();
const myConsole = new console.Console(out, err);
myConsole.log('hello world');
// Prints: hello world, to out
myConsole.log('hello %s', 'world');
// Prints: hello world, to out
myConsole.error(new Error('Whoops, something bad happened'));
// Prints: [Error: Whoops, something bad happened], to err
const name = 'Will Robinson';
myConsole.warn(`Danger ${name}! Danger!`);
// Prints: Danger Will Robinson! Danger!, to err

@seesource

console
.
Console.log(message?: any, ...optionalParams: any[]): void

Prints to stdout with newline. Multiple arguments can be passed, with the first used as the primary message and all additional used as substitution values similar to printf(3) (the arguments are all passed to util.format()).

const count = 5;
console.log('count: %d', count);
// Prints: count: 5, to stdout
console.log('count:', count);
// Prints: count: 5, to stdout

See util.format() for more information.

@sincev0.1.100

log
(
const utc3: DateTime.Utc
utc3
)
// Output: DateTime.Utc(2025-01-01T00:00:00.000Z)

Explanation:

  • The local time 2025-01-01 04:00:00 (in Italy, CET) is converted to UTC by subtracting the timezone offset (UTC+1 in January).
  • As a result, the UTC time becomes 2025-01-01 03:00:00.000Z.

Similar to unsafeMake, but returns an Option instead of throwing an error if the input is invalid. If the input is invalid, it returns None. If valid, it returns Some containing the Utc.

Example (Creating a DateTime Safely)

The following example assumes the code is executed on a system in Italy (CET timezone):

import {
import DateTime
DateTime
} from "effect"
// From a JavaScript Date
const
const maybeUtc1: Option<DateTime.Utc>
maybeUtc1
=
import DateTime
DateTime
.
const make: <Date>(input: Date) => Option<DateTime.Utc>

Create a DateTime from one of the following:

  • A DateTime
  • A Date instance (invalid dates will throw an IllegalArgumentException)
  • The number of milliseconds since the Unix epoch
  • An object with the parts of a date
  • A string that can be parsed by Date.parse

If the input is invalid, None will be returned.

@since3.6.0

@example

import { DateTime } from "effect"
// from Date
DateTime.make(new Date())
// from parts
DateTime.make({ year: 2024 })
// from string
DateTime.make("2024-01-01")

make
(new
var Date: DateConstructor
new (value: number | string | Date) => Date (+3 overloads)
Date
("2025-01-01 04:00:00"))
var console: Console

The console module provides a simple debugging console that is similar to the JavaScript console mechanism provided by web browsers.

The module exports two specific components:

  • A Console class with methods such as console.log(), console.error() and console.warn() that can be used to write to any Node.js stream.
  • A global console instance configured to write to process.stdout and process.stderr. The global console can be used without importing the node:console module.

Warning: The global console object's methods are neither consistently synchronous like the browser APIs they resemble, nor are they consistently asynchronous like all other Node.js streams. See the note on process I/O for more information.

Example using the global console:

console.log('hello world');
// Prints: hello world, to stdout
console.log('hello %s', 'world');
// Prints: hello world, to stdout
console.error(new Error('Whoops, something bad happened'));
// Prints error message and stack trace to stderr:
// Error: Whoops, something bad happened
// at [eval]:5:15
// at Script.runInThisContext (node:vm:132:18)
// at Object.runInThisContext (node:vm:309:38)
// at node:internal/process/execution:77:19
// at [eval]-wrapper:6:22
// at evalScript (node:internal/process/execution:76:60)
// at node:internal/main/eval_string:23:3
const name = 'Will Robinson';
console.warn(`Danger ${name}! Danger!`);
// Prints: Danger Will Robinson! Danger!, to stderr

Example using the Console class:

const out = getStreamSomehow();
const err = getStreamSomehow();
const myConsole = new console.Console(out, err);
myConsole.log('hello world');
// Prints: hello world, to out
myConsole.log('hello %s', 'world');
// Prints: hello world, to out
myConsole.error(new Error('Whoops, something bad happened'));
// Prints: [Error: Whoops, something bad happened], to err
const name = 'Will Robinson';
myConsole.warn(`Danger ${name}! Danger!`);
// Prints: Danger Will Robinson! Danger!, to err

@seesource

console
.
Console.log(message?: any, ...optionalParams: any[]): void

Prints to stdout with newline. Multiple arguments can be passed, with the first used as the primary message and all additional used as substitution values similar to printf(3) (the arguments are all passed to util.format()).

const count = 5;
console.log('count: %d', count);
// Prints: count: 5, to stdout
console.log('count:', count);
// Prints: count: 5, to stdout

See util.format() for more information.

@sincev0.1.100

log
(
const maybeUtc1: Option<DateTime.Utc>
maybeUtc1
)
/*
Output:
{ _id: 'Option', _tag: 'Some', value: '2025-01-01T03:00:00.000Z' }
*/
// From partial date parts
const
const maybeUtc2: Option<DateTime.Utc>
maybeUtc2
=
import DateTime
DateTime
.
const make: <{
year: number;
}>(input: {
year: number;
}) => Option<DateTime.Utc>

Create a DateTime from one of the following:

  • A DateTime
  • A Date instance (invalid dates will throw an IllegalArgumentException)
  • The number of milliseconds since the Unix epoch
  • An object with the parts of a date
  • A string that can be parsed by Date.parse

If the input is invalid, None will be returned.

@since3.6.0

@example

import { DateTime } from "effect"
// from Date
DateTime.make(new Date())
// from parts
DateTime.make({ year: 2024 })
// from string
DateTime.make("2024-01-01")

make
({
year: number
year
: 2025 })
var console: Console

The console module provides a simple debugging console that is similar to the JavaScript console mechanism provided by web browsers.

The module exports two specific components:

  • A Console class with methods such as console.log(), console.error() and console.warn() that can be used to write to any Node.js stream.
  • A global console instance configured to write to process.stdout and process.stderr. The global console can be used without importing the node:console module.

Warning: The global console object's methods are neither consistently synchronous like the browser APIs they resemble, nor are they consistently asynchronous like all other Node.js streams. See the note on process I/O for more information.

Example using the global console:

console.log('hello world');
// Prints: hello world, to stdout
console.log('hello %s', 'world');
// Prints: hello world, to stdout
console.error(new Error('Whoops, something bad happened'));
// Prints error message and stack trace to stderr:
// Error: Whoops, something bad happened
// at [eval]:5:15
// at Script.runInThisContext (node:vm:132:18)
// at Object.runInThisContext (node:vm:309:38)
// at node:internal/process/execution:77:19
// at [eval]-wrapper:6:22
// at evalScript (node:internal/process/execution:76:60)
// at node:internal/main/eval_string:23:3
const name = 'Will Robinson';
console.warn(`Danger ${name}! Danger!`);
// Prints: Danger Will Robinson! Danger!, to stderr

Example using the Console class:

const out = getStreamSomehow();
const err = getStreamSomehow();
const myConsole = new console.Console(out, err);
myConsole.log('hello world');
// Prints: hello world, to out
myConsole.log('hello %s', 'world');
// Prints: hello world, to out
myConsole.error(new Error('Whoops, something bad happened'));
// Prints: [Error: Whoops, something bad happened], to err
const name = 'Will Robinson';
myConsole.warn(`Danger ${name}! Danger!`);
// Prints: Danger Will Robinson! Danger!, to err

@seesource

console
.
Console.log(message?: any, ...optionalParams: any[]): void

Prints to stdout with newline. Multiple arguments can be passed, with the first used as the primary message and all additional used as substitution values similar to printf(3) (the arguments are all passed to util.format()).

const count = 5;
console.log('count: %d', count);
// Prints: count: 5, to stdout
console.log('count:', count);
// Prints: count: 5, to stdout

See util.format() for more information.

@sincev0.1.100

log
(
const maybeUtc2: Option<DateTime.Utc>
maybeUtc2
)
/*
Output:
{ _id: 'Option', _tag: 'Some', value: '2025-01-01T00:00:00.000Z' }
*/
// From a string
const
const maybeUtc3: Option<DateTime.Utc>
maybeUtc3
=
import DateTime
DateTime
.
const make: <"2025-01-01">(input: "2025-01-01") => Option<DateTime.Utc>

Create a DateTime from one of the following:

  • A DateTime
  • A Date instance (invalid dates will throw an IllegalArgumentException)
  • The number of milliseconds since the Unix epoch
  • An object with the parts of a date
  • A string that can be parsed by Date.parse

If the input is invalid, None will be returned.

@since3.6.0

@example

import { DateTime } from "effect"
// from Date
DateTime.make(new Date())
// from parts
DateTime.make({ year: 2024 })
// from string
DateTime.make("2024-01-01")

make
("2025-01-01")
var console: Console

The console module provides a simple debugging console that is similar to the JavaScript console mechanism provided by web browsers.

The module exports two specific components:

  • A Console class with methods such as console.log(), console.error() and console.warn() that can be used to write to any Node.js stream.
  • A global console instance configured to write to process.stdout and process.stderr. The global console can be used without importing the node:console module.

Warning: The global console object's methods are neither consistently synchronous like the browser APIs they resemble, nor are they consistently asynchronous like all other Node.js streams. See the note on process I/O for more information.

Example using the global console:

console.log('hello world');
// Prints: hello world, to stdout
console.log('hello %s', 'world');
// Prints: hello world, to stdout
console.error(new Error('Whoops, something bad happened'));
// Prints error message and stack trace to stderr:
// Error: Whoops, something bad happened
// at [eval]:5:15
// at Script.runInThisContext (node:vm:132:18)
// at Object.runInThisContext (node:vm:309:38)
// at node:internal/process/execution:77:19
// at [eval]-wrapper:6:22
// at evalScript (node:internal/process/execution:76:60)
// at node:internal/main/eval_string:23:3
const name = 'Will Robinson';
console.warn(`Danger ${name}! Danger!`);
// Prints: Danger Will Robinson! Danger!, to stderr

Example using the Console class:

const out = getStreamSomehow();
const err = getStreamSomehow();
const myConsole = new console.Console(out, err);
myConsole.log('hello world');
// Prints: hello world, to out
myConsole.log('hello %s', 'world');
// Prints: hello world, to out
myConsole.error(new Error('Whoops, something bad happened'));
// Prints: [Error: Whoops, something bad happened], to err
const name = 'Will Robinson';
myConsole.warn(`Danger ${name}! Danger!`);
// Prints: Danger Will Robinson! Danger!, to err

@seesource

console
.
Console.log(message?: any, ...optionalParams: any[]): void

Prints to stdout with newline. Multiple arguments can be passed, with the first used as the primary message and all additional used as substitution values similar to printf(3) (the arguments are all passed to util.format()).

const count = 5;
console.log('count: %d', count);
// Prints: count: 5, to stdout
console.log('count:', count);
// Prints: count: 5, to stdout

See util.format() for more information.

@sincev0.1.100

log
(
const maybeUtc3: Option<DateTime.Utc>
maybeUtc3
)
/*
Output:
{ _id: 'Option', _tag: 'Some', value: '2025-01-01T00:00:00.000Z' }
*/

Explanation:

  • The local time 2025-01-01 04:00:00 (in Italy, CET) is converted to UTC by subtracting the timezone offset (UTC+1 in January).
  • As a result, the UTC time becomes 2025-01-01 03:00:00.000Z.

A Zoned includes epochMillis along with a TimeZone, allowing you to attach an offset or a named region (like “America/New_York”) to the timestamp.

Creates a Zoned by combining a DateTime.Input with an optional TimeZone. This allows you to represent a specific point in time with an associated time zone.

The time zone can be provided in several ways:

  • As a TimeZone object
  • A string identifier (e.g., "Europe/London")
  • A numeric offset in milliseconds

If the input or time zone is invalid, an IllegalArgumentException is thrown.

Example (Creating a Zoned DateTime Without Specifying a Time Zone)

The following example assumes the code is executed on a system in Italy (CET timezone):

import {
import DateTime
DateTime
} from "effect"
// Create a Zoned DateTime based on the system's local time zone
const
const zoned: DateTime.Zoned
zoned
=
import DateTime
DateTime
.
const unsafeMakeZoned: (input: DateTime.DateTime.Input, options?: {
readonly timeZone?: number | string | DateTime.TimeZone | undefined;
readonly adjustForTimeZone?: boolean | undefined;
}) => DateTime.Zoned

Create a DateTime.Zoned using DateTime.unsafeMake and a time zone.

The input is treated as UTC and then the time zone is attached, unless adjustForTimeZone is set to true. In that case, the input is treated as already in the time zone.

@since3.6.0

@example

import { DateTime } from "effect"
DateTime.unsafeMakeZoned(new Date(), { timeZone: "Europe/London" })

unsafeMakeZoned
(new
var Date: DateConstructor
new (value: number | string | Date) => Date (+3 overloads)
Date
("2025-01-01 04:00:00"))
var console: Console

The console module provides a simple debugging console that is similar to the JavaScript console mechanism provided by web browsers.

The module exports two specific components:

  • A Console class with methods such as console.log(), console.error() and console.warn() that can be used to write to any Node.js stream.
  • A global console instance configured to write to process.stdout and process.stderr. The global console can be used without importing the node:console module.

Warning: The global console object's methods are neither consistently synchronous like the browser APIs they resemble, nor are they consistently asynchronous like all other Node.js streams. See the note on process I/O for more information.

Example using the global console:

console.log('hello world');
// Prints: hello world, to stdout
console.log('hello %s', 'world');
// Prints: hello world, to stdout
console.error(new Error('Whoops, something bad happened'));
// Prints error message and stack trace to stderr:
// Error: Whoops, something bad happened
// at [eval]:5:15
// at Script.runInThisContext (node:vm:132:18)
// at Object.runInThisContext (node:vm:309:38)
// at node:internal/process/execution:77:19
// at [eval]-wrapper:6:22
// at evalScript (node:internal/process/execution:76:60)
// at node:internal/main/eval_string:23:3
const name = 'Will Robinson';
console.warn(`Danger ${name}! Danger!`);
// Prints: Danger Will Robinson! Danger!, to stderr

Example using the Console class:

const out = getStreamSomehow();
const err = getStreamSomehow();
const myConsole = new console.Console(out, err);
myConsole.log('hello world');
// Prints: hello world, to out
myConsole.log('hello %s', 'world');
// Prints: hello world, to out
myConsole.error(new Error('Whoops, something bad happened'));
// Prints: [Error: Whoops, something bad happened], to err
const name = 'Will Robinson';
myConsole.warn(`Danger ${name}! Danger!`);
// Prints: Danger Will Robinson! Danger!, to err

@seesource

console
.
Console.log(message?: any, ...optionalParams: any[]): void

Prints to stdout with newline. Multiple arguments can be passed, with the first used as the primary message and all additional used as substitution values similar to printf(3) (the arguments are all passed to util.format()).

const count = 5;
console.log('count: %d', count);
// Prints: count: 5, to stdout
console.log('count:', count);
// Prints: count: 5, to stdout

See util.format() for more information.

@sincev0.1.100

log
(
const zoned: DateTime.Zoned
zoned
)
// Output: DateTime.Zoned(2025-01-01T04:00:00.000+01:00)
var console: Console

The console module provides a simple debugging console that is similar to the JavaScript console mechanism provided by web browsers.

The module exports two specific components:

  • A Console class with methods such as console.log(), console.error() and console.warn() that can be used to write to any Node.js stream.
  • A global console instance configured to write to process.stdout and process.stderr. The global console can be used without importing the node:console module.

Warning: The global console object's methods are neither consistently synchronous like the browser APIs they resemble, nor are they consistently asynchronous like all other Node.js streams. See the note on process I/O for more information.

Example using the global console:

console.log('hello world');
// Prints: hello world, to stdout
console.log('hello %s', 'world');
// Prints: hello world, to stdout
console.error(new Error('Whoops, something bad happened'));
// Prints error message and stack trace to stderr:
// Error: Whoops, something bad happened
// at [eval]:5:15
// at Script.runInThisContext (node:vm:132:18)
// at Object.runInThisContext (node:vm:309:38)
// at node:internal/process/execution:77:19
// at [eval]-wrapper:6:22
// at evalScript (node:internal/process/execution:76:60)
// at node:internal/main/eval_string:23:3
const name = 'Will Robinson';
console.warn(`Danger ${name}! Danger!`);
// Prints: Danger Will Robinson! Danger!, to stderr

Example using the Console class:

const out = getStreamSomehow();
const err = getStreamSomehow();
const myConsole = new console.Console(out, err);
myConsole.log('hello world');
// Prints: hello world, to out
myConsole.log('hello %s', 'world');
// Prints: hello world, to out
myConsole.error(new Error('Whoops, something bad happened'));
// Prints: [Error: Whoops, something bad happened], to err
const name = 'Will Robinson';
myConsole.warn(`Danger ${name}! Danger!`);
// Prints: Danger Will Robinson! Danger!, to err

@seesource

console
.
Console.log(message?: any, ...optionalParams: any[]): void

Prints to stdout with newline. Multiple arguments can be passed, with the first used as the primary message and all additional used as substitution values similar to printf(3) (the arguments are all passed to util.format()).

const count = 5;
console.log('count: %d', count);
// Prints: count: 5, to stdout
console.log('count:', count);
// Prints: count: 5, to stdout

See util.format() for more information.

@sincev0.1.100

log
(
const zoned: DateTime.Zoned
zoned
.
Zoned.zone: DateTime.TimeZone
zone
)
// Output: TimeZone.Offset(+01:00)

Here, the system’s time zone (CET, which is UTC+1 in January) is used to create the Zoned instance.

Example (Specifying a Named Time Zone)

The following example assumes the code is executed on a system in Italy (CET timezone):

import {
import DateTime
DateTime
} from "effect"
// Create a Zoned DateTime with a specified named time zone
const
const zoned: DateTime.Zoned
zoned
=
import DateTime
DateTime
.
const unsafeMakeZoned: (input: DateTime.DateTime.Input, options?: {
readonly timeZone?: number | string | DateTime.TimeZone | undefined;
readonly adjustForTimeZone?: boolean | undefined;
}) => DateTime.Zoned

Create a DateTime.Zoned using DateTime.unsafeMake and a time zone.

The input is treated as UTC and then the time zone is attached, unless adjustForTimeZone is set to true. In that case, the input is treated as already in the time zone.

@since3.6.0

@example

import { DateTime } from "effect"
DateTime.unsafeMakeZoned(new Date(), { timeZone: "Europe/London" })

unsafeMakeZoned
(new
var Date: DateConstructor
new (value: number | string | Date) => Date (+3 overloads)
Date
("2025-01-01 04:00:00"), {
timeZone?: string | number | DateTime.TimeZone | undefined
timeZone
: "Europe/Rome"
})
var console: Console

The console module provides a simple debugging console that is similar to the JavaScript console mechanism provided by web browsers.

The module exports two specific components:

  • A Console class with methods such as console.log(), console.error() and console.warn() that can be used to write to any Node.js stream.
  • A global console instance configured to write to process.stdout and process.stderr. The global console can be used without importing the node:console module.

Warning: The global console object's methods are neither consistently synchronous like the browser APIs they resemble, nor are they consistently asynchronous like all other Node.js streams. See the note on process I/O for more information.

Example using the global console:

console.log('hello world');
// Prints: hello world, to stdout
console.log('hello %s', 'world');
// Prints: hello world, to stdout
console.error(new Error('Whoops, something bad happened'));
// Prints error message and stack trace to stderr:
// Error: Whoops, something bad happened
// at [eval]:5:15
// at Script.runInThisContext (node:vm:132:18)
// at Object.runInThisContext (node:vm:309:38)
// at node:internal/process/execution:77:19
// at [eval]-wrapper:6:22
// at evalScript (node:internal/process/execution:76:60)
// at node:internal/main/eval_string:23:3
const name = 'Will Robinson';
console.warn(`Danger ${name}! Danger!`);
// Prints: Danger Will Robinson! Danger!, to stderr

Example using the Console class:

const out = getStreamSomehow();
const err = getStreamSomehow();
const myConsole = new console.Console(out, err);
myConsole.log('hello world');
// Prints: hello world, to out
myConsole.log('hello %s', 'world');
// Prints: hello world, to out
myConsole.error(new Error('Whoops, something bad happened'));
// Prints: [Error: Whoops, something bad happened], to err
const name = 'Will Robinson';
myConsole.warn(`Danger ${name}! Danger!`);
// Prints: Danger Will Robinson! Danger!, to err

@seesource

console
.
Console.log(message?: any, ...optionalParams: any[]): void

Prints to stdout with newline. Multiple arguments can be passed, with the first used as the primary message and all additional used as substitution values similar to printf(3) (the arguments are all passed to util.format()).

const count = 5;
console.log('count: %d', count);
// Prints: count: 5, to stdout
console.log('count:', count);
// Prints: count: 5, to stdout

See util.format() for more information.

@sincev0.1.100

log
(
const zoned: DateTime.Zoned
zoned
)
// Output: DateTime.Zoned(2025-01-01T04:00:00.000+01:00[Europe/Rome])
var console: Console

The console module provides a simple debugging console that is similar to the JavaScript console mechanism provided by web browsers.

The module exports two specific components:

  • A Console class with methods such as console.log(), console.error() and console.warn() that can be used to write to any Node.js stream.
  • A global console instance configured to write to process.stdout and process.stderr. The global console can be used without importing the node:console module.

Warning: The global console object's methods are neither consistently synchronous like the browser APIs they resemble, nor are they consistently asynchronous like all other Node.js streams. See the note on process I/O for more information.

Example using the global console:

console.log('hello world');
// Prints: hello world, to stdout
console.log('hello %s', 'world');
// Prints: hello world, to stdout
console.error(new Error('Whoops, something bad happened'));
// Prints error message and stack trace to stderr:
// Error: Whoops, something bad happened
// at [eval]:5:15
// at Script.runInThisContext (node:vm:132:18)
// at Object.runInThisContext (node:vm:309:38)
// at node:internal/process/execution:77:19
// at [eval]-wrapper:6:22
// at evalScript (node:internal/process/execution:76:60)
// at node:internal/main/eval_string:23:3
const name = 'Will Robinson';
console.warn(`Danger ${name}! Danger!`);
// Prints: Danger Will Robinson! Danger!, to stderr

Example using the Console class:

const out = getStreamSomehow();
const err = getStreamSomehow();
const myConsole = new console.Console(out, err);
myConsole.log('hello world');
// Prints: hello world, to out
myConsole.log('hello %s', 'world');
// Prints: hello world, to out
myConsole.error(new Error('Whoops, something bad happened'));
// Prints: [Error: Whoops, something bad happened], to err
const name = 'Will Robinson';
myConsole.warn(`Danger ${name}! Danger!`);
// Prints: Danger Will Robinson! Danger!, to err

@seesource

console
.
Console.log(message?: any, ...optionalParams: any[]): void

Prints to stdout with newline. Multiple arguments can be passed, with the first used as the primary message and all additional used as substitution values similar to printf(3) (the arguments are all passed to util.format()).

const count = 5;
console.log('count: %d', count);
// Prints: count: 5, to stdout
console.log('count:', count);
// Prints: count: 5, to stdout

See util.format() for more information.

@sincev0.1.100

log
(
const zoned: DateTime.Zoned
zoned
.
Zoned.zone: DateTime.TimeZone
zone
)
// Output: TimeZone.Named(Europe/Rome)

In this case, the "Europe/Rome" time zone is explicitly provided, resulting in the Zoned instance being tied to this named time zone.

By default, the input date is treated as a UTC value and then adjusted for the specified time zone. To interpret the input date as being in the specified time zone, you can use the adjustForTimeZone option.

Example (Adjusting for Time Zone Interpretation)

The following example assumes the code is executed on a system in Italy (CET timezone):

import {
import DateTime
DateTime
} from "effect"
// Interpret the input date as being in the specified time zone
const
const zoned: DateTime.Zoned
zoned
=
import DateTime
DateTime
.
const unsafeMakeZoned: (input: DateTime.DateTime.Input, options?: {
readonly timeZone?: number | string | DateTime.TimeZone | undefined;
readonly adjustForTimeZone?: boolean | undefined;
}) => DateTime.Zoned

Create a DateTime.Zoned using DateTime.unsafeMake and a time zone.

The input is treated as UTC and then the time zone is attached, unless adjustForTimeZone is set to true. In that case, the input is treated as already in the time zone.

@since3.6.0

@example

import { DateTime } from "effect"
DateTime.unsafeMakeZoned(new Date(), { timeZone: "Europe/London" })

unsafeMakeZoned
(new
var Date: DateConstructor
new (value: number | string | Date) => Date (+3 overloads)
Date
("2025-01-01 04:00:00"), {
timeZone?: string | number | DateTime.TimeZone | undefined
timeZone
: "Europe/Rome",
adjustForTimeZone?: boolean | undefined
adjustForTimeZone
: true
})
var console: Console

The console module provides a simple debugging console that is similar to the JavaScript console mechanism provided by web browsers.

The module exports two specific components:

  • A Console class with methods such as console.log(), console.error() and console.warn() that can be used to write to any Node.js stream.
  • A global console instance configured to write to process.stdout and process.stderr. The global console can be used without importing the node:console module.

Warning: The global console object's methods are neither consistently synchronous like the browser APIs they resemble, nor are they consistently asynchronous like all other Node.js streams. See the note on process I/O for more information.

Example using the global console:

console.log('hello world');
// Prints: hello world, to stdout
console.log('hello %s', 'world');
// Prints: hello world, to stdout
console.error(new Error('Whoops, something bad happened'));
// Prints error message and stack trace to stderr:
// Error: Whoops, something bad happened
// at [eval]:5:15
// at Script.runInThisContext (node:vm:132:18)
// at Object.runInThisContext (node:vm:309:38)
// at node:internal/process/execution:77:19
// at [eval]-wrapper:6:22
// at evalScript (node:internal/process/execution:76:60)
// at node:internal/main/eval_string:23:3
const name = 'Will Robinson';
console.warn(`Danger ${name}! Danger!`);
// Prints: Danger Will Robinson! Danger!, to stderr

Example using the Console class:

const out = getStreamSomehow();
const err = getStreamSomehow();
const myConsole = new console.Console(out, err);
myConsole.log('hello world');
// Prints: hello world, to out
myConsole.log('hello %s', 'world');
// Prints: hello world, to out
myConsole.error(new Error('Whoops, something bad happened'));
// Prints: [Error: Whoops, something bad happened], to err
const name = 'Will Robinson';
myConsole.warn(`Danger ${name}! Danger!`);
// Prints: Danger Will Robinson! Danger!, to err

@seesource

console
.
Console.log(message?: any, ...optionalParams: any[]): void

Prints to stdout with newline. Multiple arguments can be passed, with the first used as the primary message and all additional used as substitution values similar to printf(3) (the arguments are all passed to util.format()).

const count = 5;
console.log('count: %d', count);
// Prints: count: 5, to stdout
console.log('count:', count);
// Prints: count: 5, to stdout

See util.format() for more information.

@sincev0.1.100

log
(
const zoned: DateTime.Zoned
zoned
)
// Output: DateTime.Zoned(2025-01-01T03:00:00.000+01:00[Europe/Rome])
var console: Console

The console module provides a simple debugging console that is similar to the JavaScript console mechanism provided by web browsers.

The module exports two specific components:

  • A Console class with methods such as console.log(), console.error() and console.warn() that can be used to write to any Node.js stream.
  • A global console instance configured to write to process.stdout and process.stderr. The global console can be used without importing the node:console module.

Warning: The global console object's methods are neither consistently synchronous like the browser APIs they resemble, nor are they consistently asynchronous like all other Node.js streams. See the note on process I/O for more information.

Example using the global console:

console.log('hello world');
// Prints: hello world, to stdout
console.log('hello %s', 'world');
// Prints: hello world, to stdout
console.error(new Error('Whoops, something bad happened'));
// Prints error message and stack trace to stderr:
// Error: Whoops, something bad happened
// at [eval]:5:15
// at Script.runInThisContext (node:vm:132:18)
// at Object.runInThisContext (node:vm:309:38)
// at node:internal/process/execution:77:19
// at [eval]-wrapper:6:22
// at evalScript (node:internal/process/execution:76:60)
// at node:internal/main/eval_string:23:3
const name = 'Will Robinson';
console.warn(`Danger ${name}! Danger!`);
// Prints: Danger Will Robinson! Danger!, to stderr

Example using the Console class:

const out = getStreamSomehow();
const err = getStreamSomehow();
const myConsole = new console.Console(out, err);
myConsole.log('hello world');
// Prints: hello world, to out
myConsole.log('hello %s', 'world');
// Prints: hello world, to out
myConsole.error(new Error('Whoops, something bad happened'));
// Prints: [Error: Whoops, something bad happened], to err
const name = 'Will Robinson';
myConsole.warn(`Danger ${name}! Danger!`);
// Prints: Danger Will Robinson! Danger!, to err

@seesource

console
.
Console.log(message?: any, ...optionalParams: any[]): void

Prints to stdout with newline. Multiple arguments can be passed, with the first used as the primary message and all additional used as substitution values similar to printf(3) (the arguments are all passed to util.format()).

const count = 5;
console.log('count: %d', count);
// Prints: count: 5, to stdout
console.log('count:', count);
// Prints: count: 5, to stdout

See util.format() for more information.

@sincev0.1.100

log
(
const zoned: DateTime.Zoned
zoned
.
Zoned.zone: DateTime.TimeZone
zone
)
// Output: TimeZone.Named(Europe/Rome)

Explanation

  • Without adjustForTimeZone: The input date is interpreted as UTC and then adjusted to the specified time zone. For instance, 2025-01-01 04:00:00 in UTC becomes 2025-01-01T04:00:00.000+01:00 in CET (UTC+1).
  • With adjustForTimeZone: true: The input date is interpreted as being in the specified time zone. For example, 2025-01-01 04:00:00 in “Europe/Rome” (CET) is adjusted to its corresponding UTC time, resulting in 2025-01-01T03:00:00.000+01:00.

The makeZoned function works similarly to unsafeMakeZoned but provides a safer approach. Instead of throwing an error when the input is invalid, it returns an Option<Zoned>. If the input is invalid, it returns None. If valid, it returns Some containing the Zoned.

Example (Safely Creating a Zoned DateTime)

import {
import DateTime
DateTime
,
import Option

@since2.0.0

@since2.0.0

Option
} from "effect"
// ┌─── Option<Zoned>
// ▼
const
const zoned: Option.Option<DateTime.Zoned>
zoned
=
import DateTime
DateTime
.
const makeZoned: (input: DateTime.DateTime.Input, options?: {
readonly timeZone?: number | string | DateTime.TimeZone | undefined;
readonly adjustForTimeZone?: boolean | undefined;
}) => Option.Option<DateTime.Zoned>

Create a DateTime.Zoned using DateTime.make and a time zone.

The input is treated as UTC and then the time zone is attached.

If the date time input or time zone is invalid, None will be returned.

@since3.6.0

@example

import { DateTime } from "effect"
DateTime.makeZoned(new Date(), { timeZone: "Europe/London" })

makeZoned
(new
var Date: DateConstructor
new (value: number | string | Date) => Date (+3 overloads)
Date
("2025-01-01 04:00:00"), {
timeZone?: string | number | DateTime.TimeZone | undefined
timeZone
: "Europe/Rome"
})
if (
import Option

@since2.0.0

@since2.0.0

Option
.
const isSome: <DateTime.Zoned>(self: Option.Option<DateTime.Zoned>) => self is Option.Some<DateTime.Zoned>

Determine if a Option is a Some.

@paramself - The Option to check.

@example

import { Option } from "effect"
assert.deepStrictEqual(Option.isSome(Option.some(1)), true)
assert.deepStrictEqual(Option.isSome(Option.none()), false)

@since2.0.0

isSome
(
const zoned: Option.Option<DateTime.Zoned>
zoned
)) {
var console: Console

The console module provides a simple debugging console that is similar to the JavaScript console mechanism provided by web browsers.

The module exports two specific components:

  • A Console class with methods such as console.log(), console.error() and console.warn() that can be used to write to any Node.js stream.
  • A global console instance configured to write to process.stdout and process.stderr. The global console can be used without importing the node:console module.

Warning: The global console object's methods are neither consistently synchronous like the browser APIs they resemble, nor are they consistently asynchronous like all other Node.js streams. See the note on process I/O for more information.

Example using the global console:

console.log('hello world');
// Prints: hello world, to stdout
console.log('hello %s', 'world');
// Prints: hello world, to stdout
console.error(new Error('Whoops, something bad happened'));
// Prints error message and stack trace to stderr:
// Error: Whoops, something bad happened
// at [eval]:5:15
// at Script.runInThisContext (node:vm:132:18)
// at Object.runInThisContext (node:vm:309:38)
// at node:internal/process/execution:77:19
// at [eval]-wrapper:6:22
// at evalScript (node:internal/process/execution:76:60)
// at node:internal/main/eval_string:23:3
const name = 'Will Robinson';
console.warn(`Danger ${name}! Danger!`);
// Prints: Danger Will Robinson! Danger!, to stderr

Example using the Console class:

const out = getStreamSomehow();
const err = getStreamSomehow();
const myConsole = new console.Console(out, err);
myConsole.log('hello world');
// Prints: hello world, to out
myConsole.log('hello %s', 'world');
// Prints: hello world, to out
myConsole.error(new Error('Whoops, something bad happened'));
// Prints: [Error: Whoops, something bad happened], to err
const name = 'Will Robinson';
myConsole.warn(`Danger ${name}! Danger!`);
// Prints: Danger Will Robinson! Danger!, to err

@seesource

console
.
Console.log(message?: any, ...optionalParams: any[]): void

Prints to stdout with newline. Multiple arguments can be passed, with the first used as the primary message and all additional used as substitution values similar to printf(3) (the arguments are all passed to util.format()).

const count = 5;
console.log('count: %d', count);
// Prints: count: 5, to stdout
console.log('count:', count);
// Prints: count: 5, to stdout

See util.format() for more information.

@sincev0.1.100

log
("The DateTime is valid")
}

Creates a Zoned by parsing a string in the format YYYY-MM-DDTHH:mm:ss.sss+HH:MM[IANA timezone identifier].

If the input string is valid, the function returns a Some containing the Zoned. If the input is invalid, it returns None.

Example (Parsing a Zoned DateTime from a String)

import {
import DateTime
DateTime
,
import Option

@since2.0.0

@since2.0.0

Option
} from "effect"
// ┌─── Option<Zoned>
// ▼
const
const zoned: Option.Option<DateTime.Zoned>
zoned
=
import DateTime
DateTime
.
const makeZonedFromString: (input: string) => Option.Option<DateTime.Zoned>

Create a DateTime.Zoned from a string.

It uses the format: YYYY-MM-DDTHH:mm:ss.sss+HH:MM[Time/Zone].

@since3.6.0

makeZonedFromString
(
"2025-01-01T03:00:00.000+01:00[Europe/Rome]"
)
if (
import Option

@since2.0.0

@since2.0.0

Option
.
const isSome: <DateTime.Zoned>(self: Option.Option<DateTime.Zoned>) => self is Option.Some<DateTime.Zoned>

Determine if a Option is a Some.

@paramself - The Option to check.

@example

import { Option } from "effect"
assert.deepStrictEqual(Option.isSome(Option.some(1)), true)
assert.deepStrictEqual(Option.isSome(Option.none()), false)

@since2.0.0

isSome
(
const zoned: Option.Option<DateTime.Zoned>
zoned
)) {
var console: Console

The console module provides a simple debugging console that is similar to the JavaScript console mechanism provided by web browsers.

The module exports two specific components:

  • A Console class with methods such as console.log(), console.error() and console.warn() that can be used to write to any Node.js stream.
  • A global console instance configured to write to process.stdout and process.stderr. The global console can be used without importing the node:console module.

Warning: The global console object's methods are neither consistently synchronous like the browser APIs they resemble, nor are they consistently asynchronous like all other Node.js streams. See the note on process I/O for more information.

Example using the global console:

console.log('hello world');
// Prints: hello world, to stdout
console.log('hello %s', 'world');
// Prints: hello world, to stdout
console.error(new Error('Whoops, something bad happened'));
// Prints error message and stack trace to stderr:
// Error: Whoops, something bad happened
// at [eval]:5:15
// at Script.runInThisContext (node:vm:132:18)
// at Object.runInThisContext (node:vm:309:38)
// at node:internal/process/execution:77:19
// at [eval]-wrapper:6:22
// at evalScript (node:internal/process/execution:76:60)
// at node:internal/main/eval_string:23:3
const name = 'Will Robinson';
console.warn(`Danger ${name}! Danger!`);
// Prints: Danger Will Robinson! Danger!, to stderr

Example using the Console class:

const out = getStreamSomehow();
const err = getStreamSomehow();
const myConsole = new console.Console(out, err);
myConsole.log('hello world');
// Prints: hello world, to out
myConsole.log('hello %s', 'world');
// Prints: hello world, to out
myConsole.error(new Error('Whoops, something bad happened'));
// Prints: [Error: Whoops, something bad happened], to err
const name = 'Will Robinson';
myConsole.warn(`Danger ${name}! Danger!`);
// Prints: Danger Will Robinson! Danger!, to err

@seesource

console
.
Console.log(message?: any, ...optionalParams: any[]): void

Prints to stdout with newline. Multiple arguments can be passed, with the first used as the primary message and all additional used as substitution values similar to printf(3) (the arguments are all passed to util.format()).

const count = 5;
console.log('count: %d', count);
// Prints: count: 5, to stdout
console.log('count:', count);
// Prints: count: 5, to stdout

See util.format() for more information.

@sincev0.1.100

log
("The DateTime is valid")
}

Provides the current UTC time as a Effect<Utc>, using the Clock service.

Example (Retrieving the Current UTC Time)

import {
import DateTime
DateTime
,
import Effect

@since2.0.0

@since2.0.0

@since2.0.0

Effect
} from "effect"
const
const program: Effect.Effect<void, never, never>
program
=
import Effect

@since2.0.0

@since2.0.0

@since2.0.0

Effect
.
const gen: <YieldWrap<Effect.Effect<DateTime.Utc, never, never>>, void>(f: (resume: Effect.Adapter) => Generator<YieldWrap<Effect.Effect<DateTime.Utc, never, never>>, void, never>) => Effect.Effect<...> (+1 overload)

Provides a way to write effectful code using generator functions, simplifying control flow and error handling.

When to Use

Effect.gen allows you to write code that looks and behaves like synchronous code, but it can handle asynchronous tasks, errors, and complex control flow (like loops and conditions). It helps make asynchronous code more readable and easier to manage.

The generator functions work similarly to async/await but with more explicit control over the execution of effects. You can yield* values from effects and return the final result at the end.

@example

import { Effect } from "effect"
const addServiceCharge = (amount: number) => amount + 1
const applyDiscount = (
total: number,
discountRate: number
): Effect.Effect<number, Error> =>
discountRate === 0
? Effect.fail(new Error("Discount rate cannot be zero"))
: Effect.succeed(total - (total * discountRate) / 100)
const fetchTransactionAmount = Effect.promise(() => Promise.resolve(100))
const fetchDiscountRate = Effect.promise(() => Promise.resolve(5))
export const program = Effect.gen(function* () {
const transactionAmount = yield* fetchTransactionAmount
const discountRate = yield* fetchDiscountRate
const discountedAmount = yield* applyDiscount(
transactionAmount,
discountRate
)
const finalAmount = addServiceCharge(discountedAmount)
return `Final amount to charge: ${finalAmount}`
})

@since2.0.0

gen
(function* () {
// ┌─── Utc
// ▼
const
const currentTime: DateTime.Utc
currentTime
= yield*
import DateTime
DateTime
.
const now: Effect.Effect<DateTime.Utc, never, never>

Get the current time using the Clock service and convert it to a DateTime.

@since3.6.0

@example

import { DateTime, Effect } from "effect"
Effect.gen(function* () {
const now = yield* DateTime.now
})

now
})

Retrieves the current UTC time immediately using Date.now(), without the Clock service.

Example (Getting the Current UTC Time Immediately)

import {
import DateTime
DateTime
} from "effect"
// ┌─── Utc
// ▼
const
const currentTime: DateTime.Utc
currentTime
=
import DateTime
DateTime
.
const unsafeNow: LazyArg
() => DateTime.Utc

Get the current time using Date.now.

@since3.6.0

unsafeNow
()
FunctionDescription
isDateTimeChecks if a value is a DateTime.
isTimeZoneChecks if a value is a TimeZone.
isTimeZoneOffsetChecks if a value is a TimeZone.Offset.
isTimeZoneNamedChecks if a value is a TimeZone.Named.
isUtcChecks if a DateTime is the Utc variant.
isZonedChecks if a DateTime is the Zoned variant.

Example (Validating a DateTime)

import {
import DateTime
DateTime
} from "effect"
function
function printDateTimeInfo(x: unknown): void
printDateTimeInfo
(
x: unknown
x
: unknown) {
if (
import DateTime
DateTime
.
const isDateTime: (u: unknown) => u is DateTime.DateTime

@since3.6.0

isDateTime
(
x: unknown
x
)) {
var console: Console

The console module provides a simple debugging console that is similar to the JavaScript console mechanism provided by web browsers.

The module exports two specific components:

  • A Console class with methods such as console.log(), console.error() and console.warn() that can be used to write to any Node.js stream.
  • A global console instance configured to write to process.stdout and process.stderr. The global console can be used without importing the node:console module.

Warning: The global console object's methods are neither consistently synchronous like the browser APIs they resemble, nor are they consistently asynchronous like all other Node.js streams. See the note on process I/O for more information.

Example using the global console:

console.log('hello world');
// Prints: hello world, to stdout
console.log('hello %s', 'world');
// Prints: hello world, to stdout
console.error(new Error('Whoops, something bad happened'));
// Prints error message and stack trace to stderr:
// Error: Whoops, something bad happened
// at [eval]:5:15
// at Script.runInThisContext (node:vm:132:18)
// at Object.runInThisContext (node:vm:309:38)
// at node:internal/process/execution:77:19
// at [eval]-wrapper:6:22
// at evalScript (node:internal/process/execution:76:60)
// at node:internal/main/eval_string:23:3
const name = 'Will Robinson';
console.warn(`Danger ${name}! Danger!`);
// Prints: Danger Will Robinson! Danger!, to stderr

Example using the Console class:

const out = getStreamSomehow();
const err = getStreamSomehow();
const myConsole = new console.Console(out, err);
myConsole.log('hello world');
// Prints: hello world, to out
myConsole.log('hello %s', 'world');
// Prints: hello world, to out
myConsole.error(new Error('Whoops, something bad happened'));
// Prints: [Error: Whoops, something bad happened], to err
const name = 'Will Robinson';
myConsole.warn(`Danger ${name}! Danger!`);
// Prints: Danger Will Robinson! Danger!, to err

@seesource

console
.
Console.log(message?: any, ...optionalParams: any[]): void

Prints to stdout with newline. Multiple arguments can be passed, with the first used as the primary message and all additional used as substitution values similar to printf(3) (the arguments are all passed to util.format()).

const count = 5;
console.log('count: %d', count);
// Prints: count: 5, to stdout
console.log('count:', count);
// Prints: count: 5, to stdout

See util.format() for more information.

@sincev0.1.100

log
("This is a valid DateTime")
} else {
var console: Console

The console module provides a simple debugging console that is similar to the JavaScript console mechanism provided by web browsers.

The module exports two specific components:

  • A Console class with methods such as console.log(), console.error() and console.warn() that can be used to write to any Node.js stream.
  • A global console instance configured to write to process.stdout and process.stderr. The global console can be used without importing the node:console module.

Warning: The global console object's methods are neither consistently synchronous like the browser APIs they resemble, nor are they consistently asynchronous like all other Node.js streams. See the note on process I/O for more information.

Example using the global console:

console.log('hello world');
// Prints: hello world, to stdout
console.log('hello %s', 'world');
// Prints: hello world, to stdout
console.error(new Error('Whoops, something bad happened'));
// Prints error message and stack trace to stderr:
// Error: Whoops, something bad happened
// at [eval]:5:15
// at Script.runInThisContext (node:vm:132:18)
// at Object.runInThisContext (node:vm:309:38)
// at node:internal/process/execution:77:19
// at [eval]-wrapper:6:22
// at evalScript (node:internal/process/execution:76:60)
// at node:internal/main/eval_string:23:3
const name = 'Will Robinson';
console.warn(`Danger ${name}! Danger!`);
// Prints: Danger Will Robinson! Danger!, to stderr

Example using the Console class:

const out = getStreamSomehow();
const err = getStreamSomehow();
const myConsole = new console.Console(out, err);
myConsole.log('hello world');
// Prints: hello world, to out
myConsole.log('hello %s', 'world');
// Prints: hello world, to out
myConsole.error(new Error('Whoops, something bad happened'));
// Prints: [Error: Whoops, something bad happened], to err
const name = 'Will Robinson';
myConsole.warn(`Danger ${name}! Danger!`);
// Prints: Danger Will Robinson! Danger!, to err

@seesource

console
.
Console.log(message?: any, ...optionalParams: any[]): void

Prints to stdout with newline. Multiple arguments can be passed, with the first used as the primary message and all additional used as substitution values similar to printf(3) (the arguments are all passed to util.format()).

const count = 5;
console.log('count: %d', count);
// Prints: count: 5, to stdout
console.log('count:', count);
// Prints: count: 5, to stdout

See util.format() for more information.

@sincev0.1.100

log
("Not a DateTime")
}
}
FunctionDescription
setZoneCreates a Zoned from DateTime by applying the given TimeZone.
setZoneOffsetCreates a Zoned from DateTime using a fixed offset (in ms).
setZoneNamedCreates a Zoned from DateTime from an IANA time zone identifier or returns None if invalid.
unsafeSetZoneNamedCreates a Zoned from DateTime from an IANA time zone identifier or throws if invalid.
zoneUnsafeMakeNamedCreates a TimeZone.Named from a IANA time zone identifier or throws if the identifier is invalid.
zoneMakeNamedCreates a TimeZone.Named from a IANA time zone identifier or returns None if invalid.
zoneMakeNamedEffectCreates a Effect<TimeZone.Named, IllegalArgumentException> from a IANA time zone identifier failing with IllegalArgumentException if invalid
zoneMakeOffsetCreates a TimeZone.Offset from a numeric offset in milliseconds.
zoneMakeLocalCreates a TimeZone.Named from the system’s local time zone.
zoneFromStringAttempts to parse a time zone from a string, returning None if invalid.
zoneToStringReturns a string representation of a TimeZone.

Example (Applying a Time Zone to a DateTime)

import {
import DateTime
DateTime
} from "effect"
// Create a UTC DateTime
//
// ┌─── Utc
// ▼
const
const utc: DateTime.Utc
utc
=
import DateTime
DateTime
.
const unsafeMake: <"2024-01-01">(input: "2024-01-01") => DateTime.Utc

Create a DateTime from one of the following:

  • A DateTime
  • A Date instance (invalid dates will throw an IllegalArgumentException)
  • The number of milliseconds since the Unix epoch
  • An object with the parts of a date
  • A string that can be parsed by Date.parse

@since3.6.0

@example

import { DateTime } from "effect"
// from Date
DateTime.unsafeMake(new Date())
// from parts
DateTime.unsafeMake({ year: 2024 })
// from string
DateTime.unsafeMake("2024-01-01")

unsafeMake
("2024-01-01")
// Create a named time zone for New York
//
// ┌─── TimeZone.Named
// ▼
const
const zoneNY: DateTime.TimeZone.Named
zoneNY
=
import DateTime
DateTime
.
const zoneUnsafeMakeNamed: (zoneId: string) => DateTime.TimeZone.Named

Attempt to create a named time zone from a IANA time zone identifier.

If the time zone is invalid, an IllegalArgumentException will be thrown.

@since3.6.0

zoneUnsafeMakeNamed
("America/New_York")
// Apply it to the DateTime
//
// ┌─── Zoned
// ▼
const
const zoned: DateTime.Zoned
zoned
=
import DateTime
DateTime
.
const setZone: (self: DateTime.DateTime, zone: DateTime.TimeZone, options?: {
readonly adjustForTimeZone?: boolean | undefined;
}) => DateTime.Zoned (+1 overload)

Set the time zone of a DateTime, returning a new DateTime.Zoned.

@since3.6.0

@example

import { DateTime, Effect } from "effect"
Effect.gen(function* () {
const now = yield* DateTime.now
const zone = DateTime.zoneUnsafeMakeNamed("Europe/London")
// set the time zone
const zoned: DateTime.Zoned = DateTime.setZone(now, zone)
})

setZone
(
const utc: DateTime.Utc
utc
,
const zoneNY: DateTime.TimeZone.Named
zoneNY
)
var console: Console

The console module provides a simple debugging console that is similar to the JavaScript console mechanism provided by web browsers.

The module exports two specific components:

  • A Console class with methods such as console.log(), console.error() and console.warn() that can be used to write to any Node.js stream.
  • A global console instance configured to write to process.stdout and process.stderr. The global console can be used without importing the node:console module.

Warning: The global console object's methods are neither consistently synchronous like the browser APIs they resemble, nor are they consistently asynchronous like all other Node.js streams. See the note on process I/O for more information.

Example using the global console:

console.log('hello world');
// Prints: hello world, to stdout
console.log('hello %s', 'world');
// Prints: hello world, to stdout
console.error(new Error('Whoops, something bad happened'));
// Prints error message and stack trace to stderr:
// Error: Whoops, something bad happened
// at [eval]:5:15
// at Script.runInThisContext (node:vm:132:18)
// at Object.runInThisContext (node:vm:309:38)
// at node:internal/process/execution:77:19
// at [eval]-wrapper:6:22
// at evalScript (node:internal/process/execution:76:60)
// at node:internal/main/eval_string:23:3
const name = 'Will Robinson';
console.warn(`Danger ${name}! Danger!`);
// Prints: Danger Will Robinson! Danger!, to stderr

Example using the Console class:

const out = getStreamSomehow();
const err = getStreamSomehow();
const myConsole = new console.Console(out, err);
myConsole.log('hello world');
// Prints: hello world, to out
myConsole.log('hello %s', 'world');
// Prints: hello world, to out
myConsole.error(new Error('Whoops, something bad happened'));
// Prints: [Error: Whoops, something bad happened], to err
const name = 'Will Robinson';
myConsole.warn(`Danger ${name}! Danger!`);
// Prints: Danger Will Robinson! Danger!, to err

@seesource

console
.
Console.log(message?: any, ...optionalParams: any[]): void

Prints to stdout with newline. Multiple arguments can be passed, with the first used as the primary message and all additional used as substitution values similar to printf(3) (the arguments are all passed to util.format()).

const count = 5;
console.log('count: %d', count);
// Prints: count: 5, to stdout
console.log('count:', count);
// Prints: count: 5, to stdout

See util.format() for more information.

@sincev0.1.100

log
(
const zoned: DateTime.Zoned
zoned
)
// Output: DateTime.Zoned(2023-12-31T19:00:00.000-05:00[America/New_York])

Parses a string to create a DateTime.TimeZone.

This function attempts to interpret the input string as either:

  • A numeric time zone offset (e.g., “GMT”, “+01:00”)
  • An IANA time zone identifier (e.g., “Europe/London”)

If the string matches an offset format, it is converted into a TimeZone.Offset. Otherwise, it attempts to create a TimeZone.Named using the input.

If the input string is invalid, Option.none() is returned.

Example (Parsing a Time Zone from a String)

import {
import DateTime
DateTime
,
import Option

@since2.0.0

@since2.0.0

Option
} from "effect"
// Attempt to parse a numeric offset
const
const offsetZone: Option.Option<DateTime.TimeZone>
offsetZone
=
import DateTime
DateTime
.
const zoneFromString: (zone: string) => Option.Option<DateTime.TimeZone>

Try parse a TimeZone from a string

@since3.6.0

zoneFromString
("+01:00")
var console: Console

The console module provides a simple debugging console that is similar to the JavaScript console mechanism provided by web browsers.

The module exports two specific components:

  • A Console class with methods such as console.log(), console.error() and console.warn() that can be used to write to any Node.js stream.
  • A global console instance configured to write to process.stdout and process.stderr. The global console can be used without importing the node:console module.

Warning: The global console object's methods are neither consistently synchronous like the browser APIs they resemble, nor are they consistently asynchronous like all other Node.js streams. See the note on process I/O for more information.

Example using the global console:

console.log('hello world');
// Prints: hello world, to stdout
console.log('hello %s', 'world');
// Prints: hello world, to stdout
console.error(new Error('Whoops, something bad happened'));
// Prints error message and stack trace to stderr:
// Error: Whoops, something bad happened
// at [eval]:5:15
// at Script.runInThisContext (node:vm:132:18)
// at Object.runInThisContext (node:vm:309:38)
// at node:internal/process/execution:77:19
// at [eval]-wrapper:6:22
// at evalScript (node:internal/process/execution:76:60)
// at node:internal/main/eval_string:23:3
const name = 'Will Robinson';
console.warn(`Danger ${name}! Danger!`);
// Prints: Danger Will Robinson! Danger!, to stderr

Example using the Console class:

const out = getStreamSomehow();
const err = getStreamSomehow();
const myConsole = new console.Console(out, err);
myConsole.log('hello world');
// Prints: hello world, to out
myConsole.log('hello %s', 'world');
// Prints: hello world, to out
myConsole.error(new Error('Whoops, something bad happened'));
// Prints: [Error: Whoops, something bad happened], to err
const name = 'Will Robinson';
myConsole.warn(`Danger ${name}! Danger!`);
// Prints: Danger Will Robinson! Danger!, to err

@seesource

console
.
Console.log(message?: any, ...optionalParams: any[]): void

Prints to stdout with newline. Multiple arguments can be passed, with the first used as the primary message and all additional used as substitution values similar to printf(3) (the arguments are all passed to util.format()).

const count = 5;
console.log('count: %d', count);
// Prints: count: 5, to stdout
console.log('count:', count);
// Prints: count: 5, to stdout

See util.format() for more information.

@sincev0.1.100

log
(
import Option

@since2.0.0

@since2.0.0

Option
.
const isSome: <DateTime.TimeZone>(self: Option.Option<DateTime.TimeZone>) => self is Option.Some<DateTime.TimeZone>

Determine if a Option is a Some.

@paramself - The Option to check.

@example

import { Option } from "effect"
assert.deepStrictEqual(Option.isSome(Option.some(1)), true)
assert.deepStrictEqual(Option.isSome(Option.none()), false)

@since2.0.0

isSome
(
const offsetZone: Option.Option<DateTime.TimeZone>
offsetZone
))
// Output: true
// Attempt to parse an IANA time zone
const
const namedZone: Option.Option<DateTime.TimeZone>
namedZone
=
import DateTime
DateTime
.
const zoneFromString: (zone: string) => Option.Option<DateTime.TimeZone>

Try parse a TimeZone from a string

@since3.6.0

zoneFromString
("Europe/London")
var console: Console

The console module provides a simple debugging console that is similar to the JavaScript console mechanism provided by web browsers.

The module exports two specific components:

  • A Console class with methods such as console.log(), console.error() and console.warn() that can be used to write to any Node.js stream.
  • A global console instance configured to write to process.stdout and process.stderr. The global console can be used without importing the node:console module.

Warning: The global console object's methods are neither consistently synchronous like the browser APIs they resemble, nor are they consistently asynchronous like all other Node.js streams. See the note on process I/O for more information.

Example using the global console:

console.log('hello world');
// Prints: hello world, to stdout
console.log('hello %s', 'world');
// Prints: hello world, to stdout
console.error(new Error('Whoops, something bad happened'));
// Prints error message and stack trace to stderr:
// Error: Whoops, something bad happened
// at [eval]:5:15
// at Script.runInThisContext (node:vm:132:18)
// at Object.runInThisContext (node:vm:309:38)
// at node:internal/process/execution:77:19
// at [eval]-wrapper:6:22
// at evalScript (node:internal/process/execution:76:60)
// at node:internal/main/eval_string:23:3
const name = 'Will Robinson';
console.warn(`Danger ${name}! Danger!`);
// Prints: Danger Will Robinson! Danger!, to stderr

Example using the Console class:

const out = getStreamSomehow();
const err = getStreamSomehow();
const myConsole = new console.Console(out, err);
myConsole.log('hello world');
// Prints: hello world, to out
myConsole.log('hello %s', 'world');
// Prints: hello world, to out
myConsole.error(new Error('Whoops, something bad happened'));
// Prints: [Error: Whoops, something bad happened], to err
const name = 'Will Robinson';
myConsole.warn(`Danger ${name}! Danger!`);
// Prints: Danger Will Robinson! Danger!, to err

@seesource

console
.
Console.log(message?: any, ...optionalParams: any[]): void

Prints to stdout with newline. Multiple arguments can be passed, with the first used as the primary message and all additional used as substitution values similar to printf(3) (the arguments are all passed to util.format()).

const count = 5;
console.log('count: %d', count);
// Prints: count: 5, to stdout
console.log('count:', count);
// Prints: count: 5, to stdout

See util.format() for more information.

@sincev0.1.100

log
(
import Option

@since2.0.0

@since2.0.0

Option
.
const isSome: <DateTime.TimeZone>(self: Option.Option<DateTime.TimeZone>) => self is Option.Some<DateTime.TimeZone>

Determine if a Option is a Some.

@paramself - The Option to check.

@example

import { Option } from "effect"
assert.deepStrictEqual(Option.isSome(Option.some(1)), true)
assert.deepStrictEqual(Option.isSome(Option.none()), false)

@since2.0.0

isSome
(
const namedZone: Option.Option<DateTime.TimeZone>
namedZone
))
// Output: true
// Invalid input
const
const invalidZone: Option.Option<DateTime.TimeZone>
invalidZone
=
import DateTime
DateTime
.
const zoneFromString: (zone: string) => Option.Option<DateTime.TimeZone>

Try parse a TimeZone from a string

@since3.6.0

zoneFromString
("Invalid/Zone")
var console: Console

The console module provides a simple debugging console that is similar to the JavaScript console mechanism provided by web browsers.

The module exports two specific components:

  • A Console class with methods such as console.log(), console.error() and console.warn() that can be used to write to any Node.js stream.
  • A global console instance configured to write to process.stdout and process.stderr. The global console can be used without importing the node:console module.

Warning: The global console object's methods are neither consistently synchronous like the browser APIs they resemble, nor are they consistently asynchronous like all other Node.js streams. See the note on process I/O for more information.

Example using the global console:

console.log('hello world');
// Prints: hello world, to stdout
console.log('hello %s', 'world');
// Prints: hello world, to stdout
console.error(new Error('Whoops, something bad happened'));
// Prints error message and stack trace to stderr:
// Error: Whoops, something bad happened
// at [eval]:5:15
// at Script.runInThisContext (node:vm:132:18)
// at Object.runInThisContext (node:vm:309:38)
// at node:internal/process/execution:77:19
// at [eval]-wrapper:6:22
// at evalScript (node:internal/process/execution:76:60)
// at node:internal/main/eval_string:23:3
const name = 'Will Robinson';
console.warn(`Danger ${name}! Danger!`);
// Prints: Danger Will Robinson! Danger!, to stderr

Example using the Console class:

const out = getStreamSomehow();
const err = getStreamSomehow();
const myConsole = new console.Console(out, err);
myConsole.log('hello world');
// Prints: hello world, to out
myConsole.log('hello %s', 'world');
// Prints: hello world, to out
myConsole.error(new Error('Whoops, something bad happened'));
// Prints: [Error: Whoops, something bad happened], to err
const name = 'Will Robinson';
myConsole.warn(`Danger ${name}! Danger!`);
// Prints: Danger Will Robinson! Danger!, to err

@seesource

console
.
Console.log(message?: any, ...optionalParams: any[]): void

Prints to stdout with newline. Multiple arguments can be passed, with the first used as the primary message and all additional used as substitution values similar to printf(3) (the arguments are all passed to util.format()).

const count = 5;
console.log('count: %d', count);
// Prints: count: 5, to stdout
console.log('count:', count);
// Prints: count: 5, to stdout

See util.format() for more information.

@sincev0.1.100

log
(
import Option

@since2.0.0

@since2.0.0

Option
.
const isSome: <DateTime.TimeZone>(self: Option.Option<DateTime.TimeZone>) => self is Option.Some<DateTime.TimeZone>

Determine if a Option is a Some.

@paramself - The Option to check.

@example

import { Option } from "effect"
assert.deepStrictEqual(Option.isSome(Option.some(1)), true)
assert.deepStrictEqual(Option.isSome(Option.none()), false)

@since2.0.0

isSome
(
const invalidZone: Option.Option<DateTime.TimeZone>
invalidZone
))
// Output: false
FunctionDescription
distanceReturns the difference (in ms) between two DateTimes.
distanceDurationEitherReturns a Left or Right Duration depending on order.
distanceDurationReturns a Duration indicating how far apart two times are.
minReturns the earlier of two DateTime values.
maxReturns the later of two DateTime values.
greaterThan, greaterThanOrEqualTo, etc.Checks ordering between two DateTime values.
betweenChecks if a DateTime lies within the given bounds.
isFuture, isPast, unsafeIsFuture, etc.Checks if a DateTime is in the future or past.

Example (Finding the Distance Between Two DateTimes)

import {
import DateTime
DateTime
} from "effect"
const
const utc1: DateTime.Utc
utc1
=
import DateTime
DateTime
.
const unsafeMake: <"2025-01-01T00:00:00Z">(input: "2025-01-01T00:00:00Z") => DateTime.Utc

Create a DateTime from one of the following:

  • A DateTime
  • A Date instance (invalid dates will throw an IllegalArgumentException)
  • The number of milliseconds since the Unix epoch
  • An object with the parts of a date
  • A string that can be parsed by Date.parse

@since3.6.0

@example

import { DateTime } from "effect"
// from Date
DateTime.unsafeMake(new Date())
// from parts
DateTime.unsafeMake({ year: 2024 })
// from string
DateTime.unsafeMake("2024-01-01")

unsafeMake
("2025-01-01T00:00:00Z")
const
const utc2: DateTime.Utc
utc2
=
import DateTime
DateTime
.
const add: <DateTime.Utc>(self: DateTime.Utc, parts: Partial<DateTime.DateTime.PartsForMath>) => DateTime.Utc (+1 overload)

Add the given amount of unit's to a DateTime.

The time zone is taken into account when adding days, weeks, months, and years.

@since3.6.0

@example

import { DateTime } from "effect"
// add 5 minutes
DateTime.unsafeMake(0).pipe(
DateTime.add({ minutes: 5 })
)

add
(
const utc1: DateTime.Utc
utc1
, {
days?: number
days
: 1 })
var console: Console

The console module provides a simple debugging console that is similar to the JavaScript console mechanism provided by web browsers.

The module exports two specific components:

  • A Console class with methods such as console.log(), console.error() and console.warn() that can be used to write to any Node.js stream.
  • A global console instance configured to write to process.stdout and process.stderr. The global console can be used without importing the node:console module.

Warning: The global console object's methods are neither consistently synchronous like the browser APIs they resemble, nor are they consistently asynchronous like all other Node.js streams. See the note on process I/O for more information.

Example using the global console:

console.log('hello world');
// Prints: hello world, to stdout
console.log('hello %s', 'world');
// Prints: hello world, to stdout
console.error(new Error('Whoops, something bad happened'));
// Prints error message and stack trace to stderr:
// Error: Whoops, something bad happened
// at [eval]:5:15
// at Script.runInThisContext (node:vm:132:18)
// at Object.runInThisContext (node:vm:309:38)
// at node:internal/process/execution:77:19
// at [eval]-wrapper:6:22
// at evalScript (node:internal/process/execution:76:60)
// at node:internal/main/eval_string:23:3
const name = 'Will Robinson';
console.warn(`Danger ${name}! Danger!`);
// Prints: Danger Will Robinson! Danger!, to stderr

Example using the Console class:

const out = getStreamSomehow();
const err = getStreamSomehow();
const myConsole = new console.Console(out, err);
myConsole.log('hello world');
// Prints: hello world, to out
myConsole.log('hello %s', 'world');
// Prints: hello world, to out
myConsole.error(new Error('Whoops, something bad happened'));
// Prints: [Error: Whoops, something bad happened], to err
const name = 'Will Robinson';
myConsole.warn(`Danger ${name}! Danger!`);
// Prints: Danger Will Robinson! Danger!, to err

@seesource

console
.
Console.log(message?: any, ...optionalParams: any[]): void

Prints to stdout with newline. Multiple arguments can be passed, with the first used as the primary message and all additional used as substitution values similar to printf(3) (the arguments are all passed to util.format()).

const count = 5;
console.log('count: %d', count);
// Prints: count: 5, to stdout
console.log('count:', count);
// Prints: count: 5, to stdout

See util.format() for more information.

@sincev0.1.100

log
(
import DateTime
DateTime
.
const distance: (self: DateTime.DateTime, other: DateTime.DateTime) => number (+1 overload)

Calulate the difference between two DateTime values, returning the number of milliseconds the other DateTime is from self.

If other is after self, the result will be a positive number.

@since3.6.0

@example

import { DateTime, Effect } from "effect"
Effect.gen(function* () {
const now = yield* DateTime.now
const other = DateTime.add(now, { minutes: 1 })
// returns 60000
DateTime.distance(now, other)
})

distance
(
const utc1: DateTime.Utc
utc1
,
const utc2: DateTime.Utc
utc2
))
// Output: 86400000 (one day)
var console: Console

The console module provides a simple debugging console that is similar to the JavaScript console mechanism provided by web browsers.

The module exports two specific components:

  • A Console class with methods such as console.log(), console.error() and console.warn() that can be used to write to any Node.js stream.
  • A global console instance configured to write to process.stdout and process.stderr. The global console can be used without importing the node:console module.

Warning: The global console object's methods are neither consistently synchronous like the browser APIs they resemble, nor are they consistently asynchronous like all other Node.js streams. See the note on process I/O for more information.

Example using the global console:

console.log('hello world');
// Prints: hello world, to stdout
console.log('hello %s', 'world');
// Prints: hello world, to stdout
console.error(new Error('Whoops, something bad happened'));
// Prints error message and stack trace to stderr:
// Error: Whoops, something bad happened
// at [eval]:5:15
// at Script.runInThisContext (node:vm:132:18)
// at Object.runInThisContext (node:vm:309:38)
// at node:internal/process/execution:77:19
// at [eval]-wrapper:6:22
// at evalScript (node:internal/process/execution:76:60)
// at node:internal/main/eval_string:23:3
const name = 'Will Robinson';
console.warn(`Danger ${name}! Danger!`);
// Prints: Danger Will Robinson! Danger!, to stderr

Example using the Console class:

const out = getStreamSomehow();
const err = getStreamSomehow();
const myConsole = new console.Console(out, err);
myConsole.log('hello world');
// Prints: hello world, to out
myConsole.log('hello %s', 'world');
// Prints: hello world, to out
myConsole.error(new Error('Whoops, something bad happened'));
// Prints: [Error: Whoops, something bad happened], to err
const name = 'Will Robinson';
myConsole.warn(`Danger ${name}! Danger!`);
// Prints: Danger Will Robinson! Danger!, to err

@seesource

console
.
Console.log(message?: any, ...optionalParams: any[]): void

Prints to stdout with newline. Multiple arguments can be passed, with the first used as the primary message and all additional used as substitution values similar to printf(3) (the arguments are all passed to util.format()).

const count = 5;
console.log('count: %d', count);
// Prints: count: 5, to stdout
console.log('count:', count);
// Prints: count: 5, to stdout

See util.format() for more information.

@sincev0.1.100

log
(
import DateTime
DateTime
.
const distanceDurationEither: (self: DateTime.DateTime, other: DateTime.DateTime) => Either<Duration, Duration> (+1 overload)

Calulate the difference between two DateTime values.

If the other DateTime is before self, the result will be a negative Duration, returned as a Left.

If the other DateTime is after self, the result will be a positive Duration, returned as a Right.

@since3.6.0

@example

import { DateTime, Effect } from "effect"
Effect.gen(function* () {
const now = yield* DateTime.now
const other = DateTime.add(now, { minutes: 1 })
// returns Either.right(Duration.minutes(1))
DateTime.distanceDurationEither(now, other)
// returns Either.left(Duration.minutes(1))
DateTime.distanceDurationEither(other, now)
})

distanceDurationEither
(
const utc1: DateTime.Utc
utc1
,
const utc2: DateTime.Utc
utc2
))
/*
Output:
{
_id: 'Either',
_tag: 'Right',
right: { _id: 'Duration', _tag: 'Millis', millis: 86400000 }
}
*/
var console: Console

The console module provides a simple debugging console that is similar to the JavaScript console mechanism provided by web browsers.

The module exports two specific components:

  • A Console class with methods such as console.log(), console.error() and console.warn() that can be used to write to any Node.js stream.
  • A global console instance configured to write to process.stdout and process.stderr. The global console can be used without importing the node:console module.

Warning: The global console object's methods are neither consistently synchronous like the browser APIs they resemble, nor are they consistently asynchronous like all other Node.js streams. See the note on process I/O for more information.

Example using the global console:

console.log('hello world');
// Prints: hello world, to stdout
console.log('hello %s', 'world');
// Prints: hello world, to stdout
console.error(new Error('Whoops, something bad happened'));
// Prints error message and stack trace to stderr:
// Error: Whoops, something bad happened
// at [eval]:5:15
// at Script.runInThisContext (node:vm:132:18)
// at Object.runInThisContext (node:vm:309:38)
// at node:internal/process/execution:77:19
// at [eval]-wrapper:6:22
// at evalScript (node:internal/process/execution:76:60)
// at node:internal/main/eval_string:23:3
const name = 'Will Robinson';
console.warn(`Danger ${name}! Danger!`);
// Prints: Danger Will Robinson! Danger!, to stderr

Example using the Console class:

const out = getStreamSomehow();
const err = getStreamSomehow();
const myConsole = new console.Console(out, err);
myConsole.log('hello world');
// Prints: hello world, to out
myConsole.log('hello %s', 'world');
// Prints: hello world, to out
myConsole.error(new Error('Whoops, something bad happened'));
// Prints: [Error: Whoops, something bad happened], to err
const name = 'Will Robinson';
myConsole.warn(`Danger ${name}! Danger!`);
// Prints: Danger Will Robinson! Danger!, to err

@seesource

console
.
Console.log(message?: any, ...optionalParams: any[]): void

Prints to stdout with newline. Multiple arguments can be passed, with the first used as the primary message and all additional used as substitution values similar to printf(3) (the arguments are all passed to util.format()).

const count = 5;
console.log('count: %d', count);
// Prints: count: 5, to stdout
console.log('count:', count);
// Prints: count: 5, to stdout

See util.format() for more information.

@sincev0.1.100

log
(
import DateTime
DateTime
.
const distanceDuration: (self: DateTime.DateTime, other: DateTime.DateTime) => Duration (+1 overload)

Calulate the distance between two DateTime values.

@since3.6.0

@example

import { DateTime, Effect } from "effect"
Effect.gen(function* () {
const now = yield* DateTime.now
const other = DateTime.add(now, { minutes: 1 })
// returns Duration.minutes(1)
DateTime.distanceDuration(now, other)
})

distanceDuration
(
const utc1: DateTime.Utc
utc1
,
const utc2: DateTime.Utc
utc2
))
// Output: { _id: 'Duration', _tag: 'Millis', millis: 86400000 }
FunctionDescription
toDateUtcReturns a JavaScript Date in UTC.
toDateApplies the time zone (if present) and converts to a JavaScript Date.
zonedOffsetFor a Zoned DateTime, returns the time zone offset in ms.
zonedOffsetIsoFor a Zoned DateTime, returns an ISO offset string like “+01:00”.
toEpochMillisReturns the Unix epoch time in milliseconds.
removeTimeReturns a Utc with the time cleared (only date remains).
FunctionDescription
toPartsReturns time zone adjusted date parts (including weekday).
toPartsUtcReturns UTC date parts (including weekday).
getPart / getPartUtcRetrieves a specific part (e.g., "year" or "month") from the date.
setParts / setPartsUtcUpdates certain parts of a date, preserving or ignoring the time zone.

Example (Extracting Parts from a DateTime)

import {
import DateTime
DateTime
} from "effect"
const
const zoned: DateTime.Zoned
zoned
=
import DateTime
DateTime
.
const setZone: (self: DateTime.DateTime, zone: DateTime.TimeZone, options?: {
readonly adjustForTimeZone?: boolean | undefined;
}) => DateTime.Zoned (+1 overload)

Set the time zone of a DateTime, returning a new DateTime.Zoned.

@since3.6.0

@example

import { DateTime, Effect } from "effect"
Effect.gen(function* () {
const now = yield* DateTime.now
const zone = DateTime.zoneUnsafeMakeNamed("Europe/London")
// set the time zone
const zoned: DateTime.Zoned = DateTime.setZone(now, zone)
})

setZone
(
import DateTime
DateTime
.
const unsafeMake: <"2024-01-01">(input: "2024-01-01") => DateTime.Utc

Create a DateTime from one of the following:

  • A DateTime
  • A Date instance (invalid dates will throw an IllegalArgumentException)
  • The number of milliseconds since the Unix epoch
  • An object with the parts of a date
  • A string that can be parsed by Date.parse

@since3.6.0

@example

import { DateTime } from "effect"
// from Date
DateTime.unsafeMake(new Date())
// from parts
DateTime.unsafeMake({ year: 2024 })
// from string
DateTime.unsafeMake("2024-01-01")

unsafeMake
("2024-01-01"),
import DateTime
DateTime
.
const zoneUnsafeMakeNamed: (zoneId: string) => DateTime.TimeZone.Named

Attempt to create a named time zone from a IANA time zone identifier.

If the time zone is invalid, an IllegalArgumentException will be thrown.

@since3.6.0

zoneUnsafeMakeNamed
("Europe/Rome")
)
var console: Console

The console module provides a simple debugging console that is similar to the JavaScript console mechanism provided by web browsers.

The module exports two specific components:

  • A Console class with methods such as console.log(), console.error() and console.warn() that can be used to write to any Node.js stream.
  • A global console instance configured to write to process.stdout and process.stderr. The global console can be used without importing the node:console module.

Warning: The global console object's methods are neither consistently synchronous like the browser APIs they resemble, nor are they consistently asynchronous like all other Node.js streams. See the note on process I/O for more information.

Example using the global console:

console.log('hello world');
// Prints: hello world, to stdout
console.log('hello %s', 'world');
// Prints: hello world, to stdout
console.error(new Error('Whoops, something bad happened'));
// Prints error message and stack trace to stderr:
// Error: Whoops, something bad happened
// at [eval]:5:15
// at Script.runInThisContext (node:vm:132:18)
// at Object.runInThisContext (node:vm:309:38)
// at node:internal/process/execution:77:19
// at [eval]-wrapper:6:22
// at evalScript (node:internal/process/execution:76:60)
// at node:internal/main/eval_string:23:3
const name = 'Will Robinson';
console.warn(`Danger ${name}! Danger!`);
// Prints: Danger Will Robinson! Danger!, to stderr

Example using the Console class:

const out = getStreamSomehow();
const err = getStreamSomehow();
const myConsole = new console.Console(out, err);
myConsole.log('hello world');
// Prints: hello world, to out
myConsole.log('hello %s', 'world');
// Prints: hello world, to out
myConsole.error(new Error('Whoops, something bad happened'));
// Prints: [Error: Whoops, something bad happened], to err
const name = 'Will Robinson';
myConsole.warn(`Danger ${name}! Danger!`);
// Prints: Danger Will Robinson! Danger!, to err

@seesource

console
.
Console.log(message?: any, ...optionalParams: any[]): void

Prints to stdout with newline. Multiple arguments can be passed, with the first used as the primary message and all additional used as substitution values similar to printf(3) (the arguments are all passed to util.format()).

const count = 5;
console.log('count: %d', count);
// Prints: count: 5, to stdout
console.log('count:', count);
// Prints: count: 5, to stdout

See util.format() for more information.

@sincev0.1.100

log
(
import DateTime
DateTime
.
const getPart: (self: DateTime.DateTime, part: keyof DateTime.DateTime.PartsWithWeekday) => number (+1 overload)

Get a part of a DateTime as a number.

The part will be time zone adjusted.

@since3.6.0

@example

import { DateTime } from "effect"
const now = DateTime.unsafeMakeZoned({ year: 2024 }, { timeZone: "Europe/London" })
const year = DateTime.getPart(now, "year")
assert.strictEqual(year, 2024)

getPart
(
const zoned: DateTime.Zoned
zoned
, "month"))
// Output: 1
FunctionDescription
addDurationAdds the given Duration to a DateTime.
subtractDurationSubtracts the given Duration from a DateTime.
addAdds numeric parts (e.g., { hours: 2 }) to a DateTime.
subtractSubtracts numeric parts.
startOfMoves a DateTime to the start of the given unit (e.g., the beginning of a day or month).
endOfMoves a DateTime to the end of the given unit.
nearestRounds a DateTime to the nearest specified unit.
FunctionDescription
formatFormats a DateTime as a string using the DateTimeFormat API.
formatLocalUses the system’s local time zone and locale for formatting.
formatUtcForces UTC formatting.
formatIntlUses a provided Intl.DateTimeFormat.
formatIsoReturns an ISO 8601 string in UTC.
formatIsoDateReturns an ISO date string, adjusted for the time zone.
formatIsoDateUtcReturns an ISO date string in UTC.
formatIsoOffsetFormats a Zoned as a string with an offset like “+01:00”.
formatIsoZonedFormats a Zoned in the form YYYY-MM-DDTHH:mm:ss.sss+HH:MM[Zone].
FunctionDescription
CurrentTimeZoneA service tag for the current time zone.
setZoneCurrentSets a DateTime to use the current time zone.
withCurrentZoneProvides an effect with a specified time zone.
withCurrentZoneLocalUses the system’s local time zone for the effect.
withCurrentZoneOffsetUses a fixed offset (in ms) for the effect.
withCurrentZoneNamedUses a named time zone identifier (e.g., “Europe/London”).
nowInCurrentZoneRetrieves the current time as a Zoned in the configured time zone.
layerCurrentZoneCreates a Layer providing the CurrentTimeZone service.
layerCurrentZoneOffsetCreates a Layer from a fixed offset.
layerCurrentZoneNamedCreates a Layer from a named time zone, failing if invalid.
layerCurrentZoneLocalCreates a Layer from the system’s local time zone.

Example (Using the Current Time Zone in an Effect)

import {
import DateTime
DateTime
,
import Effect

@since2.0.0

@since2.0.0

@since2.0.0

Effect
} from "effect"
// Retrieve the current time in the "Europe/London" time zone
const
const program: Effect.Effect<void, IllegalArgumentException, never>
program
=
import Effect

@since2.0.0

@since2.0.0

@since2.0.0

Effect
.
const gen: <YieldWrap<Effect.Effect<DateTime.Zoned, never, DateTime.CurrentTimeZone>>, void>(f: (resume: Effect.Adapter) => Generator<...>) => Effect.Effect<...> (+1 overload)

Provides a way to write effectful code using generator functions, simplifying control flow and error handling.

When to Use

Effect.gen allows you to write code that looks and behaves like synchronous code, but it can handle asynchronous tasks, errors, and complex control flow (like loops and conditions). It helps make asynchronous code more readable and easier to manage.

The generator functions work similarly to async/await but with more explicit control over the execution of effects. You can yield* values from effects and return the final result at the end.

@example

import { Effect } from "effect"
const addServiceCharge = (amount: number) => amount + 1
const applyDiscount = (
total: number,
discountRate: number
): Effect.Effect<number, Error> =>
discountRate === 0
? Effect.fail(new Error("Discount rate cannot be zero"))
: Effect.succeed(total - (total * discountRate) / 100)
const fetchTransactionAmount = Effect.promise(() => Promise.resolve(100))
const fetchDiscountRate = Effect.promise(() => Promise.resolve(5))
export const program = Effect.gen(function* () {
const transactionAmount = yield* fetchTransactionAmount
const discountRate = yield* fetchDiscountRate
const discountedAmount = yield* applyDiscount(
transactionAmount,
discountRate
)
const finalAmount = addServiceCharge(discountedAmount)
return `Final amount to charge: ${finalAmount}`
})

@since2.0.0

gen
(function* () {
const
const zonedNow: DateTime.Zoned
zonedNow
= yield*
import DateTime
DateTime
.
const nowInCurrentZone: Effect.Effect<DateTime.Zoned, never, DateTime.CurrentTimeZone>

Get the current time as a DateTime.Zoned, using the CurrentTimeZone.

@since3.6.0

@example

import { DateTime, Effect } from "effect"
Effect.gen(function* () {
// will use the "Europe/London" time zone
const now = yield* DateTime.nowInCurrentZone
}).pipe(DateTime.withCurrentZoneNamed("Europe/London"))

nowInCurrentZone
var console: Console

The console module provides a simple debugging console that is similar to the JavaScript console mechanism provided by web browsers.

The module exports two specific components:

  • A Console class with methods such as console.log(), console.error() and console.warn() that can be used to write to any Node.js stream.
  • A global console instance configured to write to process.stdout and process.stderr. The global console can be used without importing the node:console module.

Warning: The global console object's methods are neither consistently synchronous like the browser APIs they resemble, nor are they consistently asynchronous like all other Node.js streams. See the note on process I/O for more information.

Example using the global console:

console.log('hello world');
// Prints: hello world, to stdout
console.log('hello %s', 'world');
// Prints: hello world, to stdout
console.error(new Error('Whoops, something bad happened'));
// Prints error message and stack trace to stderr:
// Error: Whoops, something bad happened
// at [eval]:5:15
// at Script.runInThisContext (node:vm:132:18)
// at Object.runInThisContext (node:vm:309:38)
// at node:internal/process/execution:77:19
// at [eval]-wrapper:6:22
// at evalScript (node:internal/process/execution:76:60)
// at node:internal/main/eval_string:23:3
const name = 'Will Robinson';
console.warn(`Danger ${name}! Danger!`);
// Prints: Danger Will Robinson! Danger!, to stderr

Example using the Console class:

const out = getStreamSomehow();
const err = getStreamSomehow();
const myConsole = new console.Console(out, err);
myConsole.log('hello world');
// Prints: hello world, to out
myConsole.log('hello %s', 'world');
// Prints: hello world, to out
myConsole.error(new Error('Whoops, something bad happened'));
// Prints: [Error: Whoops, something bad happened], to err
const name = 'Will Robinson';
myConsole.warn(`Danger ${name}! Danger!`);
// Prints: Danger Will Robinson! Danger!, to err

@seesource

console
.
Console.log(message?: any, ...optionalParams: any[]): void

Prints to stdout with newline. Multiple arguments can be passed, with the first used as the primary message and all additional used as substitution values similar to printf(3) (the arguments are all passed to util.format()).

const count = 5;
console.log('count: %d', count);
// Prints: count: 5, to stdout
console.log('count:', count);
// Prints: count: 5, to stdout

See util.format() for more information.

@sincev0.1.100

log
(
const zonedNow: DateTime.Zoned
zonedNow
)
}).
Pipeable.pipe<Effect.Effect<void, never, DateTime.CurrentTimeZone>, Effect.Effect<void, IllegalArgumentException, never>>(this: Effect.Effect<...>, ab: (_: Effect.Effect<...>) => Effect.Effect<...>): Effect.Effect<...> (+21 overloads)
pipe
(
import DateTime
DateTime
.
const withCurrentZoneNamed: (zone: string) => <A, E, R>(effect: Effect.Effect<A, E, R>) => Effect.Effect<A, E | IllegalArgumentException, Exclude<R, DateTime.CurrentTimeZone>> (+1 overload)

Provide the CurrentTimeZone to an effect using an IANA time zone identifier.

If the time zone is invalid, it will fail with an IllegalArgumentException.

@since3.6.0

@example

import { DateTime, Effect } from "effect"
Effect.gen(function* () {
// will use the "Europe/London" time zone
const now = yield* DateTime.nowInCurrentZone
}).pipe(DateTime.withCurrentZoneNamed("Europe/London"))

withCurrentZoneNamed
("Europe/London"))
import Effect

@since2.0.0

@since2.0.0

@since2.0.0

Effect
.
const runFork: <void, IllegalArgumentException>(effect: Effect.Effect<void, IllegalArgumentException, never>, options?: RunForkOptions) => RuntimeFiber<...>

The foundational function for running effects, returning a "fiber" that can be observed or interrupted.

When to Use

runFork is used to run an effect in the background by creating a fiber. It is the base function for all other run functions. It starts a fiber that can be observed or interrupted.

Unless you specifically need a Promise or synchronous operation, runFork is a good default choice.

@example

// Title: Running an Effect in the Background
import { Effect, Console, Schedule, Fiber } from "effect"
// ┌─── Effect<number, never, never>
// ▼
const program = Effect.repeat(
Console.log("running..."),
Schedule.spaced("200 millis")
)
// ┌─── RuntimeFiber<number, never>
// ▼
const fiber = Effect.runFork(program)
setTimeout(() => {
Effect.runFork(Fiber.interrupt(fiber))
}, 500)

@since2.0.0

runFork
(
const program: Effect.Effect<void, IllegalArgumentException, never>
program
)
/*
Example Output:
DateTime.Zoned(2025-01-06T18:36:38.573+00:00[Europe/London])
*/