<commit_before>// A solution for date and/or time user input, based on the
// http://eonasdan.github.io/bootstrap-datetimepicker jQuery plugin.
angular.module('DateTimePicker', []).
  /*
   * A directive for selecting dates and/or times.
   *
   * Usage:
   *   <date-time-picker ng-model="String expr"
   *                     ?options="Object expr">
   *   </date-time-picker>
   *
   * The ng-model expression must evaluate to one of the following:
   * * A string in ISO 8601 format. Example: '2015-04-15T12:11:17.139Z'
   * * Just the date portion of the above string. Example: '2015-04-15'
   * * Just the time portion of the above string. Example: 'T12:11:17.139Z'
   */
  directive('dateTimePicker', [
    function () {
      return {
        restrict: 'E',
        templateUrl: 'shared/directives/date_time_picker.html',
        replace: true,
        require: ['dateTimePicker', 'ngModel'],
        controller: 'DateTimePickerCtrl',

        scope: {
          options: '='
        },

        link: function (scope, element, attrs, ctrls) {
          var dateTimePicker = ctrls[0];
          var ngModel = ctrls[1];

          var input = $(element).find('input');
          var instance = input.datetimepicker(scope.options || {});
          var initialized = false;

          instance.on('dp.change', function () {
            if (!initialized) return;

            var viewValue = input.data('DateTimePicker').date();

            scope.$evalAsync(function () {
              ngModel.$setViewValue(viewValue);
            });
          });

          ngModel.$formatters.push(function (modelValue) {
            // If time only, add a dummy date portion to be able to parse and
            // display correctly.
            var fullModelValue = (modelValue[0] === 'T') ?
              moment(moment().format('YYYY-MM-DD') + modelValue) :
              moment(modelValue);

            input.data('DateTimePicker').date(fullModelValue);
            if (!initialized) initialized = true;

            return fullModelValue.format(dateTimePicker.format());
          });

          ngModel.$parsers.push(function (viewValue) {
            switch (dateTimePicker.granularity(dateTimePicker.format())) {
              case 1: // Date only
                return viewValue.format('YYYY-MM-DD');
              case 2: // Time only
                // Convoluted way to convert to UTC, but required
                var viewValueUtc = moment(viewValue).utc();
                return viewValueUtc.format('[T]hh:mm:ss.SSS[Z]');
              case 3: // Both
                return viewValue.toISOString();
              default:
                console.log('Invalid datetime granularity');
            }
          });
        }
      }
    }]).

  // Controller for the date-time-picker directive.
  controller('DateTimePickerCtrl', [
    '$scope',
    function ($scope) {
      // These cover all Moment.js possibilities
      var DATE_REGEXP = /MQdDeEwWYgG/;
      var TIME_REGEXP = /hHmsSxX/;
      var LOCALE_DATE_REGEXP = /^l{1,4}$/i;
      var LOCALE_TIME_REGEXP = /^(LT|LTS|lll|LLL|llll|LLLL)$/;<commit_msg>fixed some null related bugs in date-time-picker<commit_after>// A solution for date and/or time user input, based on the
// http://eonasdan.github.io/bootstrap-datetimepicker jQuery plugin.
angular.module('DateTimePicker', []).
  /*
   * A directive for selecting dates and/or times.
   *
   * Usage:
   *   <date-time-picker ng-model="String expr"
   *                     ?options="Object expr">
   *   </date-time-picker>
   *
   * The ng-model expression must evaluate to one of the following:
   * * A string in ISO 8601 format. Example: '2015-04-15T12:11:17.139Z'
   * * Just the date portion of the above string. Example: '2015-04-15'
   * * Just the time portion of the above string. Example: 'T12:11:17.139Z'
   */
  directive('dateTimePicker', [
    function () {
      return {
        restrict: 'E',
        templateUrl: 'shared/directives/date_time_picker.html',
        replace: true,
        require: ['dateTimePicker', 'ngModel'],
        controller: 'DateTimePickerCtrl',

        scope: {
          options: '='
        },

        link: function (scope, element, attrs, ctrls) {
          var dateTimePicker = ctrls[0];
          var ngModel = ctrls[1];

          var input = $(element).find('input');
          var instance = input.datetimepicker(scope.options || {});
          var initialized = false;

          instance.on('dp.change', function () {
            if (!initialized) return;

            var viewValue = input.data('DateTimePicker').date();

            scope.$evalAsync(function () {
              ngModel.$setViewValue(viewValue);
            });
          });

          ngModel.$formatters.push(function (modelValue) {
            var viewValue = null;

            if (modelValue) {
              // If time only, add dummy date portion to be able to parse and
              // display correctly.
              var fullModelValue = (modelValue[0] === 'T') ?
                moment(moment().format('YYYY-MM-DD') + modelValue) :
                moment(modelValue);

              // If condition is a hacky workaround for the plugin not having
              // been initialized after switching operators!
              // TODO Fix weird bug in date-time-picker
              if (input.data('DateTimePicker')) {
                input.data('DateTimePicker').date(fullModelValue);
              }

              viewValue = fullModelValue.format(dateTimePicker.format());
            } else {
              viewValue = null;
            }

            if (!initialized) initialized = true;

            return viewValue;
          });

          ngModel.$parsers.push(function (viewValue) {
            switch (dateTimePicker.granularity(dateTimePicker.format())) {
              case 1: // Date only
                return viewValue.format('YYYY-MM-DD');
              case 2: // Time only
                // Convoluted way to convert to UTC, but required
                var viewValueUtc = moment(viewValue).utc();
                return viewValueUtc.format('[T]hh:mm:ss.SSS[Z]');
              case 3: // Both
                return viewValue.toISOString();
              default:
                console.log('Invalid datetime granularity');
            }
          });
        }
      }
    }]).

  // Controller for the date-time-picker directive.
  controller('DateTimePickerCtrl', [
    '$scope',
    function ($scope) {
      // These cover all Moment.js possibilities
      var DATE_REGEXP = /MQdDeEwWYgG/;
      var TIME_REGEXP = /hHmsSxX/;
      var LOCALE_DATE_REGEXP = /^l{1,4}$/i;
      var LOCALE_TIME_REGEXP = /^(LT|LTS|lll|LLL|llll|LLLL)$/;
{'fraction_non_alphanumeric': 0.12393862654550872, 'fraction_numerical': 0.013704751973782214, 'mean_word_length': 1.9064935064935065, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3316449', 'n_tokens_mistral': 1970, 'n_tokens_neox': 1853, 'n_words': 456}