Skip to content

Commit

Permalink
fix docs
Browse files Browse the repository at this point in the history
  • Loading branch information
tim-smart committed Jul 19, 2024
1 parent ed39537 commit 0092e45
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 13 deletions.
20 changes: 10 additions & 10 deletions packages/effect/src/DateTime.ts
Original file line number Diff line number Diff line change
Expand Up @@ -397,8 +397,7 @@ export const fromInput = <A extends DateTime.Input>(input: A): DateTime.Preserve
}

/**
* Safely create a `DateTime` from a `Date`, returning `None` if the `Date` is
* invalid.
* Safely create a `DateTime` from a `Date`, returning `None` if the `Date` is invalid.
*
* @since 3.6.0
* @category constructors
Expand All @@ -408,7 +407,7 @@ export const fromDate: (date: Date) => Option.Option<DateTime.Utc> = Option.lift
/**
* Convert a partial `DateTime.Parts` into a `DateTime`.
*
* If a part is missing, it will default to `0`.
* If a part is missing, it will default to the smallest possible value. (months will start at 1, days at 1, hours at 0 etc.)
*
* @since 3.6.0
* @category constructors
Expand All @@ -418,7 +417,7 @@ export const fromParts = (parts: Partial<Exclude<DateTime.Parts, "weekDay">>): D
date.setUTCFullYear(
parts.year ?? 0,
parts.month ? parts.month - 1 : 0,
parts.day ?? 0
parts.day ?? 1
)
date.setUTCHours(
parts.hours ?? 0,
Expand Down Expand Up @@ -448,8 +447,7 @@ export const fromString = (input: string): Option.Option<DateTime.Utc> => fromDa
export const unsafeFromString = (input: string): DateTime.Utc => unsafeFromDate(new Date(input))

/**
* Get the current time using the `Clock` service and convert it to a
* `DateTime`.
* Get the current time using the `Clock` service and convert it to a `DateTime`.
*
* @since 3.6.0
* @category constructors
Expand Down Expand Up @@ -747,11 +745,13 @@ export const toPartsUtc = (self: DateTime.Input): DateTime.Parts => {
* @since 3.6.0
* @category conversions
* @example
* import { DataTime } from "effect"
* import { DateTime } from "effect"
*
* const now =
* const now = DateTime.fromParts({ year: 2024 })
* const year = DateTime.getPartUtc(now, "year")
* assert.strictEqual(year, 2024)
*/
export const toPartUtc: {
export const getPartUtc: {
(part: keyof DateTime.Parts): (self: DateTime.Input) => number
(self: DateTime.Input, part: keyof DateTime.Parts): number
} = dual(2, (self: DateTime.Input, part: keyof DateTime.Parts): number => toPartsUtc(self)[part])
Expand All @@ -764,7 +764,7 @@ export const toPartUtc: {
* @since 3.6.0
* @category conversions
*/
export const toPartAdjusted: {
export const getPartAdjusted: {
(part: keyof DateTime.Parts): (self: DateTime.WithZone) => number
(self: DateTime.WithZone, part: keyof DateTime.Parts): number
} = dual(2, (self: DateTime.WithZone, part: keyof DateTime.Parts): number => toPartsAdjusted(self)[part])
Expand Down
11 changes: 8 additions & 3 deletions packages/effect/test/DateTime.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ describe("DateTime", () => {
const start = DateTime.unsafeFromString("2024-03-15T12:00:00.000Z")
const end = DateTime.endOf(start, "week")
assert.strictEqual(end.toJSON(), "2024-03-16T23:59:59.999Z")
assert.strictEqual(DateTime.toPartUtc(end, "weekDay"), 6)
assert.strictEqual(DateTime.getPartUtc(end, "weekDay"), 6)
})

it("week last day", () => {
Expand Down Expand Up @@ -111,7 +111,7 @@ describe("DateTime", () => {
const start = DateTime.unsafeFromString("2024-03-15T12:00:00.000Z")
const end = DateTime.startOf(start, "week")
assert.strictEqual(end.toJSON(), "2024-03-10T00:00:00.000Z")
assert.strictEqual(DateTime.toPartUtc(end, "weekDay"), 0)
assert.strictEqual(DateTime.getPartUtc(end, "weekDay"), 0)
})

it("week first day", () => {
Expand Down Expand Up @@ -185,7 +185,12 @@ describe("DateTime", () => {
month: 12,
day: 25
})
console.log(DateTime.toDateUtc(date))
assert.strictEqual(date.toJSON(), "2024-12-25T00:00:00.000Z")
})

it("month is set correctly", () => {
const date = DateTime.fromParts({ year: 2024 })
assert.strictEqual(date.toJSON(), "2024-01-01T00:00:00.000Z")
})
})
})

0 comments on commit 0092e45

Please sign in to comment.