Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.javascript > #19529

How do I add new currentTime to an array

From "Tony" <tony.johansson@inport.com>
Newsgroups comp.lang.javascript
Subject How do I add new currentTime to an array
Date 2013-04-29 16:47 +0200
Organization A noiseless patient Spider
Message-ID <klm0vg$545$1@dont-email.me> (permalink)

Show all headers | View raw


I have a small problem. I change the variable currentTime in the for loop in 
function GenerateTableHeader() and I want to add this new value to the array 
timeArray.
When I add now to the array timeArray I can see that all values is the same.
I have thought that this algoritm would work but obviously it doesn't.

There must be something that I have missed here.
var temp = currentTime;
            timeArray[i] = temp;
            temp ="";


function GenerateTableHeader()
    {
        var cellTitle,
            hours,
            minutes,
            tempDate;

        hours = currentTime.getHours();
        minutes = currentTime.getMinutes();

        switch (currentInterval)
        {
            case "Interval.RdoHour":
                currentTime.setHours(currentTime.getHours() - 1);
                break;

           case "Interval.RdoHalv":
                currentTime.setMinutes((parseInt((minutes) / 30) * 30) % 
60);
                currentTime.setMinutes(currentTime.getMinutes() - 30);
                 break;

           case "Interval.RdoKvart":
                currentTime.setMinutes((parseInt((minutes) / 15) * 15) % 
60);
                currentTime.setMinutes(currentTime.getMinutes() - 15);
                break;
        }

        for (var i = -1; i < antalColumner; i++)
        {
            var tempDate

           if (i == -1)
           {
               var elem = document.getElementById("objectName").innerHTML = 
"Object";
           }
           else
           {
              if (currentInterval == "Interval.RdoHour")
              {
                  currentTime.setHours(currentTime.getHours() + 1);
                  hours = currentTime.getHours();
                  minutes = currentTime.getMinutes();
                  cellTitle = (hours < 10 ? "0" + hours : hours) + ":00";
              }
              else if (currentInterval == "Interval.RdoHalv")
              {
                  currentTime.setMinutes(currentTime.getMinutes() + 30);
                  minutes = currentTime.getMinutes();
                  hours = currentTime.getHours();
                  cellTitle = (hours < 10 ? "0" + hours : hours) + ":" + 
(minutes < 10 ? "0" + minutes : minutes);
              }
              else if (currentInterval == "Interval.RdoKvart")
              {
                  currentTime.setMinutes(currentTime.getMinutes() + 15);
                  minutes = currentTime.getMinutes();
                  hours = currentTime.getHours();
                  cellTitle = (hours < 10 ? "0" + hours : hours) + ":" + 
(minutes < 10 ? "0" + minutes : minutes);
              }

              var item = 'item'+i;
              var elem = document.getElementById(item).innerHTML = 
cellTitle;

              var temp = currentTime;
              timeArray[i] = temp;
              temp ="";
           }
        }
    }

//Tony 

Back to comp.lang.javascript | Previous | Next — Next in thread | Find similar | Unroll thread


Thread

How do I add new currentTime to an array "Tony" <tony.johansson@inport.com> - 2013-04-29 16:47 +0200
  Re: How do I add new currentTime to an array "Tony" <tony.johansson@inport.com> - 2013-04-29 16:53 +0200
  Re: How do I add new currentTime to an array Dr J R Stockton <reply1300@merlyn.demon.co.uk.invalid> - 2013-04-30 22:31 +0100

csiph-web