📝DateEx

The module that handles date and time operations.

Imports

import { DateExService } from 'niro-health';

Environment Variables

name
description

TZ

Time zone of the application.

Write .env file with environment variable. Below has an example:

.env
TZ=America/Sao_Paulo

Method of Use

To use this module, you need to inject it into the desired service.

import { Module } from '@nestjs/common';
import {
  DateExService,
  ConfigurationService,
  ValidatorRegexpService,
  StringExService,
} from 'niro-health';
import { AppController } from './app.controller';
import { AppService } from './app.service';

@Module({
  controllers: [AppController],
  providers: [
    AppService,
    {
      provide: 'IDateExService',
      useClass: DateExService,
    },
    {
      provide: 'IConfigurationService',
      useClass: ConfigurationService,
    },
    {
      provide: 'IValidatorRegexpService',
      useClass: ValidatorRegexpService,
    },
    {
      provide: 'IStringExService',
      useClass: StringExService,
    },
  ],
})
export class AppModule {}

Injecting the module into our service.

import { Inject, Injectable } from '@nestjs/common';
import type { IDateExService } from 'niro-health';

@Injectable()
export class AppService {
  constructor(
    @Inject('IDateExService')
    private readonly dateExService: IDateExService,
  ) {}

  public now() {
    return this.dateExService.now;
  }
}

With dependencies

You will need to inject the following interfaces.

Interface
Service

IConfigurationService

IValidatorRegexpService

IStringExService

Properties

Property
Scope
Description

get now

public

Returns the current date and time.

get utc

public

Returns the current date and time in UTC.

get sevenDaysAgo

public

Returns the date with the subtraction of seven days.

get sevenDaysFromNow

public

Returns the date with the addition of seven days.

get oneMonthAgo

public

Returns the date with the subtraction of one month.

get oneMonthFromNow

public

Returns the date with the addition of one month.

get oneYearAgo

public

Returns the date with the subtraction of one year.

get oneYearFromNow

public

Returns the date with the addition of one year.

Methods

Method
Scope
Description

moment

public

Returns a new moment object, which is a wrapper for the Date object.

Last updated