Skip to content

Commit 979e27f

Browse files
authored
Merge pull request #311 from UiPath/fix/df-luxon-absolute-time
fix: dateformat luxon absolute time
2 parents c9ab137 + a39eafd commit 979e27f

File tree

5 files changed

+29
-15
lines changed

5 files changed

+29
-15
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
# v14.4.1 (2023-02-15)
2+
* **dateformat** use luxon for absolute time if enabled
3+
14
# v14.4.0 (2023-02-13)
25
* **dateformat** fixes default luxon formatting
36

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "angular-components",
3-
"version": "14.4.0",
3+
"version": "14.4.1",
44
"author": {
55
"name": "UiPath Inc",
66
"url": "https://uipath.com"

projects/angular/directives/ui-dateformat/src/ui-dateformat.directive.ts

Lines changed: 22 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import 'moment-timezone';
22

33
import {
4-
DateTime,
5-
DateTimeFormatOptions,
4+
DateTime,
5+
DateTimeFormatOptions,
66
} from 'luxon';
77
import moment from 'moment';
88
import {
@@ -205,15 +205,15 @@ export class UiDateFormatDirective extends UiFormatDirective {
205205
if (!this.date) { return ''; }
206206
if (!(this.date instanceof Date)) { return this.date; }
207207

208-
const absoluteTime = this._isMomentFormat(this.dateFormat)
209-
? moment(this.date)
208+
let absoluteTime;
209+
210+
if (this._useLuxon) {
211+
absoluteTime = this._luxonAbsoluteTime(this.date);
212+
} else if (this._isStringFormat(this.dateFormat)) {
213+
absoluteTime = moment(this.date)
210214
.tz(this.timezone ?? resolveTimezone(this._options))
211-
.format(this.dateFormat)
212-
: DateTime
213-
.fromJSDate(this.date, {
214-
zone: this.timezone ?? resolveTimezone(this._options),
215-
})
216-
.toLocaleString(this.dateFormat);
215+
.format(this.dateFormat);
216+
}
217217

218218
return absoluteTime ?? '';
219219
}
@@ -304,7 +304,7 @@ export class UiDateFormatDirective extends UiFormatDirective {
304304
this._renderer.setAttribute(this._elementRef.nativeElement, 'data-title', this._timeForType(this.titleType));
305305
}
306306

307-
private _isMomentFormat(format: string | DateTimeFormatOptions): format is string {
307+
private _isStringFormat(format: string | DateTimeFormatOptions): format is string {
308308
return typeof format === 'string';
309309
}
310310

@@ -326,4 +326,15 @@ export class UiDateFormatDirective extends UiFormatDirective {
326326

327327
return value !== compareValue;
328328
};
329+
330+
private _luxonAbsoluteTime(date: Date) {
331+
const time = DateTime
332+
.fromJSDate(date, {
333+
zone: this.timezone ?? resolveTimezone(this._options),
334+
});
335+
336+
return this._isStringFormat(this.dateFormat)
337+
? time.toFormat(this.dateFormat)
338+
: time.toLocaleString(this.dateFormat);
339+
}
329340
}

projects/angular/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@uipath/angular",
3-
"version": "14.4.0",
3+
"version": "14.4.1",
44
"license": "MIT",
55
"author": {
66
"name": "UiPath Inc",

0 commit comments

Comments
 (0)