| 1234567891011121314151617181920212223242526272829303132333435363738394041 |
- ///<reference path="../../../headers/common.d.ts" />
- import _ from 'lodash';
- import angular from 'angular';
- import moment from 'moment';
- export function inputDateDirective() {
- return {
- restrict: 'A',
- require: 'ngModel',
- link: function ($scope, $elem, attrs, ngModel) {
- var format = 'YYYY-MM-DD HH:mm:ss';
- var fromUser = function (text) {
- if (text.indexOf('now') !== -1) {
- return text;
- }
- var parsed;
- if ($scope.ctrl.isUtc) {
- parsed = moment.utc(text, format);
- } else {
- parsed = moment(text, format);
- }
- return parsed.isValid() ? parsed : undefined;
- };
- var toUser = function (currentValue) {
- if (moment.isMoment(currentValue)) {
- return currentValue.format(format);
- } else {
- return currentValue;
- }
- };
- ngModel.$parsers.push(fromUser);
- ngModel.$formatters.push(toUser);
- }
- };
- }
|