forked from helpers/handlebars-helpers
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ad1fa1c
commit b634004
Showing
1 changed file
with
8 additions
and
50 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,62 +1,20 @@ | ||
'use strict'; | ||
var Utils = require('../utils/utils'); | ||
var Dates = require('../utils/dates'); | ||
|
||
/** | ||
* Port of formatDate-js library (http://bit.ly/18eo2xw) | ||
* Expose `moment` helper | ||
*/ | ||
|
||
exports.formatDate = function(date, format) { | ||
date = new Date(date); | ||
return Dates.format(date, format); | ||
}; | ||
|
||
exports.now = function(format) { | ||
var date = new Date(); | ||
if (Utils.isUndefined(format)) { | ||
return date; | ||
} else { | ||
return Dates.format(date, format); | ||
} | ||
}; | ||
exports.moment = require('helper-moment'); | ||
|
||
/** | ||
* Modified version of http://bit.ly/18WwJYf | ||
* Expose `dateformat` helper | ||
*/ | ||
|
||
exports.timeago = function(date) { | ||
date = new Date(date); | ||
|
||
var seconds = Math.floor((new Date() - date) / 1000); | ||
var interval = Math.floor(seconds / 31536000); | ||
|
||
if (interval > 1) { | ||
return interval + ' years ago'; | ||
} | ||
|
||
interval = Math.floor(seconds / 2592000); | ||
if (interval > 1) { | ||
return interval + ' months ago'; | ||
} | ||
exports.dateformat = require('helper-dateformat'); | ||
|
||
interval = Math.floor(seconds / 86400); | ||
if (interval > 1) { | ||
return interval + ' days ago'; | ||
} | ||
|
||
interval = Math.floor(seconds / 3600); | ||
if (interval > 1) { | ||
return interval + ' hours ago'; | ||
} | ||
|
||
interval = Math.floor(seconds / 60); | ||
if (interval > 1) { | ||
return interval + ' minutes ago'; | ||
} | ||
/** | ||
* Expose `date` helper | ||
*/ | ||
|
||
if (Math.floor(seconds) === 0) { | ||
return 'Just now'; | ||
} else { | ||
return Math.floor(seconds) + ' seconds ago'; | ||
} | ||
}; | ||
exports.date = require('helper-date'); |