Bug 1291 : Date.getTime() fails after second execution - interference with month() day() hour() etc
Last modified: 2009-07-21 06:58




Status:
RESOLVED
Resolution:
INVALID -
Priority:
P2
Severity:
normal

 

Reporter:
Stefan Nowak
Assigned To:
fry

Attachment Type Created Size Actions

Description:   Opened: 2009-07-20 13:11
[quote]
[color=#7E7E7E]/// Setup Function[/color]

[color=#CC6600]void[/color] [color=#CC6600][b]setup[/b][/color]() {
  [color=#CC6600]size[/color](200, 200);
  [color=#CC6600]background[/color](0);
  [color=#CC6600]loop[/color](); [color=#7E7E7E]// noLoop() or loop()[/color]
  [color=#006699]frameRate[/color](1);
  [color=#CC6600]println[/color]([color=#006699]"Waiting 3 secs"[/color]);
  [color=#CC6600]delay[/color](3000); [color=#7E7E7E]// Offtopic, but also curious: delay()
is completely ignored here within setup()! Why?[/color]
  [color=#CC6600]println[/color]([color=#006699]"Continuing."[/color]);
}

[color=#7E7E7E]/// Main Loop[/color]

[color=#CC6600]void[/color] [color=#CC6600][b]draw[/b][/color]() {
  [color=#7E7E7E]// Standard Java fails!!![/color]
[color=#7E7E7E]//  Date timeNow = new Date();[/color]
[color=#7E7E7E]//  int ageNow = int(timeNow.getTime()/1000);[/color]

  [color=#7E7E7E]// Messy workaround:[/color]
  [color=#CC6600]int[/color] ageNow =
([color=#CC6600]month[/color]()*30*24*60*60)+([color=#CC6600]day[/color]()*24*60*60)
+([color=#CC6600]hour[/color]()*60*60)+([color=#CC6600]minute[/color]()*60)+([color=#
CC6600]second[/color]()*1);

  [color=#CC6600]int[/color] timeDuration = ageNow - ageLapseRecent;
  [color=#CC6600]println[/color]([color=#006699]"Last Time Lapse: "[/color] +
ageLapseRecent + [color=#006699]". Now: "[/color] + ageNow + [color=#006699]". Time
since last TimeLapse: "[/color] + timeDuration);
  [color=#CC6600]if[/color] (timeDuration >= liveModeDuration) {
    ageLapseRecent = ageNow;
    [color=#CC6600]println[/color]([color=#006699]"Simulation: Live Mode is over, switching
to Time Lapse Mode."[/color]);
  }
  
[color=#7E7E7E]//  println("Waiting 2 secs");[/color]
[color=#7E7E7E]//  delay(2000); // Works within draw(). Not necessary as frameRate() anyh
ow causes a time delay, only an additional test.[/color]
[color=#7E7E7E]//  println("Continuing.");[/color]
}

[color=#7E7E7E]/// Global Variables[/color]

[color=#7E7E7E]//SimpleDateFormat stampFormat = new SimpleDateFormat("yyyyMMdd-
HHmmss");[/color]
[color=#7E7E7E]//TimeZone stampTimeZone = TimeZone.getTimeZone("GMT");[/color]
[color=#7E7E7E]//stampFormat.setTimeZone(stampTimeZone);[/color]

[color=#7E7E7E]// Standard Java fails!!![/color]
[color=#7E7E7E]//Date timeLapseRecent = new Date();[/color]
[color=#7E7E7E]//int ageLapseRecent = int(timeLapseRecent.getTime()/1000);[/color]
[color=#7E7E7E]// Messy workaround:[/color]
[color=#CC6600]int[/color] ageLapseRecent =
([color=#CC6600]month[/color]()*30*24*60*60)+([color=#CC6600]day[/color]()*24*60*60)
+([color=#CC6600]hour[/color]()*60*60)+([color=#CC6600]minute[/color]()*60)+([color=#
CC6600]second[/color]()*1);
[color=#CC6600]int[/color] liveModeDuration = 5;

[/quote]
Additional Comment #1 From Stefan Nowak 2009-07-20 13:12
Sorry, I was out of my mind, and confused the bug tracker markup, with the forum markup
language. Please erase the bug. I will recreate a proper one
Additional Comment #2 From fry 2009-07-20 13:48
I'm all but certain you're just misunderstanding how the Java's Date and
Calendar classes work (I don't blame you, they're a mess), and also how the
delay() method works (read the reference for delay() carefully).
Additional Comment #3 From Stefan Nowak 2009-07-21 06:42
I accidentally posted bug 1291. I only intended a preview, to which I was used from the
forum, and so the post also contained an offtopic question, which I had wanted to remove anyway before finally posting the bug!

My offtopic question why delay() is executed within draw() but not within setup() was
answered in the forum post:
http://processing.org/discourse/yabb2/YaBB.pl?num=1208748388/#2

Yes delay() makes no sense in setup() in real operation, but I have put it there for debugging
purposes, and so only coincidentally detected that delay() does not work within setup.

The real topic, why I cannot get a unix timestamp in Processing, neither with Java's
Date.getTime() nor a core function, is in bug 1292.
Additional Comment #4 From fry 2009-07-21 06:58
*** Bug 1292 has been marked as a duplicate of this bug. ***