Skip to content

Commit

Permalink
Merge pull request #50 from systelab/adding-ne-method-format-date-sho…
Browse files Browse the repository at this point in the history
…rt-month

Adding ne method format date short month #49
  • Loading branch information
vinyulis committed Dec 3, 2020
2 parents 944fe31 + 03358bb commit c10b56b
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 1 deletion.
5 changes: 5 additions & 0 deletions projects/systelab-translate/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,11 @@ public formatMonthAndYear(date: Date): string
```
Returns the month in text and the year.

```javascript
public formatDateAndShortMonth(date: Date): string
```
Returns the day and the short month in text.

```javascript
public getDateFrom(date: Date)
```
Expand Down
2 changes: 1 addition & 1 deletion projects/systelab-translate/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"Translate",
"i18n"
],
"version": "9.0.0",
"version": "9.0.1",
"license": "MIT",
"homepage": "https://github.com/systelab/systelab-translate.git",
"repository": {
Expand Down
7 changes: 7 additions & 0 deletions projects/systelab-translate/src/lib/date-util/date-util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,13 @@ export class DateUtil {
return format(date, 'MMMM, yyyy', {locale: this.convertSystelabLocaleToDateFnsLocale(this.locale)});
}

public formatDateAndShortMonth(date: Date) {
if (!date) {
return undefined;
}
return format(date, 'd MMM', {locale: this.convertSystelabLocaleToDateFnsLocale(this.locale)});
}

public getDateFrom(date: Date) {
let d: Date = setHours(date, 0);
d = setMinutes(d, 0);
Expand Down
4 changes: 4 additions & 0 deletions projects/systelab-translate/src/lib/i18n.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,10 @@ export class I18nService {
return this.dateUtil.formatMonthAndYear(date);
}

public formatDateAndShortMonth(date: Date): string {
return this.dateUtil.formatDateAndShortMonth(date);
}

public getDateFrom(date: Date): Date {
return this.dateUtil.getDateFrom(date);
}
Expand Down
4 changes: 4 additions & 0 deletions projects/systelab-translate/src/test/date.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ describe('Date Service', () => {
.toBe('28/01/16');
expect(service.formatDateFullYear(date))
.toBe('28/01/2016');
expect(service.formatDateAndShortMonth(date))
.toBe('28 ene');
done();
})
});
Expand Down Expand Up @@ -171,6 +173,8 @@ describe('Date Service', () => {
.toBe(undefined);
expect(service.formatDateFullYear(date))
.toBe(undefined);
expect(service.formatDateAndShortMonth(date))
.toBe(undefined);
done();
});
});
Expand Down

0 comments on commit c10b56b

Please sign in to comment.