<commit_before>// Copyright (c) 2016, the Dart project authors.  Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.

import 'dart:async';
import 'dart:html';

import 'package:angular/angular.dart';
import 'package:intl/intl.dart';
import 'package:quiver/time.dart';
import 'package:angular_components/interfaces/has_disabled.dart';
import 'package:angular_components/material_datepicker/module.dart';
import 'package:angular_components/material_input/material_input.dart';
import 'package:angular_components/material_select/material_dropdown_select.dart';
import 'package:angular_components/model/a11y/keyboard_handler_mixin.dart';
import 'package:angular_components/model/selection/select.dart';
import 'package:angular_components/model/selection/selection_model.dart';
import 'package:angular_components/model/selection/string_selection_options.dart';
import 'package:angular_components/utils/disposer/disposer.dart';

/// A material-design-styled time input component.
@Component(
  selector: 'material-time-picker',
  changeDetection: ChangeDetectionStrategy.OnPush,
  directives: [
    MaterialDropdownSelectComponent,
    materialInputDirectives,
    NgStyle,
  ],
  providers: [
    Provider(HasDisabled, useExisting: MaterialTimePickerComponent),
  ],
  templateUrl: 'material_time_picker.html',
  styleUrls: ['material_time_picker.scss.css'],
)
class MaterialTimePickerComponent extends KeyboardHandlerMixin
    implements HasDisabled, OnInit, OnDestroy {
  static DateTime _utcTime(int hour, [int minute = 0]) => DateTime.utc(
      _unixEpoch.year, _unixEpoch.month, _unixEpoch.day, hour, minute);

  static DateTime _localTime(int hour, [int minute = 0]) =>
      DateTime(_unixEpoch.year, _unixEpoch.month, _unixEpoch.day, hour, minute);

  static DateTime _withEpochDate(DateTime input) {
    if (input == null) return null;
    return input.isUtc
        ? _utcTime(input.hour, input.minute)
        : _localTime(input.hour, input.minute);
  }

  static final _unixEpoch = DateTime(1970, DateTime.january, 1, 0, 0);
  static final _supportedTimeFormats = [
    DateFormat.jm(),
    DateFormat.Hm(),
    DateFormat.jms(),
    DateFormat.Hms()
  ];

  final Clock _clock;
  final _disposer = Disposer.oneShot();
  final _timeChangeController = StreamController<DateTime>.broadcast();
  DateTime _time;
  bool displayErrorPanel;
  String inputError;

  /// The format used to format time.
  ///
  /// Defaults to `jm`, e.g. '5:08 PM'.
  @Input()
  DateFormat outputFormat = DateFormat.jm();

  /// The selected time.
  ///
  /// Date part sets to epoch(1970-1-1).
  @Input()
  set time(DateTime value) {
    value = utc ? value?.toUtc() : value?.toLocal();
    if ((value?.hour != _time?.hour ||
        value?.minute != _time?.minute ||
        value?.isUtc != _time?.isUtc)) {
      _time = value;
      _timeChangeController.add(time);
    }
    setInputErrorText(_validateTime(time));
    timeInputText = time == null ? "" : renderTime(time);
  }
<commit_msg>SelectedTime is not reset when the time is set programmatically.<commit_after>// Copyright (c) 2016, the Dart project authors.  Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.

import 'dart:async';
import 'dart:html';

import 'package:angular/angular.dart';
import 'package:intl/intl.dart';
import 'package:quiver/time.dart';
import 'package:angular_components/interfaces/has_disabled.dart';
import 'package:angular_components/material_datepicker/module.dart';
import 'package:angular_components/material_input/material_input.dart';
import 'package:angular_components/material_select/material_dropdown_select.dart';
import 'package:angular_components/model/a11y/keyboard_handler_mixin.dart';
import 'package:angular_components/model/selection/select.dart';
import 'package:angular_components/model/selection/selection_model.dart';
import 'package:angular_components/model/selection/string_selection_options.dart';
import 'package:angular_components/utils/disposer/disposer.dart';

/// A material-design-styled time input component.
@Component(
  selector: 'material-time-picker',
  changeDetection: ChangeDetectionStrategy.OnPush,
  directives: [
    MaterialDropdownSelectComponent,
    materialInputDirectives,
    NgStyle,
  ],
  providers: [
    Provider(HasDisabled, useExisting: MaterialTimePickerComponent),
  ],
  templateUrl: 'material_time_picker.html',
  styleUrls: ['material_time_picker.scss.css'],
)
class MaterialTimePickerComponent extends KeyboardHandlerMixin
    implements HasDisabled, OnInit, OnDestroy {
  static DateTime _utcTime(int hour, [int minute = 0]) => DateTime.utc(
      _unixEpoch.year, _unixEpoch.month, _unixEpoch.day, hour, minute);

  static DateTime _localTime(int hour, [int minute = 0]) =>
      DateTime(_unixEpoch.year, _unixEpoch.month, _unixEpoch.day, hour, minute);

  static DateTime _withEpochDate(DateTime input) {
    if (input == null) return null;
    return input.isUtc
        ? _utcTime(input.hour, input.minute)
        : _localTime(input.hour, input.minute);
  }

  static final _unixEpoch = DateTime(1970, DateTime.january, 1, 0, 0);
  static final _supportedTimeFormats = [
    DateFormat.jm(),
    DateFormat.Hm(),
    DateFormat.jms(),
    DateFormat.Hms()
  ];

  final Clock _clock;
  final _disposer = Disposer.oneShot();
  final _timeChangeController = StreamController<DateTime>.broadcast();
  DateTime _time;
  bool displayErrorPanel;
  String inputError;

  /// The format used to format time.
  ///
  /// Defaults to `jm`, e.g. '5:08 PM'.
  @Input()
  DateFormat outputFormat = DateFormat.jm();

  /// The selected time.
  ///
  /// Date part sets to epoch(1970-1-1).
  @Input()
  set time(DateTime value) {
    value = utc ? value?.toUtc() : value?.toLocal();
    if ((value?.hour != _time?.hour ||
        value?.minute != _time?.minute ||
        value?.isUtc != _time?.isUtc)) {
      _time = value;
      selectedTime.clear();
      _timeChangeController.add(time);
    }
    setInputErrorText(_validateTime(time));
    timeInputText = time == null ? "" : renderTime(time);
  }

{'fraction_non_alphanumeric': 0.1206262981306918, 'fraction_numerical': 0.007668956702348618, 'mean_word_length': 4.391903531438415, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 9, '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': '1209626', 'n_tokens_mistral': 1986, 'n_tokens_neox': 1930, 'n_words': 434}