GithubHelp home page GithubHelp logo

andrewpoyntz / time-ago-pipe Goto Github PK

View Code? Open in Web Editor NEW
128.0 6.0 68.0 169 KB

An Angular pipe for converting a date string into a time ago

License: MIT License

TypeScript 100.00%
timeago angular angular2 pipe aot-compatible

time-ago-pipe's Introduction

time-ago-pipe

Build Status npm npm GitHub issues npm

A really simple, lightweight Angular pipe for converting a date string into a time ago

Time Range Output
0 - 45 seconds a few seconds ago
45 - 90 seconds a minute ago
90 seconds - 45 minutes X minutes ago
45 - 90 minutes an hour ago
90 minutes - 22 hours X hours ago
22 - 36 hours a day ago
36 hours - 25 days X days ago
25 - 45 days a month ago
45 - 345 days X months ago
345 - 545 days (1.5 years) a year ago
546 days+ X years ago

Installation

npm install time-ago-pipe --save

Usage

It can be imported into your angular project, as you would for any other library.

In the @NgModule you want to use it in

import {TimeAgoPipe} from 'time-ago-pipe';

add "TimeAgoPipe" to your declarations

@NgModule({
	imports: [... etc ...],
	declarations: [..., TimeAgoPipe, ... ]
})

In your component templates you can just do:

<span>{{your_date | timeAgo}}</span>

where "your_date" is a local date string, which could be parsed by the standard Js Date()

If this value is null or not parsable as a date, then the pipe will display nothing

time-ago-pipe's People

Contributors

andrewpoyntz avatar arknotts avatar dfederm avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

time-ago-pipe's Issues

TimeAgoPipe does not compile with Angular 5

Hello,

i wanted to launch build in prod mode with ng build prod
i got this error:

ERROR in : Cannot determine the module for class TimeAgoPipe in /home/gh_action/cca-front-end/node_modules/time-ago-pipe/time-ago-pipe.d.ts! Add TimeAgoPipe to the NgModule to fix it. TypeError: Cannot read property 'flags' of undefined

dispite, it is imported and exported in my module.

