Titanium JIRA Archive
Appcelerator Community (AC)

[AC-2347] iOS 6: DatePicker dates between February 16, 1986 and February 28, 1986 are wrongly reported

GitHub Issuen/a
TypeBug
Priorityn/a
StatusClosed
ResolutionCannot Reproduce
Resolution Date2013-03-15T18:16:09.000+0000
Affected Version/sn/a
Fix Version/sn/a
ComponentsTitanium SDK & CLI
Labelsdate, datepicker, datetime, locale, picker, triage
ReporterYgor Lemos
AssigneeMauro Parra-Miranda
Created2012-10-30T23:07:45.000+0000
Updated2017-02-15T00:22:13.000+0000

Description

When getting the value back from a datepicker "change" event, the returned values from February 16, 1986 to February 28, 1986 are reported wrong. All other dates are reported normally. No date treatment is being made on the event data.
var win = Ti.UI.createWindow();

// Picker Animations
var slideIn = Ti.UI.createAnimation({
	bottom : -40
});
var slideOut = Ti.UI.createAnimation({
	bottom : -288
});

// Birthday Picker
var birthPickerView = Ti.UI.createView({
	height : 288,
	//bottom : -288,
	zIndex : 9
});
var birthPicker = Ti.UI.createPicker({
	top : 40,
	type : Ti.UI.PICKER_TYPE_DATE,
	locale : Ti.Platform.locale,
	selectionIndicator : true,
	minDate : new Date(1900, 0, 1),
	maxDate : new Date(1997, 11, 31)
});
birthPickerView.add(birthPicker);
var birthPickerLabel = Ti.UI.createLabel({
	text : "Your Birthday",
	color : "#fff",
	font : {
		fontWeight : "bold",
		fontSize : 16
	},
	shadowColor : "#000",
	shadowOffset : {
		x : 0.5,
		y : 0.5
	}
});
birthPickerSpace = Ti.UI.createButton({
	style : Ti.UI.iPhone.SystemButtonStyle.FIXED_SPACE,
	width : 29
}, function() {
});
birthPickerOKButton = Ti.UI.createButton({
	title : "Confirm",
	style : Ti.UI.iPhone.SystemButtonStyle.DONE
}, function() {
	birthPickerView.animate(slideOut);
});

var birthPickerToolbar = Ti.UI.iOS.createToolbar({
	top : 0,
	height : 40,
	items : [birthPickerLabel, birthPickerSpace, birthPickerOKButton]
});
birthPickerView.add(birthPickerToolbar);
win.add(birthPickerView);

birthPicker.addEventListener("change", function(e) {
	console.log("Date Object: " + e);
	console.log("Date Value: " + e.value);
	console.log("Date: " + e.value.getDate());
	console.log("Day: " + e.value.getDay());
	console.log("Date String: " + e.value.toDateString());
	console.log("ISO String: " + e.value.toISOString());
	console.log("Full Date: " + e.value.toString());
	var selDate = "Formatted Date: " + e.value.getDate() + "/" + String(Number(e.value.getMonth()) + 1) + "/" + e.value.getFullYear();
	console.log(selDate);
	//fBirthdayLabel.setText(selDate);
});

win.open();
Example: Selected Date: February 14, 1986
[INFO] {

    source = "[object TiUIPicker]";

    type = change;

    value = "1986-02-14 02:00:00 +0000";

}

[INFO] 1986-02-14 02:00:00 +0000

[INFO] 14

[INFO] 5

[INFO] Fri Feb 14 1986

[INFO] 1986-02-14T02:00:00.000Z

[INFO] Fri Feb 14 1986 00:00:00 GMT-0200 (BRST)
Selected Date: February 18, 1986
[INFO] {

    source = "[object TiUIPicker]";

    type = change;

    value = "1986-02-18 02:00:00 +0000";

}

[INFO] 1986-02-18 02:00:00 +0000

[INFO] 17

[INFO] 1

[INFO] Mon Feb 17 1986

[INFO] 1986-02-18T02:00:00.000Z

[INFO] Mon Feb 17 1986 23:00:00 GMT-0300 (BRT)

So as you might see, the objects returned on Feb are returned with times different than 0, so, every date between the aforementioned range is getting returned with one day less when you call .getDate() on the result value of the change event. It might be related to locale, but if I left locale out I lose the picker translation and that is unacceptable. Any hints?

Attachments

FileDateSize
datepicker-pt-br.png2012-12-06T23:04:02.000+000090410

Comments

  1. Ygor Lemos 2012-10-30

    For now, I've solved this using the ISOString Date, manually stripping the date and ignoring the weird time that comes together with the date.
       var selDate = e.value.toISOString().split("T")[0].split("-").reverse().join("/")
       
    this solves it... but isn't ideal...
  2. Daniel Sefton 2012-12-06

    Cannot reproduce on iOS 6 simulator with Ti Studio 3.0, Ti SDK 2.1.3 GA, 2.1.4 GA or 3.0 RC. e.g. When setting February 18th, it's reported correctly (all values are 18). Like you said, could be specific to your locale.
  3. Ygor Lemos 2012-12-06

    I've used Brazil for the location and Portuguese - Brazil for this specific case.
  4. Daniel Sefton 2012-12-06

    I'm afraid I can't reproduce it with that locale either ("pt-BR"), on TiSDK 2.1.3 GA, 2.1.4 GA or 3.0 RC. See screenshot.
  5. Ingo Muschenetz 2013-03-15

    Please reopen if we can reproduce this issue.
  6. Ygor Lemos 2017-02-15

    This still happens on Titanium 5.5.1.GA :O

JSON Source