Skip to content

Instantly share code, notes, and snippets.

@Jylanthas
Created July 15, 2015 22:35
Show Gist options
  • Save Jylanthas/28df1a583278fd19bcdc to your computer and use it in GitHub Desktop.
Save Jylanthas/28df1a583278fd19bcdc to your computer and use it in GitHub Desktop.
<input class="form-control" type="text" unix-time-directive="timeFormat" ng-model="t.pickup_time">
.directive('unixTimeDirective', function(moment) {
function link(scope, element, attrs, ngModelController) {
var format = scope.$eval(attrs.unixTimeDirective);
scope.$watch(attrs.unixTimeDirective, function(value) {
format = value;
});
ngModelController.$parsers.push(function(data) {
return moment(data, format).unix();
});
ngModelController.$formatters.push(function(data) {
return moment.unix(data).format(format);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment