Skip to content

Commit

Permalink
Added TimeToPipe. It's a new feature that was requested here:
Browse files Browse the repository at this point in the history
  • Loading branch information
pedro-deleon committed Sep 12, 2021
1 parent 40cf409 commit 74d289f
Show file tree
Hide file tree
Showing 3 changed files with 1 addition and 12 deletions.
2 changes: 1 addition & 1 deletion src/ng-pipes/pipes/date/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@ export const DATE_PIPES = [TimeAgoPipe, TimeToPipe];
export class NgDatePipesModule {}

export { TimeAgoPipe } from './time-ago';
export {TimeToPipe} from './time-to.pipe';
export { TimeToPipe } from './time-to.pipe';
6 changes: 0 additions & 6 deletions src/ng-pipes/pipes/date/time-to.pipe.spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { TimeToPipe } from './time-to.pipe';


describe('TimeToPipe', () => {
let pipe: TimeToPipe;
const today = new Date();
Expand Down Expand Up @@ -45,7 +44,6 @@ describe('TimeToPipe', () => {
const fewYearsToString = 5 + ' years to';
const fewYearsToDate = new Date(new Date().setDate(new Date().getDate() + 366 * 5));


beforeAll(() => {
pipe = new TimeToPipe();
});
Expand Down Expand Up @@ -109,8 +107,4 @@ describe('TimeToPipe', () => {
it('should return 5 years to', () => {
expect(pipe.transform(fewYearsToDate)).toEqual(fewYearsToString);
});



});

5 changes: 0 additions & 5 deletions src/ng-pipes/pipes/date/time-to.pipe.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import { Pipe, PipeTransform } from '@angular/core';
name: 'timeTo',
})
export class TimeToPipe implements PipeTransform {

private static YEAR_MS: number = 1000 * 60 * 60 * 24 * 7 * 4 * 12;
private static MAPPER: any = [
{ single: 'next year', many: 'years', div: 1 },
Expand All @@ -20,8 +19,6 @@ export class TimeToPipe implements PipeTransform {
return 'Invalid date';
}



const future = inputDate.toDate ? inputDate.toDate() : inputDate.getTime();
const now = +new Date();
console.log(new Date(future));
Expand All @@ -31,7 +28,6 @@ export class TimeToPipe implements PipeTransform {
return 'in the past';
}


for (let i = 0, l = TimeToPipe.MAPPER.length, ms = future - now, div = TimeToPipe.YEAR_MS; i < l; i++) {
const elm = TimeToPipe.MAPPER[i];

Expand All @@ -43,5 +39,4 @@ export class TimeToPipe implements PipeTransform {

return 'just now';
}

}

0 comments on commit 74d289f

Please sign in to comment.