Uploaded image for project: 'Titanium SDK/CLI'
  1. Titanium SDK/CLI
  2. TIMOB-26044

Android: Time picker "value" property does not retain assigned year/month/day like iOS

    Details

    • Story Points:
      3

      Description

      After thinking about it, perhaps this behavior is okay. If you want the year/month/day parts preserved, then you should be using the Ti.UI.PICKER_TYPE_DATE_AND_TIME type. Especially since one problem with preserving the date in a Ti.UI.PICKER_TYPE_TIME is it has a daylight savings time issue where 2 AM cannot be selected on a spring-forward day (such as 2018/03/11), which is currently the case for both Android and iOS. This behavior would be okay in a date-time picker, but perhaps not in a time-only picker.

      Summary:
      A Ti.UI.Picker of type PICKER_TYPE_TIME does not retain the originally assigned year, month, day, and seconds assigned to its value property. The date returned by value is always set to the current date (this is wrong), with the hour and minute components set to what's selected in the picker (this last part is fine).

      On iOS, all other date components (year, month, day, seconds) are preserved. Android should do the same.

      Test:

      1. Build and run the below code on Android.
      2. Tap the "Get Selected Time" button.
      3. An alert dialog displays the picker's current date and time. Note that the date is set to current day instead of the hardcoded 2018/01/01.

      var window = Ti.UI.createWindow();
      var picker = Ti.UI.createPicker({
      	type: Ti.UI.PICKER_TYPE_TIME,
      	value: new Date(2018, 0, 1, 12),
      });
      window.add(picker);
      var button = Ti.UI.createButton({
      	title: "Get Selected Time Value",
      	bottom: "20dp",
      });
      button.addEventListener("click", function(e) {
      	var date = picker.value;
      	var dialog = Ti.UI.createAlertDialog({
      		title: "Selected Time",
      		message: date.toString(),
      	});
      	dialog.show();
      });
      window.add(button);
      window.open();
      

      Note:
      This is an issue with Titanium's "TiUITimeSpinner" Java class...
      TiUITimeSpinner.java

      Work-Around:
      You can extract the hour and minute selected from the picker and recreate a date object with the correct time like this...

      var originalDate = new Date(2018, 0, 1, 12);
      picker.value = originalDate;
      picker.addEventListener("change", function(e) {
      	var newDate = new Date(originalDate.getTime());
      	newDate.setHours(picker.value.getHours());
      	newDate.setMinutes(picker.value.getMinutes());
      });
      

        Attachments

          Activity

            People

            • Assignee:
              jquick Joshua Quick
              Reporter:
              jquick Joshua Quick
            • Watchers:
              1 Start watching this issue

              Dates

              • Created:
                Updated:

                Backbone Issue Sync

                • Titanium SDK/CLI <> Titanium Mobile
                  Synced with:
                  TIMOB-6345
                  Sync status:
                  ERROR
                  Last received:
                  Last sent:

                  Git Integration