In my Firebase database, I store the following information:
Timestamp for the day a record was created in Firebase.
Terms entered by the user at the time of creation.
For instance, it may look like this:
1439612582756 // converts to: Aug 14, 2015
15 // Formats to: "Net 15" according to my code
The code snippet I am currently using is as follows:
<td>{{invoice.settings.created | date}}</td>
<td>{{invoice.settings.created + invoice.settings.terms | date}}</td>
I have added moment.js
and 'angular-moment.js' libraries to handle date formatting and manipulation, but I am struggling to add days to a given date without any preprocessing. Is there a way to create a custom filter to achieve this?
As you can see from the sample code above, my current implementation is not working as intended. Any guidance on how to solve this issue would be greatly appreciated!
UPDATE
After referring to the documentation on
http://momentjs.com/docs/#/durations/add/
, I attempted to create a new filter:
.filter('dateTerms', function() {
return function(created, terms) {
var a = moment.duration(created, 'd');
var b = moment.duration(terms, 'd');
return a.add(b).days();
}
})
However, when I apply this filter, I only get a result of 0
?
<td>{{invoice.settings.created | date}}</td>
<td>{{invoice.settings.terms | dateTerms}}</td> // This line
I suspect this is because I am passing only one variable to the filter. How can I pass two variables to make it work correctly?
UPDATE 2
Deciding to simplify things, I updated my filter as follows:
.filter('dateTerms', function() {
return function(input, created) {
var date = new Date(created*1000);
date.setDate(date.getDate() + input);
return (date.getMonth()+1)+'/'+ date.getDate() +'/'+date.getFullYear();
}
})
And in my HTML:
<td>{{invoice.settings.terms | dateTerms:1439746291480}}</td>
1439746291480 converts to `Aug 16, 2015`
This results in:
8/24/47601