index

Übersicht: Blend4Web



We need all parts of a given time, seconds, minutes, hours. This task is realised in getTimeStamp:

blend4web/berlin-clock/b4w_part_timestamp.js (Source)

   function myclock () {

     // coloring all parts of the clock for a timestamp
     var ts = getTimeStamp ();
     console.log('myclock called'); 
   }

   function getTimeStamp (){
   
     // get all parts of the actual time

     var datum = new Date()
     var timestamp =  {}
     // Sekunden
     timestamp.seconds = datum.getSeconds() % 2 > '0'
     // 5-hour parts
     timestamp.hour_01 = datum.getHours() > '4'
     timestamp.hour_02 = datum.getHours() > '9'
     timestamp.hour_03 = datum.getHours() > '14'
     timestamp.hour_04 = datum.getHours() > '19'
     // 1-hour parts
     timestamp.hour_05 = datum.getHours() % 5 > '0'
     timestamp.hour_06 = datum.getHours() % 5 > '1'
     timestamp.hour_07 = datum.getHours() % 5 > '2'
     timestamp.hour_08 = datum.getHours() % 5 > '3'
     //  5-minute parts
     timestamp.minute_01 = datum.getMinutes() > '4'
     timestamp.minute_02 = datum.getMinutes() > '9'
     timestamp.minute_03 = datum.getMinutes() > '14'
     timestamp.minute_04 = datum.getMinutes() > '19'
     timestamp.minute_05 = datum.getMinutes() > '24'
     timestamp.minute_06 = datum.getMinutes() > '29'
     timestamp.minute_07 = datum.getMinutes() > '34'
     timestamp.minute_08 = datum.getMinutes() > '39'
     timestamp.minute_09 = datum.getMinutes() > '44'
     timestamp.minute_10 = datum.getMinutes() > '49'
     timestamp.minute_11 = datum.getMinutes() > '54'
     //  1-minute parts
     console.log(datum.getMinutes() % 5);
     timestamp.minute_12 = datum.getMinutes() % 5 > '0'
     timestamp.minute_13 = datum.getMinutes() % 5 > '1'
     timestamp.minute_14 = datum.getMinutes() % 5 > '2'
     timestamp.minute_15 = datum.getMinutes() % 5 > '3'
     //console.log(timestamp);
     return timestamp;

   }

With the help of the modulo-Operator we can determine, if a part should be visualised or not. As values we need only true or false. The following picture is showing one evaluaeted timestamp as console.log output.

/blend4web/berlin-clock/bc-console-log-timestamp.png

Comments