Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-13659] iOS: Date() value gets changed when passed via events

GitHub Issuen/a
TypeBug
PriorityLow
StatusOpen
ResolutionUnresolved
Affected Version/sRelease 3.1.0
Fix Version/sn/a
ComponentsiOS
Labelsreprod
ReporterJoel Margolese
AssigneeUnknown
Created2013-04-23T18:39:20.000+0000
Updated2018-02-28T20:03:23.000+0000

Description

*Problem description* I have built a simple Alloy test case that passes a date object between two controllers by firing Ti.App.fireEvent. Tested in iOS 6.1 simulator on Mountain Lion. Titantium 3.1.0.GA. But this occurs with 3.0.2.GA as well. *Test case*
function buttonClick() {
	var time = new Date('4/21/2013 11:45 am');

	var argInfo = {
		eventTime : time
	};
	Ti.API.info('starting time: ' + JSON.stringify(argInfo));

	Ti.App.fireEvent("testEvent", argInfo);
}

Ti.App.addEventListener('testEvent', function(info) {
	Ti.API.info(" in event time: " + info.eventTime.toString());
});

var win = Ti.UI.createWindow({
	backgroundColor : "#FFF"
});

var button = Titanium.UI.createButton({
	title : 'Fire Event',
	top : 10,
	width : 100,
	height : 50
});
button.addEventListener('click', buttonClick);

win.add(button);
win.open();
*Console output*
[INFO] starting time: {"eventTime":"2013-04-21T15:45:00.000Z"}
[INFO]  in event time: Sun Apr 21 2013 11:46:02 GMT-0400 (EDT)
*Note* The time prior to firing the event is 15:45, but when it arrives the minutes are now: 46.02 I presume this is a problem with the serializing of the date object. Perhaps Data() objects are not legal for events, but they used to work, this is old code that has now stopped working. If they are not legal, Titanium should throw an error or it should be documented. *Workaround* Pass the date as:
newDate().toString()

Attachments

FileDateSize
test.zip2013-04-23T18:42:08.000+00008914514

Comments

  1. Joel Margolese 2013-04-23

    deleted build folder, not sure why, but it was 90MB.
  2. Daniel Sefton 2013-04-23

    Tested and sort of confirmed on iOS 6 simulator, Ti SDK 3.1 GA. This is the output I get:
    [INFO] :   starting time: {"eventTime":"2013-04-21T18:45:00.000Z"}
       [INFO] :   in event time: Sun Apr 21 2013 11:45:10 GMT-0700 (PDT)
    So there's about 10 seconds difference here...
  3. Lee Morris 2017-07-10

    I am able to reproduce this issue with the following environment; iPhone 6 (10.0) Studio 4.9.0.201705302345 Ti SDK 6.1.1 GA Appc NPM 4.2.9 Appc CLI 6.2.2 Ti CLI 5.0.14 Alloy 1.9.11 Xcode 8.2 (8C38) Node v4.8.2 Java 1.8.0_131

JSON Source