mirror of
https://gitlab.com/openstapps/openstapps.git
synced 2026-01-20 08:33:11 +00:00
refactor: use SwiperJS in schedule module
This commit is contained in:
27
src/app/util/date-from-index.pipe.ts
Normal file
27
src/app/util/date-from-index.pipe.ts
Normal file
@@ -0,0 +1,27 @@
|
||||
/*
|
||||
* Copyright (C) 2021 StApps
|
||||
* This program is free software: you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License as published by the Free
|
||||
* Software Foundation, version 3.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
||||
* more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along with
|
||||
* this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
import {Pipe, PipeTransform} from '@angular/core';
|
||||
import {Moment} from 'moment';
|
||||
|
||||
@Pipe({
|
||||
name: 'dateFromIndex',
|
||||
pure: true,
|
||||
})
|
||||
export class DateFromIndexPipe implements PipeTransform {
|
||||
transform(index: number, baseline: Moment): Moment {
|
||||
return baseline.clone().add(index, 'days');
|
||||
}
|
||||
}
|
||||
@@ -30,7 +30,16 @@ export class DateIsThisPipe implements PipeTransform {
|
||||
* Transform
|
||||
*/
|
||||
// tslint:disable-next-line:prefer-function-over-method
|
||||
transform(value: Moment, granularity: unitOfTime.StartOf): boolean {
|
||||
return value.isSame(moment(moment.now()), granularity);
|
||||
transform(
|
||||
value: Moment | string | number,
|
||||
granularity: unitOfTime.StartOf,
|
||||
): boolean {
|
||||
return (
|
||||
typeof value === 'string'
|
||||
? moment(value)
|
||||
: typeof value === 'number'
|
||||
? moment.unix(value)
|
||||
: value
|
||||
).isSame(moment(moment.now()), granularity);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,9 +17,20 @@ import {NgModule} from '@angular/core';
|
||||
import {ArrayLastPipe} from './array-last.pipe';
|
||||
import {DateIsThisPipe} from './date-is-today.pipe';
|
||||
import {NullishCoalescingPipe} from './nullish-coalecing.pipe';
|
||||
import {DateFromIndexPipe} from './date-from-index.pipe';
|
||||
|
||||
@NgModule({
|
||||
declarations: [ArrayLastPipe, DateIsThisPipe, NullishCoalescingPipe],
|
||||
exports: [ArrayLastPipe, DateIsThisPipe, NullishCoalescingPipe],
|
||||
declarations: [
|
||||
ArrayLastPipe,
|
||||
DateIsThisPipe,
|
||||
NullishCoalescingPipe,
|
||||
DateFromIndexPipe,
|
||||
],
|
||||
exports: [
|
||||
ArrayLastPipe,
|
||||
DateIsThisPipe,
|
||||
NullishCoalescingPipe,
|
||||
DateFromIndexPipe,
|
||||
],
|
||||
})
|
||||
export class UtilModule {}
|
||||
|
||||
Reference in New Issue
Block a user