API Reference

DatePropertyAccessorclass

Date accessor implementation used by the index-value-accessor pipeline. It exposes a fixed set of Date parts (local and UTC variants) as named indexes and supports reading and updating those parts.

Import

import { DatePropertyAccessor } from '@rs-x/core';

Example

import {
  type DateProperty,
  InjectionContainer,
  RsXCoreInjectionTokens,
  RsXCoreModule,
  type IDatePropertyAccessor,
} from '@rs-x/core';

await InjectionContainer.load(RsXCoreModule);

const accessor = InjectionContainer.get<IDatePropertyAccessor>(
  RsXCoreInjectionTokens.IDatePropertyAccessor,
);

const date = new Date('2024-01-10T00:00:00.000Z');
const property: DateProperty = 'utcYear';

console.log(accessor.getValue(date, property)); // 2024
accessor.setValue(date, property, 2025);
console.log(accessor.getValue(date, property)); // 2025
console.log(accessor.hasValue(date, property)); // true

Constructor injection example

import { Inject, RsXCoreInjectionTokens, type IDatePropertyAccessor } from '@rs-x/core';

class MyConsumer {
  constructor(
    @Inject(RsXCoreInjectionTokens.IDatePropertyAccessor)
    private readonly dependency: IDatePropertyAccessor,
  ) {}
}

Members

6 members in this class.

applies
methodpublic
public applies(
  context: unknown,
  index: DateProperty
): boolean

Parameters

Name
Type
Required
context
unknown
required
index
DateProperty
required

Returns

boolean

getIndexes
methodpublic
public getIndexes(): IterableIterator<DateProperty>

Parameters

No parameters.

Returns

IterableIterator<DateProperty>

getResolvedValue
methodpublic
public getResolvedValue(
  context: Date,
  index: DateProperty
): unknown

Parameters

Name
Type
Required
context
Date
required
index
DateProperty
required

Returns

unknown

getValue
methodpublic
public getValue(
  date: Date,
  index: DateProperty
): unknown

Parameters

Name
Type
Required
date
Date
required
index
DateProperty
required

Returns

unknown

hasValue
methodpublic
public hasValue(
  context: Date,
  index: DateProperty
): boolean

Parameters

Name
Type
Required
context
Date
required
index
DateProperty
required

Returns

boolean

setValue
methodpublic
public setValue(
  date: Date,
  index: DateProperty,
  value: number
): void

Parameters

Name
Type
Required
date
Date
required
index
DateProperty
required
value
number
required

Returns

void