> For the complete documentation index, see [llms.txt](https://guilhermesantos.gitbook.io/niro-health/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://guilhermesantos.gitbook.io/niro-health/modules/dateex.md).

# DateEx

The module that handles date and time operations.

### Imports

{% tabs %}
{% tab title="Service" %}

```typescript
import { DateExService } from 'niro-health';
```

{% endtab %}

{% tab title="Module" %}

```typescript
import { DateExModule } from 'niro-health';
```

{% endtab %}

{% tab title="Interface" %}

```typescript
import type { IDateExService } from 'niro-health';
```

{% endtab %}
{% endtabs %}

### Environment Variables

<table><thead><tr><th width="260">name</th><th>description</th></tr></thead><tbody><tr><td><code>TZ</code></td><td><code>Time zone of the application.</code></td></tr></tbody></table>

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

{% code title=".env" %}

```bash
TZ=America/Sao_Paulo
```

{% endcode %}

### Method of Use

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

{% code overflow="wrap" %}

```typescript
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 {}
```

{% endcode %}

Injecting the module into our service.

```typescript
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.

<table><thead><tr><th width="308">Interface</th><th>Service</th></tr></thead><tbody><tr><td><code>IConfigurationService</code></td><td><a href="/niro-health/modules/configuration.md">Link to Service documentation</a></td></tr><tr><td><code>IValidatorRegexpService</code></td><td><a href="/niro-health/modules/validator-regexp.md">Link to Service documentation</a></td></tr><tr><td><code>IStringExService</code></td><td><a href="/niro-health/modules/stringex.md">Link to Service documentation</a></td></tr></tbody></table>

### Properties

<table><thead><tr><th width="301.3333333333333">Property</th><th width="127" align="center">Scope</th><th>Description</th></tr></thead><tbody><tr><td><mark style="color:blue;"><strong>get</strong></mark> <code>now</code></td><td align="center"><code>public</code></td><td><code>Returns the current date and time.</code></td></tr><tr><td><mark style="color:blue;"><strong>get</strong></mark> <code>utc</code></td><td align="center"><code>public</code></td><td><code>Returns the current date and time in UTC.</code></td></tr><tr><td><mark style="color:blue;"><strong>get</strong></mark> <code>sevenDaysAgo</code></td><td align="center"><code>public</code></td><td><code>Returns the date with the subtraction of seven days.</code></td></tr><tr><td><mark style="color:blue;"><strong>get</strong></mark> <code>sevenDaysFromNow</code></td><td align="center"><code>public</code></td><td><code>Returns the date with the addition of seven days.</code></td></tr><tr><td><mark style="color:blue;"><strong>get</strong></mark> <code>oneMonthAgo</code></td><td align="center"><code>public</code></td><td><code>Returns the date with the subtraction of one month.</code></td></tr><tr><td><mark style="color:blue;"><strong>get</strong></mark> <code>oneMonthFromNow</code></td><td align="center"><code>public</code></td><td><code>Returns the date with the addition of one month.</code></td></tr><tr><td><mark style="color:blue;"><strong>get</strong></mark> <code>oneYearAgo</code></td><td align="center"><code>public</code></td><td><code>Returns the date with the subtraction of one year.</code></td></tr><tr><td><mark style="color:blue;"><strong>get</strong></mark> <code>oneYearFromNow</code></td><td align="center"><code>public</code></td><td><code>Returns the date with the addition of one year.</code></td></tr></tbody></table>

### Methods

<table><thead><tr><th width="301.3333333333333">Method</th><th width="129" align="center">Scope</th><th>Description</th></tr></thead><tbody><tr><td><code>moment</code></td><td align="center"><code>public</code></td><td><code>Returns a new moment object, which is a wrapper for the Date object.</code></td></tr></tbody></table>
