Hyperlinkv0.8.0-beta.28

DateTime

DateTime.mutateUtcconsteffect/DateTime.ts:2128
(f: (date: Date) => void): <A extends DateTime>(self: A) => A
<A extends DateTime>(self: A, f: (date: Date) => void): A

Modifies a DateTime with a mutable UTC Date copy.

When to use

Use to adjust the instant with an existing Date mutation API that works on UTC calendar fields.

Example (Mutating DateTime values with UTC Dates)

import { DateTime } from "effect"

const dt = DateTime.makeZonedUnsafe("2024-01-01T12:00:00Z", {
  timeZone: "Europe/London"
})

const modified = DateTime.mutateUtc(dt, (date) => {
  date.setUTCHours(18) // Set UTC time to 6 PM
})

console.log(DateTime.formatIso(modified)) // "2024-01-01T18:00:00.000Z"
mapping
export const mutateUtc: {
  (f: (date: Date) => void): <A extends DateTime>(self: A) => A
  <A extends DateTime>(self: A, f: (date: Date) => void): A
} = Internal.mutateUtc