here is my Project configuration after running ng -v


    _                      _                 ____ _     ___

  / △ \ | '_ \ / _` | | | | |/ _` | '__|   | |   | |    | |
 / ___ \| | | | (_| | |_| | | (_| | |      | |___| |___ | |
/_/   \_\_| |_|\__, |\__,_|_|\__,_|_|       \____|_____|___|
               |___/
    
Angular CLI: 1.7.4
Node: 14.17.5
OS: win32 x64
Angular: 5.2.11
... animations, common, compiler, compiler-cli, core, forms
... http, language-service, platform-browser
... platform-browser-dynamic, router
TimeAgoPipe version: 1.3.2
@angular/cdk: 5.2.5
@angular/cli: 1.7.4
@angular/material: 9.2.4
@angular-devkit/architect: 0.1102.14
@angular-devkit/build-angular: 0.1102.14
@angular-devkit/build-optimizer: 0.3.2
@angular-devkit/build-webpack: 0.1102.14
@angular-devkit/core: 0.3.2
@angular-devkit/schematics: 0.3.2
@ngtools/json-schema: 1.2.0
@ngtools/webpack: 1.10.2
@schematics/angular: 0.3.2
@schematics/package-update: 0.3.2
typescript: 2.5.3
webpack: 3.11.0

Error during --prod --aot build

Hello. I get error when I build as --prod --aot with angular cli. Here is console output.

ERROR in Error: Cannot determine the module for class TimeAgoPipe in D:/WorkSpace/improver/browser/node_modules/time-ago-pipe/time-ago-pipe.ts! Add TimeAgoPipe to the NgModule to fix it.
at syntaxError (D:\WorkSpace\improver\browser\node_modules@angular\compiler\bundles\compiler.umd.js:1729:34)
at analyzeAndValidateNgModules (D:\WorkSpace\improver\browser\node_modules@angular\compiler\bundles\compiler.umd.js:24306:15)
at AotCompiler.analyzeModulesAsync (D:\WorkSpace\improver\browser\node_modules@angular\compiler\bundles\compiler.umd.js:23937:46)
at CodeGenerator.codegen (D:\WorkSpace\improver\browser\node_modules@angular\compiler-cli\src\codegen.js:32:14)
at Function.NgTools_InternalApi_NG_2.codeGen (D:\WorkSpace\improver\browser\node_modules@angular\compiler-cli\src\ngtools_api.js:73:30)
at _donePromise.Promise.resolve.then (D:\WorkSpace\improver\browser\node_modules@ngtools\webpack\src\plugin.js:386:44)
at
at process._tickCallback (internal/process/next_tick.js:188:7)

webpack: Failed to compile.

Could auto update as time progresses

At the moment, it'll update whenever Angular 2's change detection runs, but maybe it shouldn't rely on this & auto update when time actually changes
the frequency of update time checks could be based on how long ago it was too - i.e. if the time was x hours ago, it probably doesn't make sense to check every minute!

Feature request: support for passing in a number to the pipe

Some IDEAs (latest Intellij) will complain when passing a number to the pipe (since its transform method accepts only a string)

Date's constructor does support passing a number, so in runtime this works. It also passes compilation by the angular template compiler, the only issue is IDEA warning and future risk angular template compiler may fail the compilation based on type checking

Suggested fix in pull request: #28

not exported member

Hi,
I have implement this pipe but showing this error.
node_modules/time-ago-pipe/time-ago-pipe"' has no exported member 'TimeAgoPipeModule'.
Is it work with angular5.
How to resolve..?

doesn't work with angular 9 version

I have an error in console, when try to import TimeAgoPipe and add to module declarations.

So, little "crutch" like that solved my problem

...
import { TimeAgoPipe } from 'time-ago-pipe';

@Pipe({
    name: 'timeAgo',
    pure: false
})
export class TimeAgoExtendsPipe extends TimeAgoPipe {}

@NgModule({
    declarations: [
        TimeAgoExtendsPipe,
...

Not Convert

cannot convert this format in ionic 3

/Date(1530357388933)/

Expression has changed after it was checked

Ocassionally, getting similiar errors:

Expression has changed after it was checked. Previous value: '16 minutes ago'. Current value: '17 minutes ago'.

I believe it is related to the pipe relaying on timer to support real-time scenario.
Is it possible to disable real-time updates?

"badly packaged library"

I'm seeing this error when doing AOT compilation:

ERROR in ./node_modules/time-ago-pipe/index.ts
Module build failed: Error: C:\Users\David\Code\...\node_modules\time-ago-pipe\index.ts is missing from the TypeScript compilation. Please make sure it is in your tsconfig via the 'files' or 'include' property.
The missing file seems to be part of a third party library. TS files in published libraries are often a sign of a badly packaged library. Please open an issue in the library repository to alert its author and ask them to package the library using the Angular Package Format (https://goo.gl/jB3GVv).

According to the error, it seems like the problem is that there's no JS in the package, so it's actually trying to compile the package as well when compiling my code, which shouldn't be done.

According to Google, the "right" way to package an Angular module is described here: https://goo.gl/jB3GVv

Divide by zero exception results in odd message

let seconds = Math.round(Math.abs((now.getTime() - d.getTime()) / 1000));

If those values are the same you get a message NAN years until it updates. We're able to generate this message because of some client side updates that remove any delay that would otherwise exist between fetching data on the server and displaying it.

testing component with pipe

Trying to test component but have error
{{[ERROR ->] moment | amTimeAgo }}

The pipe 'amTimeAgo' could not be found ("}}

TestBed.configureTestingModule({
  declarations: [
    Component,
    TimeAgoPipe
  ]
})
  .compileComponents();

}));

How I can test component with it?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.