1.7.0 • Published 7 years ago

gb-date-formatter v1.7.0

Weekly downloads
4
License
MIT
Repository
github
Last release
7 years ago

gb-date-formatter

Build Status

A partial re-engineering of AngularJs's date formatting.

Install

$ npm install gb-date-formatter

API

To use the DateFormatter class in a TypeScript file

import { DateFormatter } from "gb-date-formatter";

const formatter = new DateFormatter();
console.log(formatter.format(new Date("1924-02-25T07:44:40.755Z"), "MMMM y"));
// February 1924

To use the DateFormatter class in a JavaScript file

var DateFormatter = require("gb-date-formatter").DateFormatter;

var formatter = new DateFormatter();
console.log(formatter.format(new Date("1924-02-25T07:44:40.755Z"), "MMMM y"));
// February 1924

To use the DateFormatter class in an Angular pipe

wrap the gb-date-formatter in an Angular Pipe

import { Pipe, PipeTransform } from '@angular/core';
import { DateFormatter, FormatString } from 'gb-date-formatter';

@Pipe({ name: 'gbCustomDate' })
export class CustomDatePipe implements PipeTransform {
  private static namedFormats: { [name: string]: FormatString; } = {
    medium: 'MMMM y',
    long: 'EEE MMM d, y h:mm a'
  };
  private formatter: DateFormatter = new DateFormatter('en-US');

  public transform(value: Date, fmt: string): string {
    return this.formatter.format(value, CustomDatePipe.namedFormats[fmt]);

  }
}

and add the directive to a template

<td [title]="friend.birthday | gbCustomDate:'long'">{{friend.birthday | gbCustomDate:'medium'}}</td>
1.7.0

7 years ago

1.6.0

7 years ago

1.5.1

7 years ago

1.5.0

7 years ago

1.4.0

8 years ago

1.3.0

8 years ago

1.2.2

8 years ago

1.2.1

8 years ago

1.2.0

8 years ago

1.1.0

8 years ago

1.0.0

8 years ago