https://github.com/srph/angular-timestamp-filter
:calendar: AngularJS filter which converts date to timestamp
https://github.com/srph/angular-timestamp-filter
Last synced: 4 months ago
JSON representation
:calendar: AngularJS filter which converts date to timestamp
- Host: GitHub
- URL: https://github.com/srph/angular-timestamp-filter
- Owner: srph
- Created: 2014-12-17T13:28:40.000Z (over 11 years ago)
- Default Branch: master
- Last Pushed: 2015-06-13T08:54:26.000Z (about 11 years ago)
- Last Synced: 2025-07-15T04:46:05.015Z (12 months ago)
- Language: JavaScript
- Homepage:
- Size: 226 KB
- Stars: 4
- Watchers: 1
- Forks: 4
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
angular-timestamp-filter
=====
[](https://travis-ci.org/srph/angular-timestamp-filter) [](http://badge.fury.io/bo/angular-srph-timestamp-filter) [](http://opensource.org/licenses/MIT)
Filter which parses date (```11/23/1996 12:23:42```) to timestamp.
For some reason, Angular's [```date``` filter](https://docs.angularjs.org/api/ng/filter/date) doesn't seem to be able to convert timestamp format `M-d-Y h:i:s` properly. This library allows you to convert your date (string or a Date instance) to a timestamp.
## Getting Started
### Requirements
Not sure if it works with versions Angular ```<=1.2```, but it should work fine (unless the ```Filter``` API changed) with Angular ```>=1.2```.
### Installation
```angular-timestamp-filter``` is available in [**bower**]
```bash
$ bower install angular-srph-timestamp-filter
```
While it is also possible to use a CDN (thanks to [RawGit](https://rawgit.com/)).
```html
```
Include the script in your template (replace ```path/to/``` with its proper path) after AngularJS.
```html
```
Add in the library's module to your module's dependencies:
```js
angular.module('your-app-name', [/** other deps */, 'srph.timestamp-filter']);
```
### Usage
Through html binding (delimiters ```{{}}```)
```html
{{ '11/23/1996' | timestamp }}
```
You can do the same thing with ```ng-bind```
```html
```
Or with ```$filter```
```js
MyController.$inject = ['$scope', '$filter'];
function MyController($scope, $filter) {
$scope.date = $filter('timestamp')('11/23/1996');
}
```
The most practical way to use this library is to integrate it with the ```date``` filter by Angular. For instance,
```html
{{ '11/23/1996 00:00:00' | timestamp | date: 'MMM d, yyyy' }}
```
## Compatibility
\* As of version `v0.1.0`, `angular-timestamp-filter` [now harmonically works with Firefox `Date.parse` issue with dashes](http://stackoverflow.com/questions/11516332/date-parse-results-in-nan).
I have no time as of now, but you can check if there are issues with ```Date.parse```.
## Changelog
See the [Changelog](https://github.com/srph/angular-timestamp-filter/blob/master/doc/changelog.md) file.
## Contribution
I'd suggest to submit an issue first before putting up a pull-request as this avoids closed pull-requests; no wasted work. Feel free to put up an issue or submit a pull-request!
Not obligatory, but **don't forget to add tests**!
### Building
Check the [Building docs](https://github.com/srph/angular-timestamp-filter/blob/master/doc/building.md).
## Acknowledgement
**angular-timestamp-filter** © 2015+, Kier Borromeo (srph). **angular-timestamp-filter** is released under the [MIT](mit-license.org) license.
> [srph.github.io](http://srph.github.io) ·
> GitHub [@srph](https://github.com/srph) ·
> Twitter [@_srph](https://twitter.com/_srph)