ngx-moment
ngx-moment copied to clipboard
amFromUtc and amParse to accept a string or an array of strings with formats
Did you search for duplicate issue? [Yes]
Both implementation of pipes FromUtcPipe and ParsePipe, are not accepting format / formats as parameters, while moment instead provides the option.
from-utc.pipe.ts
import {Pipe, PipeTransform} from '@angular/core';
import * as moment from 'moment';
@Pipe({ name: 'amFromUtc' })
export class FromUtcPipe implements PipeTransform {
transform(value: any, ...args: string[]): any {
return moment.utc(value);
}
}
could return instead
import {Pipe, PipeTransform} from '@angular/core';
import * as moment from 'moment';
@Pipe({ name: 'amFromUtc' })
export class FromUtcPipe implements PipeTransform {
transform(value: any, formats: string|string[], ...args: string[]): any {
return moment.utc(value, formats);
}
}
the same is true for the ParsePipe which only accepts a string format and not an array:
parse.pipe.ts
import { Pipe, PipeTransform } from '@angular/core';
import * as moment from 'moment';
// under systemjs, moment is actually exported as the default export, so we account for that
const momentConstructor: (value?: any) => moment.Moment = (<any>moment).default || moment;
@Pipe({ name: 'amParse' })
export class ParsePipe implements PipeTransform {
transform(value: string, format: string): moment.Moment {
return moment(value, format);
}
}
while it could be:
import { Pipe, PipeTransform } from '@angular/core';
import * as moment from 'moment';
// under systemjs, moment is actually exported as the default export, so we account for that
const momentConstructor: (value?: any) => moment.Moment = (<any>moment).default || moment;
@Pipe({ name: 'amParse' })
export class ParsePipe implements PipeTransform {
transform(value: string, formats: string|string[]): moment.Moment {
return moment(value, formats);
}
}
Thanks! Can you please send a pull request (with relevant unit-tests for the new functionality) ?
If you need help in getting the unit tests to work just ping here and I'll try to help
Hi, I'll try my best to do it asap.
cheers
Any progress? This feature would be nice.
I submitted a PR https://github.com/urish/ngx-moment/pull/215