mirror of
https://github.com/richard-loafle/fuse-angular.git
synced 2026-03-25 21:39:17 +00:00
Replace moment with luxon
This commit is contained in:
@@ -9,14 +9,13 @@ import { MatFormFieldModule } from '@angular/material/form-field';
|
||||
import { MatIconModule } from '@angular/material/icon';
|
||||
import { MatInputModule } from '@angular/material/input';
|
||||
import { MatMenuModule } from '@angular/material/menu';
|
||||
import { MatMomentDateModule } from '@angular/material-moment-adapter';
|
||||
import { MatLuxonDateModule, MAT_LUXON_DATE_FORMATS } from '@angular/material-luxon-adapter';
|
||||
import { MatProgressBarModule } from '@angular/material/progress-bar';
|
||||
import { MatRadioModule } from '@angular/material/radio';
|
||||
import { MatSelectModule } from '@angular/material/select';
|
||||
import { MatSidenavModule } from '@angular/material/sidenav';
|
||||
import { MatTableModule } from '@angular/material/table';
|
||||
import { MatTooltipModule } from '@angular/material/tooltip';
|
||||
import * as moment from 'moment';
|
||||
import { FuseFindByKeyPipeModule } from '@fuse/pipes/find-by-key';
|
||||
import { SharedModule } from 'app/shared/shared.module';
|
||||
import { contactsRoutes } from 'app/modules/admin/apps/contacts/contacts.routing';
|
||||
@@ -40,7 +39,7 @@ import { ContactsListComponent } from 'app/modules/admin/apps/contacts/list/list
|
||||
MatIconModule,
|
||||
MatInputModule,
|
||||
MatMenuModule,
|
||||
MatMomentDateModule,
|
||||
MatLuxonDateModule,
|
||||
MatProgressBarModule,
|
||||
MatRadioModule,
|
||||
MatRippleModule,
|
||||
@@ -54,17 +53,7 @@ import { ContactsListComponent } from 'app/modules/admin/apps/contacts/list/list
|
||||
providers : [
|
||||
{
|
||||
provide : MAT_DATE_FORMATS,
|
||||
useValue: {
|
||||
parse : {
|
||||
dateInput: moment.ISO_8601
|
||||
},
|
||||
display: {
|
||||
dateInput : 'LL',
|
||||
monthYearLabel : 'MMM YYYY',
|
||||
dateA11yLabel : 'LL',
|
||||
monthYearA11yLabel: 'MMMM YYYY'
|
||||
}
|
||||
}
|
||||
useValue: MAT_LUXON_DATE_FORMATS
|
||||
}
|
||||
]
|
||||
})
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
import { ChangeDetectionStrategy, ChangeDetectorRef, Component, OnDestroy, OnInit, ViewEncapsulation } from '@angular/core';
|
||||
import { UntypedFormBuilder, UntypedFormGroup } from '@angular/forms';
|
||||
import { CdkDragDrop, moveItemInArray, transferArrayItem } from '@angular/cdk/drag-drop';
|
||||
import { DateTime } from 'luxon';
|
||||
import { Subject, takeUntil } from 'rxjs';
|
||||
import * as moment from 'moment';
|
||||
import { FuseConfirmationService } from '@fuse/services/confirmation';
|
||||
import { ScrumboardService } from 'app/modules/admin/apps/scrumboard/scrumboard.service';
|
||||
import { Board, Card, List } from 'app/modules/admin/apps/scrumboard/scrumboard.models';
|
||||
@@ -243,7 +243,7 @@ export class ScrumboardBoardComponent implements OnInit, OnDestroy
|
||||
*/
|
||||
isOverdue(date: string): boolean
|
||||
{
|
||||
return moment(date, moment.ISO_8601).isBefore(moment(), 'days');
|
||||
return DateTime.fromISO(date).startOf('day') < DateTime.now().startOf('day');
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { ChangeDetectionStrategy, ChangeDetectorRef, Component, OnDestroy, OnInit, ViewEncapsulation } from '@angular/core';
|
||||
import { Subject, takeUntil } from 'rxjs';
|
||||
import * as moment from 'moment';
|
||||
import { DateTime } from 'luxon';
|
||||
import { Board } from 'app/modules/admin/apps/scrumboard/scrumboard.models';
|
||||
import { ScrumboardService } from 'app/modules/admin/apps/scrumboard/scrumboard.service';
|
||||
|
||||
@@ -68,7 +68,8 @@ export class ScrumboardBoardsComponent implements OnInit, OnDestroy
|
||||
*/
|
||||
formatDateAsRelative(date: string): string
|
||||
{
|
||||
return moment(date, moment.ISO_8601).fromNow();
|
||||
// not quite the same behavior as moment, which rounds up
|
||||
return DateTime.fromISO(date).toRelative();
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -3,7 +3,7 @@ import { UntypedFormBuilder, UntypedFormGroup, Validators } from '@angular/forms
|
||||
import { MatCheckboxChange } from '@angular/material/checkbox';
|
||||
import { MatDialogRef } from '@angular/material/dialog';
|
||||
import { debounceTime, Subject, takeUntil, tap } from 'rxjs';
|
||||
import * as moment from 'moment';
|
||||
import { DateTime } from 'luxon';
|
||||
import { assign } from 'lodash-es';
|
||||
import { ScrumboardService } from 'app/modules/admin/apps/scrumboard/scrumboard.service';
|
||||
import { Board, Card, Label } from 'app/modules/admin/apps/scrumboard/scrumboard.models';
|
||||
@@ -237,7 +237,7 @@ export class ScrumboardCardDetailsComponent implements OnInit, OnDestroy
|
||||
*/
|
||||
isOverdue(date: string): boolean
|
||||
{
|
||||
return moment(date, moment.ISO_8601).isBefore(moment(), 'days');
|
||||
return DateTime.fromISO(date).startOf('day') < DateTime.now().startOf('day');
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -10,9 +10,8 @@ import { MatFormFieldModule } from '@angular/material/form-field';
|
||||
import { MatIconModule } from '@angular/material/icon';
|
||||
import { MatInputModule } from '@angular/material/input';
|
||||
import { MatMenuModule } from '@angular/material/menu';
|
||||
import { MatMomentDateModule } from '@angular/material-moment-adapter';
|
||||
import { MatLuxonDateModule, MAT_LUXON_DATE_FORMATS } from '@angular/material-luxon-adapter';
|
||||
import { MatProgressBarModule } from '@angular/material/progress-bar';
|
||||
import * as moment from 'moment';
|
||||
import { SharedModule } from 'app/shared/shared.module';
|
||||
import { ScrumboardComponent } from 'app/modules/admin/apps/scrumboard/scrumboard.component';
|
||||
import { ScrumboardBoardsComponent } from 'app/modules/admin/apps/scrumboard/boards/boards.component';
|
||||
@@ -44,24 +43,14 @@ import { scrumboardRoutes } from 'app/modules/admin/apps/scrumboard/scrumboard.r
|
||||
MatIconModule,
|
||||
MatInputModule,
|
||||
MatMenuModule,
|
||||
MatMomentDateModule,
|
||||
MatLuxonDateModule,
|
||||
MatProgressBarModule,
|
||||
SharedModule
|
||||
],
|
||||
providers : [
|
||||
{
|
||||
provide : MAT_DATE_FORMATS,
|
||||
useValue: {
|
||||
parse : {
|
||||
dateInput: moment.ISO_8601
|
||||
},
|
||||
display: {
|
||||
dateInput : 'll',
|
||||
monthYearLabel : 'MMM YYYY',
|
||||
dateA11yLabel : 'LL',
|
||||
monthYearA11yLabel: 'MMMM YYYY'
|
||||
}
|
||||
}
|
||||
useValue: MAT_LUXON_DATE_FORMATS
|
||||
}
|
||||
]
|
||||
})
|
||||
|
||||
@@ -7,7 +7,7 @@ import { MatDrawerToggleResult } from '@angular/material/sidenav';
|
||||
import { FuseConfirmationService } from '@fuse/services/confirmation';
|
||||
import { debounceTime, filter, Subject, takeUntil, tap } from 'rxjs';
|
||||
import { assign } from 'lodash-es';
|
||||
import * as moment from 'moment';
|
||||
import { DateTime } from 'luxon';
|
||||
import { Tag, Task } from 'app/modules/admin/apps/tasks/tasks.types';
|
||||
import { TasksListComponent } from 'app/modules/admin/apps/tasks/list/list.component';
|
||||
import { TasksService } from 'app/modules/admin/apps/tasks/tasks.service';
|
||||
@@ -465,7 +465,7 @@ export class TasksDetailsComponent implements OnInit, AfterViewInit, OnDestroy
|
||||
*/
|
||||
isOverdue(): boolean
|
||||
{
|
||||
return moment(this.task.dueDate, moment.ISO_8601).isBefore(moment(), 'days');
|
||||
return DateTime.fromISO(this.task.dueDate).startOf('day') < DateTime.now().startOf('day');
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -11,13 +11,12 @@ import { MatFormFieldModule } from '@angular/material/form-field';
|
||||
import { MatIconModule } from '@angular/material/icon';
|
||||
import { MatInputModule } from '@angular/material/input';
|
||||
import { MatMenuModule } from '@angular/material/menu';
|
||||
import { MatMomentDateModule } from '@angular/material-moment-adapter';
|
||||
import { MatLuxonDateModule, MAT_LUXON_DATE_FORMATS } from '@angular/material-luxon-adapter';
|
||||
import { MatProgressBarModule } from '@angular/material/progress-bar';
|
||||
import { MatRadioModule } from '@angular/material/radio';
|
||||
import { MatSelectModule } from '@angular/material/select';
|
||||
import { MatSidenavModule } from '@angular/material/sidenav';
|
||||
import { MatTooltipModule } from '@angular/material/tooltip';
|
||||
import * as moment from 'moment';
|
||||
import { FuseFindByKeyPipeModule } from '@fuse/pipes/find-by-key';
|
||||
import { SharedModule } from 'app/shared/shared.module';
|
||||
import { tasksRoutes } from 'app/modules/admin/apps/tasks/tasks.routing';
|
||||
@@ -43,7 +42,7 @@ import { TasksListComponent } from 'app/modules/admin/apps/tasks/list/list.compo
|
||||
MatIconModule,
|
||||
MatInputModule,
|
||||
MatMenuModule,
|
||||
MatMomentDateModule,
|
||||
MatLuxonDateModule,
|
||||
MatProgressBarModule,
|
||||
MatRadioModule,
|
||||
MatRippleModule,
|
||||
@@ -56,17 +55,7 @@ import { TasksListComponent } from 'app/modules/admin/apps/tasks/list/list.compo
|
||||
providers : [
|
||||
{
|
||||
provide : MAT_DATE_FORMATS,
|
||||
useValue: {
|
||||
parse : {
|
||||
dateInput: moment.ISO_8601
|
||||
},
|
||||
display: {
|
||||
dateInput : 'll',
|
||||
monthYearLabel : 'MMM YYYY',
|
||||
dateA11yLabel : 'LL',
|
||||
monthYearA11yLabel: 'MMMM YYYY'
|
||||
}
|
||||
}
|
||||
useValue: MAT_LUXON_DATE_FORMATS
|
||||
}
|
||||
]
|
||||
})
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { ChangeDetectionStrategy, ChangeDetectorRef, Component, OnDestroy, OnInit, ViewChild, ViewEncapsulation } from '@angular/core';
|
||||
import { DateTime } from 'luxon';
|
||||
import { Subject, takeUntil } from 'rxjs';
|
||||
import * as moment from 'moment';
|
||||
import { ApexOptions, ChartComponent } from 'ng-apexcharts';
|
||||
import { FuseMediaWatcherService } from '@fuse/services/media-watcher';
|
||||
import { CryptoService } from 'app/modules/admin/dashboards/crypto/crypto.service';
|
||||
@@ -183,7 +183,7 @@ export class CryptoComponent implements OnInit, OnDestroy
|
||||
rotate : 0,
|
||||
minHeight : 40,
|
||||
hideOverlappingLabels: true,
|
||||
formatter : (value): string => moment().subtract(Math.abs(parseInt(value, 10)), 'minutes').format('HH:mm'),
|
||||
formatter : (value): string => DateTime.now().minus({ minutes: Math.abs(parseInt(value, 10)) }).toFormat('HH:mm'),
|
||||
style : {
|
||||
colors: 'currentColor'
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { ChangeDetectionStrategy, Component, OnInit, ViewEncapsulation } from '@angular/core';
|
||||
import { DateTime } from 'luxon';
|
||||
import { Observable } from 'rxjs';
|
||||
import * as moment from 'moment';
|
||||
import { Activity } from 'app/modules/admin/pages/activities/activities.types';
|
||||
import { ActivitiesService } from 'app/modules/admin/pages/activities/activities.service';
|
||||
|
||||
@@ -46,7 +46,8 @@ export class ActivitiesComponent implements OnInit
|
||||
*/
|
||||
isSameDay(current: string, compare: string): boolean
|
||||
{
|
||||
return moment(current, moment.ISO_8601).isSame(moment(compare, moment.ISO_8601), 'day');
|
||||
return DateTime.fromISO(current).hasSame(DateTime.fromISO(compare), 'day');
|
||||
// return moment(current, moment.ISO_8601).isSame(moment(compare, moment.ISO_8601), 'day');
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -56,22 +57,10 @@ export class ActivitiesComponent implements OnInit
|
||||
*/
|
||||
getRelativeFormat(date: string): string
|
||||
{
|
||||
const today = moment().startOf('day');
|
||||
const yesterday = moment().subtract(1, 'day').startOf('day');
|
||||
|
||||
// Is today?
|
||||
if ( moment(date, moment.ISO_8601).isSame(today, 'day') )
|
||||
{
|
||||
return 'Today';
|
||||
}
|
||||
|
||||
// Is yesterday?
|
||||
if ( moment(date, moment.ISO_8601).isSame(yesterday, 'day') )
|
||||
{
|
||||
return 'Yesterday';
|
||||
}
|
||||
|
||||
return moment(date, moment.ISO_8601).fromNow();
|
||||
const comp = DateTime.fromISO(date);
|
||||
const day = comp.toRelativeCalendar();
|
||||
// uppercase first letter
|
||||
return day[0].toUpperCase() + day.substring(1);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -9,7 +9,7 @@ import { MatFormFieldModule } from '@angular/material/form-field';
|
||||
import { MatIconModule } from '@angular/material/icon';
|
||||
import { MatInputModule } from '@angular/material/input';
|
||||
import { MatMenuModule } from '@angular/material/menu';
|
||||
import { MatMomentDateModule } from '@angular/material-moment-adapter';
|
||||
import { MatLuxonDateModule } from '@angular/material-luxon-adapter';
|
||||
import { MatSelectModule } from '@angular/material/select';
|
||||
import { FuseHighlightModule } from '@fuse/components/highlight';
|
||||
import { SharedModule } from 'app/shared/shared.module';
|
||||
@@ -37,7 +37,7 @@ export const routes: Route[] = [
|
||||
MatIconModule,
|
||||
MatInputModule,
|
||||
MatMenuModule,
|
||||
MatMomentDateModule,
|
||||
MatLuxonDateModule,
|
||||
MatSelectModule,
|
||||
FuseHighlightModule,
|
||||
SharedModule
|
||||
|
||||
Reference in New Issue
Block a user