Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

amFromUtc and amParse to accept a string or an array of strings with formats #186

Open
gigadie opened this issue Jan 2, 2018 · 4 comments

Comments

@gigadie
Copy link
Contributor

gigadie commented Jan 2, 2018

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);
  }
}
@urish
Copy link
Owner

urish commented Jan 3, 2018

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

@gigadie
Copy link
Contributor Author

gigadie commented Jan 5, 2018

Hi,
I'll try my best to do it asap.

cheers

@rroex
Copy link

rroex commented May 16, 2018

Any progress? This feature would be nice.

@gigadie
Copy link
Contributor Author

gigadie commented Jul 31, 2019

I submitted a PR
#215

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants