PDA

View Full Version : Dividing The Hour



TimeTracker
07-29-2008, 11:12 PM
Is it possible to extend this script created by DIMX so that it does not divide the day into 24 hours, but a nominated hour? It will be used to account for time drift over the centuries according to a constant variable.

<!doctype html public "-//w3c//dtd html 4.0 transitional//en">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Dividing The Hour</title>
<script type="text/javascript">
//Code provided by Dynamic Drive (http://www.dynamicdrive.com/forums/.
<!--

function Time(h, m, s) {
this.hours = typeof h == "number" ? h : 0;
this.minutes = typeof m == "number" ? m : 0;
this.seconds = typeof s == "number" ? s : 0;
}

Time.prototype.AddTime = function(time) {
this.AddHours(time.hours);
this.AddMinutes(time.minutes);
this.AddSeconds(time.seconds);
}

Time.prototype.AddHours = function(h) {
this.hours = (this.hours + h) % 24;
}

Time.prototype.AddMinutes = function(m) {
this.minutes += m;
this.AddMinutes(Math.floor(this.minutes / 60));
this.minutes %= 60;
}

Time.prototype.AddSeconds = function(s) {
this.seconds += s;
this.AddSeconds(Math.floor(this.seconds / 60));
this.seconds %= 60;
}

Time.prototype.AsString = function() {
return (this.hours < 10 ? "0" + this.hours : this.hours)
+ ":"
+ (this.minutes < 10 ? "0" + this.minutes : this.minutes)
+ ":"
+ (this.seconds < 10 ? "0" + this.seconds : this.seconds);
}

// Output to text field...

function makeList(df) {
var hrnum = df.hrnum.selectedIndex + 1;
var minnum = df.minnum.selectedIndex + 1;
var time = new Time(eval(df.hrnum.selectedIndex), eval(df.minnum.selectedIndex), eval(df.secnum.value));
time.AddHours(0);
var Hour2401 = df.Hour2401.value;
df.Hour2401.value = time.AsString();
time.AddHours(1);
var Hour0102 = df.Hour0102.value;
df.Hour0102.value = time.AsString();
time.AddHours(1);
}
// -->
</script>
</head>
<body text="#000000" bgcolor="#FFFFD5" link="#0000EE" vlink="#551A8B" alink="#FF0000">
&nbsp;
<center><table BORDER=0 CELLSPACING=2 CELLPADDING=5 COLS=1 WIDTH="600" >
<tr>
<td ALIGN=CENTER VALIGN=TOP WIDTH="50%"><form>
<center><table BORDER=0 CELLSPACING=0 CELLPADDING=5 COLS=4 WIDTH="320" >
<tr>
<td ALIGN=CENTER VALIGN=TOP WIDTH="60"><select name="hrnum" size="1"><option>00</option><option>1</option><option>2</option><option>3</option><option>4</option><option>5</option><option>6</option><option>7</option><option>8</option><option>9</option><option>10</option><option>11</option><option>12</option><option>13</option><option>14</option><option>15</option><option>16</option><option>17</option><option>18</option><option>19</option><option>20</option><option>21</option><option>22</option><option>23</option></select></td>

<td ALIGN=CENTER VALIGN=TOP WIDTH="60"><select name="minnum" size="1"><option>00</option><option>01</option><option>02</option><option>03</option><option>04</option><option>05</option><option>06</option><option>07</option><option>08</option><option>09</option><option>10</option><option>11</option><option>12</option><option>13</option><option>14</option><option>15</option><option>16</option><option>17</option><option>18</option><option>19</option><option>20</option><option>21</option><option>22</option><option>23</option><option>24</option><option>25</option><option>26</option><option>27</option><option>28</option><option>29</option><option>30</option><option>31</option><option>32</option><option>33</option><option>34</option><option>35</option><option>36</option><option>37</option><option>38</option><option>39</option><option>40</option><option>41</option><option>42</option><option>43</option><option>44</option><option>45</option><option>46</option><option>47</option><option>48</option><option>49</option><option>50</option><option>51</option><option>52</option><option>53</option><option>54</option><option>55</option><option>56</option><option>57</option><option>58</option><option>59</option></select></td>

<td><input type="text" name="secnum" value=30 size=2></td>

<td ALIGN=CENTER VALIGN=TOP WIDTH="200"><input type="button" value="Hourly Module" onclick="makeList(this.form)" /></td>
</tr>

<tr>
<td>
<div align=right><b><font face="Tahoma"><font size=-1><font color="#3333FF">HH</font><font color="#FFFFD5">----</font><font color="#3333FF">:</font></font></font></b></div>
</td>

<td><b><font face="Tahoma"><font size=-1><font color="#FFFFD5">--</font><font color="#3333FF">MM</font></font></font></b></td>

<td></td>
</tr>
</table></center>
</td>
</tr>

<tr>
<td>
<center><input type="text" name="Hour2401" size="10">'24/1' Begins |&nbsp;<input type="text" name="Hour0102" size="10">'1/2'
Starts</form></center>
</td>
</tr>
</table></center>

</body>
</html>

Jesdisciple
07-30-2008, 06:17 AM
What the heck is a nominated hour? This thread is the top result on Google so I know it's quite esoteric: http://www.google.com/search?q="nominated+hour"

TimeTracker
07-30-2008, 12:34 PM
Chris, a nominated hour is any sixty minute period which can begin at any stage in the hour and flow over into the next hour. This will usually be determined by the changeover time for a new Thrones module. My research into Rev. 4:2-4 is esoteric, but is anchored in logic and mathematics. When the penny eventually drops that every person on this planet is carrying the exact age of the earth within them and that it determines much of what they experience in life, then it will not sound so esoteric. It becomes one percent inspiration and ninety-nine percent perspiration.

Maybe DIMX's script is not the right way to go about it. Since it can be any hour, that does not need to be included. Minutes and seconds are fine. I included the hour so that the flow on could be seen. In my manually prepared table the hour does not appear. This caters for the two starting times possible in any hour at the present time. 2000 years ago it might have been 11:37 and 41:37; 4000 years ago 01:37 and 31:37, etc.

M:S - M:S Module M:S - M:S

21:37 - 24:07 '24/1' 51:37 - 54:07
24:07 - 26:37 '1/2' 54:07 - 56:37
26:37 - 29:07 '2/3' 56:37 - 59:07
29:07 - 31:37 '3/4' 59:07 - 01:37

Jesdisciple
07-30-2008, 03:27 PM
See if this helps any when replacing the current Time constructor...
function Time(m, s) {
this.hours = typeof m == "number" ? Math.floor(m / 60) : 0;
this.minutes = typeof m == "number" ? m % 60 : 0;
this.seconds = typeof s == "number" ? s : 0;
}That takes the number of hours from the integer part of the mixed (m / 60) number and the number of minutes from the numerator of the same.

TimeTracker
07-30-2008, 09:44 PM
Chris, this does work. However, the hour is either 00: or 01: and each portion needs to increment by 2.5 minutes. So (this.hours + h) would not be needed.

I had hoped to keep the nominated hour in, if possible. Let me give you an example. My changeover time today is close to 22:21:37. When I was born at 00:23 or thereabouts it was close to 22:21:22. I am now into the 3rd hour ('2/3' hourly module) of the twenty-four hour period. This drives me in what I do. My remark about inspiration and perspiration came from Thomas Edison who was born during a '2/3' week (Thu, Feb 11th, 1847). This research is very hard yakka. Most of my time is spent studying words, concepts and numbers. Yet I am first off the rank ('24/1') in the hour. Here I do a lot of writing, including HTML and JavaScript, and keep reviewing things, among many other traits, not all positive.

If I was born at, say, 04:23, then I would select 4 as the hour, 21 as the minute and 22 as the second. The 2.5 minute hourly divisions would range from 04: to 05:. As it is they are 00: and 01:.

Last night I made up a chart using OpenOffice.org's spreadsheet, previewed it in a browser, copied and pasted the source into WordPad, saved it as .html and that works too. If a JavaScript solution cannot be found, I have this to fall back on, but the hour is always 00: and 01:. It means creating a lot of files, though, and I like to centralise. Which is why I am looking for a solution at Dynamic Drive.

Jesdisciple
07-31-2008, 03:32 AM
Because I don't need a course in this chronologistics in order to write the script (and that's what your published work will be for), I'm going to trim your post so this doesn't take us longer than it must. Of course, point out anything I omitted but shouldn't have.


Chris, this does work. However, the hour is either 00: or 01: and each portion needs to increment by 2.5 minutes. So (this.hours + h) would not be needed.The hour is either 0 or 1? That doesn't make much sense to me, but how is it relevant to the JS?


I had hoped to keep the nominated hour in, if possible. Let me give you an example. My changeover time today is close to 22:21:37.What's a changeover time, or how is it significant to the JS?


When I was born at 00:23 or thereabouts it was close to 22:21:22.That seems to break with the general pattern of 07 and 37... I obviously don't understand where the numbers come from, but does it matter to the JS?


I am now into the 3rd hour ('2/3' hourly module) of the twenty-four hour period.What's an hourly module, or how is it significant to the JS? I got lost in the rest of that paragraph, so I'm omitting it.


If I was born at, say, 04:23, then I would select 4 as the hour, 21 as the minute and 22 as the second.I'm guessing that you meant "23 as the minute" and that 22 was just an arbitrary number rather than calculated from 4:23?


The 2.5 minute hourly divisions would range from 04: to 05:. As it is they are 00: and 01:.How can a division of 2.5 hours only range 1 hour?


Last night I made up a chart using OpenOffice.org's spreadsheet, previewed it in a browser, copied and pasted the source into WordPad, saved it as .html and that works too. If a JavaScript solution cannot be found, I have this to fall back on, but the hour is always 00: and 01:. It means creating a lot of files, though, and I like to centralise. Which is why I am looking for a solution at Dynamic Drive.As a programmer, I can certainly understand that; it's what my trade is based on!

TimeTracker
07-31-2008, 07:04 AM
Chris, as a JS programmer it would help to see things in perspective. The system on which I am working has three levels: weekly, hourly and hourly portion (for want of a better term).

The first comes on stream once a week, every week, simultaneously worldwide. Each time zone experiences it at a different clock time to the others. For some it occurs during the early part of the hour, for most the latter part. It does not do so on the hour or half hour as one might expect, but within an hour and a minute (e.g. 07:51:37 NY EST). The weekly activity was sorted out with JS back in 2000.

DIMX's script helped me with the hourly module. For this I thank Dynamic Drive.

The hourly portion is 1/24th of an hour or 2.5 minutes. This is where I need help. Perhaps the term is confusing, considering your comment, "How can a division of 2.5 hours only range 1 hour?" It cannot.

My question is, as I stated right at the beginning, Is it possible to extend the script created by DIMX so that it does not divide the day into 24 hours, but a nominated hour (instead) - a sixty minute period which begins part way into a standard hour in terms of minutes and seconds and obviously finishes sixty minutes later in the next hour?

Quote: "I'm guessing that you meant "23 as the minute" and that 22 was just an arbitrary number rather than calculated from 4:23?"

04:21:22 would be when the hourly portion begins, to which 4:23 would naturally belong, as the next time period starts at 04:23:52. Do you see the 2.5 minute increment? I have tried to modify DIMX's script in dozens of ways without success.

To be able to so divide that or any sixty minute period into 24 such portions is what I am seeking to do. With twenty-four such periods in a system day, to also include the hour, minute and second would be a great advantage.

To be honest, I find my spreadsheet version too complicated and look forward to your input. Please bear in mind that I did not invent this system. I merely discovered it twelve years ago and am still trying to get a handle on it after all these years. The hourly portion is important for the insights it provides and I want the web experience to be as simple and enjoyable as possible.

Jesdisciple
07-31-2008, 08:38 AM
No, I'm sure your explanation is clearer than I seem to testify; I often have difficulty communicating with people who have different thought-patterns than my own.

Now that I understand it's just an issue of multiples, try this... (Because the zero-padding for AsString was getting too complex for ternary statements, I put it all in a nested function. It uses logarithms to find the higher of the two powers of 10 closest to a number, then pads the number based on an argument and that power of 10.)
<!doctype html public "-//w3c//dtd html 4.0 transitional//en">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Dividing The Hour</title>
<script type="text/javascript">
//Code provided by Dynamic Drive (http://www.dynamicdrive.com/forums/.
<!--

function Time(h, m, s) {
this.hours = typeof h == "number" ? h : 0;
this.minutes = typeof m == "number" ? m : 0;
this.seconds = typeof s == "number" ? s : 0;
}

Time.prototype.AddTime = function(time) {
this.AddHours(time.hours);
this.AddMinutes(time.minutes);
this.AddSeconds(time.seconds);
}

Time.prototype.AddHours = function(h) {
this.hours = (this.hours + h) % 576;
}

Time.prototype.AddMinutes = function(m) {
this.minutes += m;
this.AddMinutes(Math.floor(this.minutes / 60));
this.minutes %= 60;
}

Time.prototype.AddSeconds = function(s) {
this.seconds += s;
this.AddSeconds(Math.floor(this.seconds / 60));
this.seconds %= 60;
}

Time.prototype.AsString = function() {
var retval = '';
function padNum(num, digits){
var zeroes = digits - Math.ceil(Math.log(num) / Math.log(10));
for(var i = 0; i < zeroes; i++){
num = '0' + num;
}
return num;
}
return padNum(this.hours, 3) + ":" + padNum(this.minutes, 2) + ":" + padNum(this.seconds, 2);
}

// Output to text field...

function makeList(df) {
var hrnum = parseInt(df.hrnum.value) + 1;
var minnum = df.minnum.selectedIndex + 1;
var time = new Time(eval(df.hrnum.value), eval(df.minnum.selectedIndex), eval(df.secnum.value));
time.AddHours(0);
var Hour2401 = df.Hour2401.value;
df.Hour2401.value = time.AsString();
time.AddHours(1);
var Hour0102 = df.Hour0102.value;
df.Hour0102.value = time.AsString();
time.AddHours(1);
}
// -->
</script>
</head>
<body text="#000000" bgcolor="#FFFFD5" link="#0000EE" vlink="#551A8B" alink="#FF0000">
&nbsp;
<center><table BORDER=0 CELLSPACING=2 CELLPADDING=5 COLS=1 WIDTH="600" >
<tr>
<td ALIGN=CENTER VALIGN=TOP WIDTH="50%"><form>
<center><table BORDER=0 CELLSPACING=0 CELLPADDING=5 COLS=4 WIDTH="320" >
<tr>
<td ALIGN=CENTER VALIGN=TOP WIDTH="60"><input type="text" name="hrnum" size="3"></td>

<td ALIGN=CENTER VALIGN=TOP WIDTH="60"><select name="minnum" size="1"><option>00</option><option>01</option><option>02</option><option>03</option><option>04</option><option>05</option><option>06</option><option>07</option><option>08</option><option>09</option><option>10</option><option>11</option><option>12</option><option>13</option><option>14</option><option>15</option><option>16</option><option>17</option><option>18</option><option>19</option><option>20</option><option>21</option><option>22</option><option>23</option><option>24</option><option>25</option><option>26</option><option>27</option><option>28</option><option>29</option><option>30</option><option>31</option><option>32</option><option>33</option><option>34</option><option>35</option><option>36</option><option>37</option><option>38</option><option>39</option><option>40</option><option>41</option><option>42</option><option>43</option><option>44</option><option>45</option><option>46</option><option>47</option><option>48</option><option>49</option><option>50</option><option>51</option><option>52</option><option>53</option><option>54</option><option>55</option><option>56</option><option>57</option><option>58</option><option>59</option></select></td>

<td><input type="text" name="secnum" value="30" size="2"></td>

<td ALIGN=CENTER VALIGN=TOP WIDTH="200"><input type="button" value="Hourly Module" onclick="makeList(this.form)" /></td>
</tr>

<tr>
<td>
<div align=right><b><font face="Tahoma"><font size=-1><font color="#3333FF">HH</font><font color="#FFFFD5">----</font><font color="#3333FF">:</font></font></font></b></div>
</td>

<td><b><font face="Tahoma"><font size=-1><font color="#FFFFD5">--</font><font color="#3333FF">MM</font></font></font></b></td>

<td></td>
</tr>
</table></center>
</td>
</tr>
<tr>
<td>
<center><input type="text" name="Hour2401" size="10">'24/1' Begins |&nbsp;<input type="text" name="Hour0102" size="10">'1/2'
Starts</form></center>
</td>
</tr>
</table></center>
</body>
</html>

TimeTracker
07-31-2008, 11:02 AM
Chris, there is something wrong in the code. Netscape 7, IE 7 and FireFox 2 all refused to process it. FireFox asked to stop the script. Twice I copied and pasted the code into WordPad (.html) to make sure.

I returned the selectedIndex to "hrnum" and the hour now has three digits, it progresses to the next hour as before and has not started to divide the next sixty minutes into 24 portions.

Who does not have difficulty communicating at times? It is not your fault. You are who you are and I consider you a genius. This is a very difficult challenge.

Jesdisciple
07-31-2008, 06:01 PM
The infinite loop was due to the special case of Math.log(0) == -Infinity, although I would think -Infinity would be less than any positive number and so wouldn't cause a problem. I included a hack so 1 will be the presumed output of Math.log when 0 is the value, but 0 will still be the padded number. EDIT: I found that Math.log(x) where x <= 1 is the real special case and included it in the above hack. Negative times with more than one digit are avoided by taking the absolute value at the top of the function.
<!doctype html public "-//w3c//dtd html 4.0 transitional//en">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Dividing The Hour</title>
<script type="text/javascript">
//Code provided by Dynamic Drive (http://www.dynamicdrive.com/forums/.
<!--

function Time(h, m, s) {
this.hours = typeof h == "number" ? h : 0;
this.minutes = typeof m == "number" ? m : 0;
this.seconds = typeof s == "number" ? s : 0;
}

Time.prototype.AddTime = function(time) {
this.AddHours(time.hours);
this.AddMinutes(time.minutes);
this.AddSeconds(time.seconds);
}

Time.prototype.AddHours = function(h) {
this.hours = (this.hours + h) % 576;
}

Time.prototype.AddMinutes = function(m) {
this.minutes += m;
this.AddMinutes(Math.floor(this.minutes / 60));
this.minutes %= 60;
}

Time.prototype.AddSeconds = function(s) {
this.seconds += s;
this.AddSeconds(Math.floor(this.seconds / 60));
this.seconds %= 60;
}

Time.prototype.AsString = function() {
function padNum(num, digits){
num = Math.abs(num);
var zeroes = digits - Math.ceil((num <= 1 ? 1 : Math.log(num)) / Math.log(10));
for(var i = 0; i < zeroes; i++){
num = '0' + num;
}
return num;
}
return padNum(this.hours, 3) + ":" + padNum(this.minutes, 2) + ":" + padNum(this.seconds, 2);
}

// Output to text field...

function makeList(df) {
var hrnum = parseInt(df.hrnum.value) + 1;
var minnum = df.minnum.selectedIndex + 1;
var time = new Time(eval(df.hrnum.value), eval(df.minnum.selectedIndex), eval(df.secnum.value));
time.AddHours(0);
var Hour2401 = df.Hour2401.value;
df.Hour2401.value = time.AsString();
time.AddHours(1);
var Hour0102 = df.Hour0102.value;
df.Hour0102.value = time.AsString();
time.AddHours(1);
}
// -->
</script>
</head>
<body text="#000000" bgcolor="#FFFFD5" link="#0000EE" vlink="#551A8B" alink="#FF0000">
&nbsp;
<center><table BORDER=0 CELLSPACING=2 CELLPADDING=5 COLS=1 WIDTH="600" >
<tr>
<td ALIGN=CENTER VALIGN=TOP WIDTH="50%"><form>
<center><table BORDER=0 CELLSPACING=0 CELLPADDING=5 COLS=4 WIDTH="320" >
<tr>
<td ALIGN=CENTER VALIGN=TOP WIDTH="60"><input type="text" name="hrnum" size="3"></td>

<td ALIGN=CENTER VALIGN=TOP WIDTH="60"><select name="minnum" size="1"><option>00</option><option>01</option><option>02</option><option>03</option><option>04</option><option>05</option><option>06</option><option>07</option><option>08</option><option>09</option><option>10</option><option>11</option><option>12</option><option>13</option><option>14</option><option>15</option><option>16</option><option>17</option><option>18</option><option>19</option><option>20</option><option>21</option><option>22</option><option>23</option><option>24</option><option>25</option><option>26</option><option>27</option><option>28</option><option>29</option><option>30</option><option>31</option><option>32</option><option>33</option><option>34</option><option>35</option><option>36</option><option>37</option><option>38</option><option>39</option><option>40</option><option>41</option><option>42</option><option>43</option><option>44</option><option>45</option><option>46</option><option>47</option><option>48</option><option>49</option><option>50</option><option>51</option><option>52</option><option>53</option><option>54</option><option>55</option><option>56</option><option>57</option><option>58</option><option>59</option></select></td>

<td><input type="text" name="secnum" value="30" size="2"></td>

<td ALIGN=CENTER VALIGN=TOP WIDTH="200"><input type="button" value="Hourly Module" onclick="makeList(this.form)" /></td>
</tr>

<tr>
<td>
<div align=right><b><font face="Tahoma"><font size=-1><font color="#3333FF">HH</font><font color="#FFFFD5">----</font><font color="#3333FF">:</font></font></font></b></div>
</td>

<td><b><font face="Tahoma"><font size=-1><font color="#FFFFD5">--</font><font color="#3333FF">MM</font></font></font></b></td>

<td></td>
</tr>
</table></center>
</td>
</tr>
<tr>
<td>
<center><input type="text" name="Hour2401" size="10">'24/1' Begins |&nbsp;<input type="text" name="Hour0102" size="10">'1/2'
Starts</form></center>
</td>
</tr>
</table></center>
</body>
</html>

Well, it's not my fault in one sense, but my brain is certainly handicapped. But I have come to terms with it (or with that aspect of it, at least) and am scheduled to let a specialist iron some of my kinks out soon.

TimeTracker
07-31-2008, 08:43 PM
Chris,
Neither of my three browsers like it. Again I had to reinstall selectedIndex to "hrnum" to get a result and it was the same as before. I have been experimenting with the "this.hours = (this.hours + h) % 576;" code and found that the % 576 or % 60 can be any value at all and will return the same result. It can even be omitted from the code altogether with no apparent adverse effect.

function makeList(df) {
var hrnum = parseInt(df.hrnum.selectedIndex + 1);
var minnum = parseInt(df.minnum.selectedIndex + 1);
var time = new Time(eval(df.hrnum.selectedIndex), eval(df.minnum.selectedIndex), eval(df.secnum.value));

<td ALIGN=CENTER VALIGN=TOP WIDTH="60"><select name="hrnum" size="1"><option>00</option><option>1</option><option>2</option><option>3</option><option>4</option><option>5</option><option>6</option><option>7</option><option>8</option><option>9</option><option>10</option><option>11</option><option>12</option><option>13</option><option>14</option><option>15</option><option>16</option><option>17</option><option>18</option><option>19</option><option>20</option><option>21</option><option>22</option><option>23</option></select></td>

The things we do for love! I pray that the specialist can help you. A healthy brain is important for existence, yet we all find ways to abuse it, even unwittingly.

Jesdisciple
07-31-2008, 11:08 PM
Umm... What browsers are you using? Firefox does fine with it; when I input 677:0:30 it outputs 101:00:30 and 102:00:30...

EDIT: And are you using the entire HTML I posted? I changed the first <select> to an <input type="text"> and may have made other changes.

TimeTracker
08-01-2008, 12:23 AM
Chris, it is a bit frustrating when a reply is posted and it does not appear on the page. The solution remains as evasive as ever. None of my browsers will produce a result unless selectedIndex is returned for "hrnum". Even then only the hour progresses, not its portion. I am reinserting the code here:

// Output to text field...

function makeList(df) {
var hrnum = parseInt(df.hrnum.selectedIndex + 1);
var minnum = parseInt(df.minnum.selectedIndex + 1);
var time = new Time(eval(df.hrnum.selectedIndex), eval(df.minnum.selectedIndex), eval(df.secnum.value));
time.AddHours(0);
var Hour2401 = df.Hour2401.value;
df.Hour2401.value = time.AsString();
time.AddHours(1);
var Hour0102 = df.Hour0102.value;
df.Hour0102.value = time.AsString();

}
// -->
</script>
</head>
<body text="#000000" bgcolor="#FFFFD5" link="#0000EE" vlink="#551A8B" alink="#FF0000">
&nbsp;
<center><table BORDER=0 CELLSPACING=2 CELLPADDING=5 COLS=1 WIDTH="600" >
<tr>
<td ALIGN=CENTER VALIGN=TOP WIDTH="50%"><form>
<center><table BORDER=0 CELLSPACING=0 CELLPADDING=5 COLS=4 WIDTH="320" >
<tr>
<td ALIGN=CENTER VALIGN=TOP WIDTH="60"><select name="hrnum" size="1"><option>00</option><option>1</option><option>2</option><option>3</option><option>4</option><option>5</option><option>6</option><option>7</option><option>8</option><option>9</option><option>10</option><option>11</option><option>12</option><option>13</option><option>14</option><option>15</option><option>16</option><option>17</option><option>18</option><option>19</option><option>20</option><option>21</option><option>22</option><option>23</option></select></td>

The 3 in "return padNum(this.hours, 3)" has been replaced by 2, for a two digit hour and I have removed the second "time.AddHours(1);".

For some time I have been experimenting with "this.hours = (this.hours + h) % 576;" and learned that the 576 can be 24, 60, or any number at all and the "% 576" omitted altogether without returning an adverse result. Perhaps there is a clue here.

TimeTracker
08-01-2008, 12:36 AM
Chris, I did not realise there was a page two. This has never happened to me before.
I did as you suggested (I have each time anyway, usually twice) and it returns the same result as with selectedIndex. Hours are only supposed to be 0 > 23 and still the hour from the time selected is not divided into 24 portions. Put in 577 and it will return 01:00:30 and 02:00:30. 575 and under returns that value plus the next hour.

Jesdisciple
08-01-2008, 12:57 AM
Hah, I've done that before...

Since I'm not getting your results on my end, it's difficult to debug them... I've uploaded the page as I have it to http://jesdisciple.110mb.com/TimeTracker.html so I can be certain that your code is no different from mine. Does it work?

EDIT: Wait, does your last post indicate that it now works?

And I'm still curious what browsers you're testing in.

TimeTracker
08-01-2008, 02:24 AM
Chris, there was a thunderstorm and I always shut down during those events. I have the latest FireFox 2.0.0.16, Internet Explorer for XP and Netscape 7.1 (I did not like 8, so stayed with 7.1).

I get the same results as you. The %24 limits the number of hours to 24. My page will eventually have twenty-four text fields. Each successive text field will show the time to be 150 seconds (2.5 minutes) later than the previous one. So the first will be, starting at zero hour, 00:00:30, the second 00:03:00, the third 00:05:30 etc till 01:00:30.

It may be that DIMX's code cannot do the job. Where AddHours(1), I changed it to AddSeconds(150) and received stack overflow at line 34 message.

Jesdisciple
08-01-2008, 07:25 AM
DIMX made both AddSeconds and AddMinutes unconditionally recursive, but I'm quite certain he meant to stagger the functions, i.e. call the next highest function (if any) with the integer-part of x/t, where t is the current threshold (60 in both applicable cases). He also forgot to plug the constructor into these functions, so I've done that below.

After getting frustrated by the logarithms again, I asked some friends for help. One happened to have a simple zero-padding algorithm and gave it to me, so I incorporated it. Come to find out, I was making it way too complicated; the string's length is all I was after.
<!doctype html public "-//w3c//dtd html 4.0 transitional//en">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Dividing The Hour</title>
<script type="text/javascript">
//Code provided by Dynamic Drive (http://www.dynamicdrive.com/forums/.
<!--

function Time(h, m, s) {
this.hours = this.minutes = this.seconds = 0;
if(typeof h == "number"){
this.AddHours(h);
}
if(typeof m == "number"){
this.AddMinutes(m);
}
if(typeof s == "number"){
this.AddSeconds(s);
}
}

Time.prototype.AddTime = function(time) {
this.AddHours(time.hours);
this.AddMinutes(time.minutes);
this.AddSeconds(time.seconds);
}

Time.prototype.AddHours = function(h) {
this.hours = (this.hours + h) % 24;
}

Time.prototype.AddMinutes = function(m) {
this.minutes += m;
this.AddHours(Math.floor(this.minutes / 60));
this.minutes %= 60;
}

Time.prototype.AddSeconds = function(s) {
this.seconds += s;
this.AddMinutes(Math.floor(this.seconds / 60));
this.seconds %= 60;
}

Time.prototype.AsString = function() {
function padNum(num, digits){
num = String(Math.abs(num));
var zeroes = digits - num.length;
for(var i = 0; i < zeroes; i++){
num = '0' + num;
}
return num;
}
return padNum(this.hours, 2) + ":" + padNum(this.minutes, 2) + ":" + padNum(this.seconds, 2);
}

// Output to text field...

function makeList(df) {
var hrnum = parseInt(df.hrnum.value) + 1;
var minnum = df.minnum.selectedIndex + 1;
var time = new Time(eval(df.hrnum.value), eval(df.minnum.selectedIndex), eval(df.secnum.value));
time.AddHours(0);
var Hour2401 = df.Hour2401.value;
df.Hour2401.value = time.AsString();
time.AddHours(1);
var Hour0102 = df.Hour0102.value;
df.Hour0102.value = time.AsString();
time.AddHours(1);
}
// -->
</script>
</head>
<body text="#000000" bgcolor="#FFFFD5" link="#0000EE" vlink="#551A8B" alink="#FF0000">
&nbsp;
<center><table BORDER=0 CELLSPACING=2 CELLPADDING=5 COLS=1 WIDTH="600" >
<tr>
<td ALIGN=CENTER VALIGN=TOP WIDTH="50%"><form>
<center><table BORDER=0 CELLSPACING=0 CELLPADDING=5 COLS=4 WIDTH="320" >
<tr>
<td ALIGN=CENTER VALIGN=TOP WIDTH="60"><select name="hrnum" size="1"><option>00</option><option>01</option><option>02</option><option>03</option><option>04</option><option>05</option><option>06</option><option>07</option><option>08</option><option>09</option><option>10</option><option>11</option><option>12</option><option>13</option><option>14</option><option>15</option><option>16</option><option>17</option><option>18</option><option>19</option><option>20</option><option>21</option><option>22</option><option>23</option></select></td>

<td ALIGN=CENTER VALIGN=TOP WIDTH="60"><select name="minnum" size="1"><option>00</option><option>01</option><option>02</option><option>03</option><option>04</option><option>05</option><option>06</option><option>07</option><option>08</option><option>09</option><option>10</option><option>11</option><option>12</option><option>13</option><option>14</option><option>15</option><option>16</option><option>17</option><option>18</option><option>19</option><option>20</option><option>21</option><option>22</option><option>23</option><option>24</option><option>25</option><option>26</option><option>27</option><option>28</option><option>29</option><option>30</option><option>31</option><option>32</option><option>33</option><option>34</option><option>35</option><option>36</option><option>37</option><option>38</option><option>39</option><option>40</option><option>41</option><option>42</option><option>43</option><option>44</option><option>45</option><option>46</option><option>47</option><option>48</option><option>49</option><option>50</option><option>51</option><option>52</option><option>53</option><option>54</option><option>55</option><option>56</option><option>57</option><option>58</option><option>59</option></select></td>

<td><select name="secnum" size="1"><option>00</option><option>01</option><option>02</option><option>03</option><option>04</option><option>05</option><option>06</option><option>07</option><option>08</option><option>09</option><option>10</option><option>11</option><option>12</option><option>13</option><option>14</option><option>15</option><option>16</option><option>17</option><option>18</option><option>19</option><option>20</option><option>21</option><option>22</option><option>23</option><option>24</option><option>25</option><option>26</option><option>27</option><option>28</option><option>29</option><option selected="selected">30</option><option>31</option><option>32</option><option>33</option><option>34</option><option>35</option><option>36</option><option>37</option><option>38</option><option>39</option><option>40</option><option>41</option><option>42</option><option>43</option><option>44</option><option>45</option><option>46</option><option>47</option><option>48</option><option>49</option><option>50</option><option>51</option><option>52</option><option>53</option><option>54</option><option>55</option><option>56</option><option>57</option><option>58</option><option>59</option></select></td>

<td ALIGN=CENTER VALIGN=TOP WIDTH="200"><input type="button" value="Hourly Module" onclick="makeList(this.form)" /></td>
</tr>

<tr>
<td>
<div align=right><b><font face="Tahoma"><font size=-1><font color="#3333FF">HH</font><font color="#FFFFD5">----</font><font color="#3333FF">:</font></font></font></b></div>
</td>

<td><b><font face="Tahoma"><font size=-1><font color="#FFFFD5">--</font><font color="#3333FF">MM</font></font></font></b></td>

<td></td>
</tr>
</table></center>
</td>
</tr>
<tr>
<td>
<center><input type="text" name="Hour2401" size="10">'24/1' Begins |&nbsp;<input type="text" name="Hour0102" size="10">'1/2'
Starts</form></center>
</td>
</tr>
</table></center>
</body>
</html>

TimeTracker
08-01-2008, 08:01 AM
Chris, where in the script is there any provision to add 2 min 30 sec per portion of the sixty minutes? The hours and minutes are always the same. They are supposed to change incrementally. They are not doing this. Remember, 00:00:30 in one text field result, 00:03:00 in the next, 00:05:30 in the third, 00:08:00 in the fourth and so on. Please address this issue. There is no point otherwise. I want to be able to divide in normal clock time format a sixty minute period from one hour to the next and do so at any time of day or night. The user needs to match a time of birth with the results.

I take your point about "both AddSeconds and AddMinutes (being) unconditionally recursive," and will adjust his script accordingly. Thanks so much for that.

Jesdisciple
08-01-2008, 08:37 AM
I'm having some trouble with just how to manage the increment because I don't fully understand it. Should the existing text-inputs be simply repeated 24 times?

I think I updated the code after you posted, so you might want to get it again. I changed all fields to dropdown menus but kept the 30-second default.

TimeTracker
08-01-2008, 10:14 AM
Chris, this is how I was able to get DIMX's code to work. I have the full list of 24, but for the sake of space will delete over a half to give you the idea. The problem for this exercise is it only does hourly increments, not 2.5 minute increments. For the initial one it was perfect. That is the most frustrating aspect about the present exercise. Whenever I try to modify the (1)s to reflect 2 min 30 secs, I either get garbage or nothing. I keep getting stack overflow messages whenever I change time.AddHours(1) to time.AddMinutes(2.5) and so many other variations. It is wearing me down. It looks so simple, yet the simplicity escapes me.

time.AddHours(0);
var Hour2401 = df.Hour2401.value;
df.Hour2401.value = time.AsString();
time.AddHours(1);
var Hour0102 = df.Hour0102.value;
df.Hour0102.value = time.AsString();
time.AddHours(1);
var Hour0203 = df.Hour0203.value;
df.Hour0203.value = time.AsString();
time.AddHours(1);
var Hour0304 = df.Hour0304.value;
df.Hour0304.value = time.AsString();
time.AddHours(1);
var Hour0405 = df.Hour0405.value;
df.Hour0405.value = time.AsString();
...
time.AddHours(1);
var Hour1920 = df.Hour1920.value;
df.Hour1920.value = time.AsString();
time.AddHours(1);
var Hour2021 = df.Hour2021.value;
df.Hour2021.value = time.AsString();
time.AddHours(1);
var Hour2122 = df.Hour2122.value;
df.Hour2122.value = time.AsString();
time.AddHours(1);
var Hour2223 = df.Hour2223.value;
df.Hour2223.value = time.AsString();
time.AddHours(1);
var Hour2324 = df.Hour2324.value;
df.Hour2324.value = time.AsString();
}

TimeTracker
08-01-2008, 11:40 AM
Chris, thank you for adding the selectedIndex for "secnum". I have been experimenting a little more and have managed to add 2.5 or 1.5 min incrementally (I do not know why 1.5).
'24/1' is the same as the input values (prefix zeros do not appear with nums < 10) with '1/2' showing the first increment. At least this is a start.

Time.prototype.AsString = function() {
this.minutes = eval(this.minutes + 2);
this.minutes %= 60;
this.seconds = eval(this.seconds + 30);
this.seconds %= 60;
function padNum(num, digits){
num = String(Math.abs(num));
var zeroes = digits - num.length;
for(var i = 0; i < zeroes; i++){
num = '0' + num;
}
return num;
}
return padNum(this.hours, 2) + ":" + padNum(this.minutes, 2) + ":" + padNum(this.seconds, 2);
}

// Output to text field...

function makeList(df) {
var hrnum = parseInt(df.hrnum.value);
var minnum = parseInt(df.minnum.selectedIndex + 1);
var secnum = parseInt(df.secnum.value);
var time = new Time(eval(df.hrnum.value), eval(df.minnum.selectedIndex), eval(df.secnum.value));
time.AddHours(0);
var Hour2401 = df.Hour2401.value;
df.Hour2401.value = parseFloat(df.hrnum.value) + ":" + parseFloat(df.minnum.selectedIndex) + ":" + parseFloat(df.secnum.value);
time.AddHours(0);
var Hour0102 = df.Hour0102.value;
df.Hour0102.value = time.AsString();
time.AddHours(0);
var Hour0203 = df.Hour0203.value;
df.Hour0203.value = time.AsString();
time.AddHours(0);
var Hour0304 = df.Hour0304.value;
df.Hour0304.value = time.AsString();
}

I changed the button value to "Hourly Portion".

<tr>
<td>
<center><input type="text" name="Hour2401" size="10">'24/1' Begins |&nbsp;<input type="text" name="Hour0102" size="10">'1/2' Starts<br><input type="text" name="Hour0203" size="10">'2/3' Begins<input type="text" name="Hour0304" size="10">'3/4' Starts</form></center>
</td>
</tr>
</table></center>
</body>

Everything else is as you have presented it. At least we might be heading in the right direction. I did notice, though, when the time values for the minutes exceed the hour that it retains the hour value and does not advance. Try an example with 56 min to see this.

Jesdisciple
08-01-2008, 09:04 PM
I discovered that the value property is common to both text-inputs and select-menus, so the code now uses it "across the board" and the HTML can now switch between the two field-types without any changes being required of the JS.

I managed to stagger the functions backwards as well as forwards so they now take floating-point ("decimal") input, but for this I had to include a few more if-statements and Math.floors. The if-statements avoid infinite recursion and the Math.floors avoid floating-point output, e.g. the input 00:2.5:00 was outputting 00:2.5:30.

But I'm not understanding what you mean about "when the time values for the minutes exceed the hour that it retains the hour value and does not advance." I tried 00:56:00 and got the same; I tried 00:65:00 and got 01:05:00.

EDIT: I'm also not understanding the "Hourly Portion" thing, but I'll edit it into the code to see what you mean.
<!doctype html public "-//w3c//dtd html 4.0 transitional//en">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Dividing The Hour</title>
<script type="text/javascript">
//Code provided by Dynamic Drive (http://www.dynamicdrive.com/forums/).
<!--

function Time(h, m, s) {
this.hours = this.minutes = this.seconds = 0;
if(typeof h == "number"){
this.AddHours(h);
}
if(typeof m == "number"){
this.AddMinutes(m);
}
if(typeof s == "number"){
this.AddSeconds(s);
}
}

Time.prototype.AddTime = function(time) {
this.AddHours(time.hours);
this.AddMinutes(time.minutes);
this.AddSeconds(time.seconds);
}

Time.prototype.AddHours = function(h) {
this.hours = (this.hours + Math.floor(h)) % 24;
var m = Math.floor(h % 1 * 60);
if(m > 0){
this.AddMinutes(m);
}
}

Time.prototype.AddMinutes = function(m) {
this.minutes += Math.floor(m);
var h = Math.floor(this.minutes / 60);
if(h > 0){
this.AddHours(h);
}
this.minutes %= 60;
var s = Math.floor(m % 1 * 60);
if(s > 0){
this.AddSeconds(s);
}
}

Time.prototype.AddSeconds = function(s) {
this.seconds += Math.floor(s);
var m = Math.floor(this.seconds / 60);
if(m > 0){
this.AddMinutes(m);
}
this.seconds %= 60;
}

Time.prototype.AsString = function() {
function padNum(num, digits){
num = String(Math.abs(num));
var zeroes = digits - num.length;
for(var i = 0; i < zeroes; i++){
num = '0' + num;
}
return num;
}
return padNum(this.hours, 2) + ":" + padNum(this.minutes, 2) + ":" + padNum(this.seconds, 2);
}

// Output to text field...

function makeList(df) {
var hrnum = parseInt(df.hrnum.value) + 1;
var minnum = df.minnum.value + 1;
var time = new Time(eval(df.hrnum.value), eval(df.minnum.value), eval(df.secnum.value));
time.AddHours(0);
var Hour2401 = df.Hour2401.value;
df.Hour2401.value = time.AsString();
time.AddHours(1);
var Hour0102 = df.Hour0102.value;
df.Hour0102.value = time.AsString();
time.AddHours(1);
}
// -->
</script>
</head>
<body text="#000000" bgcolor="#FFFFD5" link="#0000EE" vlink="#551A8B" alink="#FF0000">
&nbsp;
<center><table BORDER=0 CELLSPACING=2 CELLPADDING=5 COLS=1 WIDTH="600" >
<tr>
<td ALIGN=CENTER VALIGN=TOP WIDTH="50%"><form>
<center><table BORDER=0 CELLSPACING=0 CELLPADDING=5 COLS=4 WIDTH="320" >
<tr>
<td ALIGN=CENTER VALIGN=TOP WIDTH="60"><select name="hrnum" size="1"><option>00</option><option>01</option><option>02</option><option>03</option><option>04</option><option>05</option><option>06</option><option>07</option><option>08</option><option>09</option><option>10</option><option>11</option><option>12</option><option>13</option><option>14</option><option>15</option><option>16</option><option>17</option><option>18</option><option>19</option><option>20</option><option>21</option><option>22</option><option>23</option></select></td>

<td ALIGN=CENTER VALIGN=TOP WIDTH="60"><input type="text" name="minnum" size="1"></td>

<td ALIGN=CENTER VALIGN=TOP WIDTH="60"><select name="secnum" size="1"><option>00</option><option>01</option><option>02</option><option>03</option><option>04</option><option>05</option><option>06</option><option>07</option><option>08</option><option>09</option><option>10</option><option>11</option><option>12</option><option>13</option><option>14</option><option>15</option><option>16</option><option>17</option><option>18</option><option>19</option><option>20</option><option>21</option><option>22</option><option>23</option><option>24</option><option>25</option><option>26</option><option>27</option><option>28</option><option>29</option><option selected="selected">30</option><option>31</option><option>32</option><option>33</option><option>34</option><option>35</option><option>36</option><option>37</option><option>38</option><option>39</option><option>40</option><option>41</option><option>42</option><option>43</option><option>44</option><option>45</option><option>46</option><option>47</option><option>48</option><option>49</option><option>50</option><option>51</option><option>52</option><option>53</option><option>54</option><option>55</option><option>56</option><option>57</option><option>58</option><option>59</option></select></td>

<td ALIGN=CENTER VALIGN=TOP WIDTH="200"><input type="button" value="Hourly Module" onclick="makeList(this.form)" /></td>
</tr>

<tr>
<td>
<div align=right><b><font face="Tahoma"><font size=-1><font color="#3333FF">HH</font><font color="#FFFFD5">----</font><font color="#3333FF">:</font></font></font></b></div>
</td>

<td><b><font face="Tahoma"><font size=-1><font color="#FFFFD5">--</font><font color="#3333FF">MM</font></font></font></b></td>

<td></td>
</tr>
</table></center>
</td>
</tr>
<tr>
<td>
<center><input type="text" name="Hour2401" size="10">'24/1' Begins |&nbsp;<input type="text" name="Hour0102" size="10">'1/2'
Starts</form></center>
</td>
</tr>
</table></center>
</body>
</html>

TimeTracker
08-02-2008, 12:17 AM
Chris, thank you for bearing with me. This is where my code is at. Copy and paste it to see what it does. It is nearly there, but not quite. I feel certain that you can work the logic properly.

Forget the notion of an hourly portion. Suppose somebody wants to divide a day's activities into 25 or 35 minute segments starting from 9:15 a.m. Next to each output result text field they have a text area where they can fill in the activity details and then print out the schedule. It would be great for planning. This code has potential for wider usage. Here is my code.

<!doctype html public "-//w3c//dtd html 4.0 transitional//en">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Dividing The Hour</title>
<script type="text/javascript">
//Code provided by Dynamic Drive (http://www.dynamicdrive.com/forums/.
<!--

function Time(h, m, s) {
this.hours = this.minutes = this.seconds = 0;
if(typeof h == "number"){
this.AddHours(h);
}
if(typeof m == "number"){
this.AddMinutes(m);
}
if(typeof s == "number"){
this.AddSeconds(s);
}
}

Time.prototype.AddTime = function(time) {
this.AddHours(time.hours);
this.AddMinutes(time.minutes);
this.AddSeconds(time.seconds);
}

Time.prototype.AddHours = function(h) {
this.hours = (this.hours + h) % 24;
}

Time.prototype.AddMinutes = function(m) {
this.minutes += m;
this.AddHours(Math.floor(this.minutes / 60));
this.minutes %= 60;
}

Time.prototype.AddSeconds = function(s) {
this.seconds += s;
this.AddMinutes(Math.floor(this.seconds / 60));
this.seconds %= 60;
}

Time.prototype.AsString = function() {
this.hours = eval(this.hours + 0);
this.hours %= 24;
this.minutes = eval(this.minutes + 2);
this.minutes %= 60;
this.seconds = eval(this.seconds + 30);
this.seconds %= 60;
function padNum(num, digits){
num = String(Math.abs(num));
var zeroes = digits - num.length;
for(var i = 0; i < zeroes; i++){
num = '0' + num;
}
return num;
}
return padNum(this.hours, 2) + ":" + padNum(this.minutes, 2) + ":" + padNum(this.seconds, 2);
}

// Output to text field...

function makeList(df) {
var hrnum = parseInt(df.hrnum.value);
var minnum = parseInt(df.minnum.selectedIndex + 1);
var secnum = parseInt(df.secnum.value);
var time = new Time(eval(df.hrnum.value), eval(df.minnum.selectedIndex), eval(df.secnum.value));
time.AddHours(0);
var Hour2401 = df.Hour2401.value;
df.Hour2401.value = parseFloat(df.hrnum.value) + ":" + parseFloat(df.minnum.selectedIndex) + ":" + parseFloat(df.secnum.value);
time.AddHours(0);
var Hour0102 = df.Hour0102.value;
df.Hour0102.value = time.AsString();
time.AddHours(0);
var Hour0203 = df.Hour0203.value;
df.Hour0203.value = time.AsString();
time.AddHours(0);
var Hour0304 = df.Hour0304.value;
df.Hour0304.value = time.AsString();
time.AddHours(0);
var Hour0405 = df.Hour0405.value;
df.Hour0405.value = time.AsString();
time.AddHours(0);
var Hour0506 = df.Hour0506.value;
df.Hour0506.value = time.AsString();
}
// -->
</script>
</head>
<body text="#000000" bgcolor="#FFFFD5" link="#0000EE" vlink="#551A8B" alink="#FF0000">
&nbsp;
<center><table BORDER=0 CELLSPACING=2 CELLPADDING=5 COLS=1 WIDTH="600" >
<tr>
<td ALIGN=CENTER VALIGN=TOP WIDTH="50%"><form>
<center><table BORDER=0 CELLSPACING=0 CELLPADDING=5 COLS=4 WIDTH="320" >
<tr>
<td ALIGN=CENTER VALIGN=TOP WIDTH="60"><select name="hrnum" size="1"><option>00</option><option>01</option><option>02</option><option>03</option><option>04</option><option>05</option><option>06</option><option>07</option><option>08</option><option>09</option><option>10</option><option>11</option><option>12</option><option>13</option><option>14</option><option>15</option><option>16</option><option>17</option><option>18</option><option>19</option><option>20</option><option>21</option><option>22</option><option>23</option></select></td>

<td ALIGN=CENTER VALIGN=TOP WIDTH="60"><select name="minnum" size="1"><option>00</option><option>01</option><option>02</option><option>03</option><option>04</option><option>05</option><option>06</option><option>07</option><option>08</option><option>09</option><option>10</option><option>11</option><option>12</option><option>13</option><option>14</option><option>15</option><option>16</option><option>17</option><option>18</option><option>19</option><option>20</option><option>21</option><option>22</option><option>23</option><option>24</option><option>25</option><option>26</option><option>27</option><option>28</option><option>29</option><option>30</option><option>31</option><option>32</option><option>33</option><option>34</option><option>35</option><option>36</option><option>37</option><option>38</option><option>39</option><option>40</option><option>41</option><option>42</option><option>43</option><option>44</option><option>45</option><option>46</option><option>47</option><option>48</option><option>49</option><option>50</option><option>51</option><option>52</option><option>53</option><option>54</option><option>55</option><option>56</option><option>57</option><option>58</option><option>59</option></select></td>

<td><select name="secnum" size="1"><option>00</option><option>01</option><option>02</option><option>03</option><option>04</option><option>05</option><option>06</option><option>07</option><option>08</option><option>09</option><option>10</option><option>11</option><option>12</option><option>13</option><option>14</option><option>15</option><option>16</option><option>17</option><option>18</option><option>19</option><option>20</option><option>21</option><option>22</option><option>23</option><option>24</option><option>25</option><option>26</option><option>27</option><option>28</option><option>29</option><option selected="selected">30</option><option>31</option><option>32</option><option>33</option><option>34</option><option>35</option><option>36</option><option>37</option><option>38</option><option>39</option><option>40</option><option>41</option><option>42</option><option>43</option><option>44</option><option>45</option><option>46</option><option>47</option><option>48</option><option>49</option><option>50</option><option>51</option><option>52</option><option>53</option><option>54</option><option>55</option><option>56</option><option>57</option><option>58</option><option>59</option></select></td>

<td ALIGN=CENTER VALIGN=TOP WIDTH="200"><input type="button" value="Hourly Portion" onclick="makeList(this.form)" /></td>
</tr>

<tr>
<td>
<div align=right><b><font face="Tahoma"><font size=-1><font color="#3333FF">HH</font><font color="#FFFFD5">----</font><font color="#3333FF">:</font></font></font></b></div>
</td>

<td><b><font face="Tahoma"><font size=-1><font color="#FFFFD5">--</font><font color="#3333FF">MM</font></font></font></b></td>

<td></td>
</tr>
</table></center>
</td>
</tr>
<tr>
<td>
<center><input type="text" name="Hour2401" size="10">'24/1' Begins |&nbsp;<input type="text" name="Hour0102" size="10">'1/2' Starts<br><input type="text" name="Hour0203" size="10">'2/3' Begins |&nbsp;<input type="text" name="Hour0304" size="10">'3/4' Starts<br><input type="text" name="Hour0405" size="10">'4/5' Begins |&nbsp;<input type="text" name="Hour0506" size="10">'5/6' Starts</form></center>
</td>
</tr>
</table></center>
</body>
</html>

Jesdisciple
08-02-2008, 02:13 AM
Before you posted, I had my own version of the code, and I've just finished merging them. I also generally cleaned them up and made them standards-compliant except where it broke something (most commonly the alignment of elements). Of course, Firefox never exited Quirks Mode because of the non-compliance, so I don't fault it (as Quirks Mode is designed to allow for the non-compliance of outdated or otherwise non-compliant pages). I might try throwing it into Standards Compliance Mode to see if stuff is still broken.

While I was merging them I caught a bug that was common between them, but from what I can see it's not in the script. I think Firefox has a bug with its select-menus that makes assignments to their value or selectedIndex properties fail only in certain cases. Anyway, I removed the select-menus from the code because of this bug, and they probably needed to go anyway as they didn't work with floating-points.

The feature I've included which made the bug visible allows you to move any of the output times to the input fields. I think this will help with how many times you need to calculate at once and thus how many output fields you need.
<!doctype html public "-//w3c//dtd html 4.0 transitional//en">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Dividing The Hour</title>
<script type="text/javascript"><!--
//Code provided by Dynamic Drive (http://www.dynamicdrive.com/forums/).

// modified from http://extjs.com/forum/showthread.php?t=26644
function clone(o) {
if(!o || 'object' !== typeof o) {
return o;
}
var c = 'function' === typeof o.pop ? [] : {};
for(var p in o) {
var v = o[p];
if(v && 'object' === typeof v) {
c[p] = clone(v);
} else {
c[p] = v;
}
}
return c;
};


function Time(h, m, s) {
this.constructor = Time;
this.hours = this.minutes = this.seconds = 0;
if(typeof h == "number"){
this.AddHours(h);
}
if(typeof m == "number"){
this.AddMinutes(m);
}
if(typeof s == "number"){
this.AddSeconds(s);
}
}

Time.prototype = {
AddTime: function(time) {
this.AddHours(time.hours);
this.AddMinutes(time.minutes);
this.AddSeconds(time.seconds);
},

AddHours: function(h) {
this.hours = (this.hours + Math.floor(h)) % 24;
var m = Math.floor(h % 1 * 60);
if(m > 0){
this.AddSeconds(m);
}
},

AddMinutes: function(m) {
this.minutes += Math.floor(m);
var h = Math.floor(this.minutes / 60);
if(h > 0){
this.AddHours(h);
}
this.minutes %= 60;
var s = Math.floor(m % 1 * 60);
if(s > 0){
this.AddSeconds(s);
}
},

AddSeconds: function(s) {
this.seconds += Math.floor(s);
var m = Math.floor(this.seconds / 60);
if(m > 0){
this.AddMinutes(m);
}
this.seconds %= 60;
},

AsString: function() {
function padNum(num, digits){
num = String(Math.abs(num));
var zeroes = digits - num.length;
for(var i = 0; i < zeroes; i++){
num = '0' + num;
}
return num;
}
return padNum(this.hours, 2) + ":" + padNum(this.minutes, 2) + ":" + padNum(this.seconds, 2);
}
};

// Output to text field...

function makeList(df) {
function dress(name){
//prepare
time.AddMinutes(2.5);

df[name].value = time.AsString();
df['apply_' + name].time = clone(time);
df['apply_' + name].onclick = function () {
df.hrnum.value = this.time.hours;
df.minnum.value = this.time.minutes;
df.secnum.value = this.time.seconds;
};
}

var hrnum = parseInt(df.hrnum.value);
var minnum = parseInt(df.minnum.value + 1);
var secnum = parseInt(df.secnum.value);
var time = new Time(parseFloat(df.hrnum.value), parseFloat(df.minnum.value), parseFloat(df.secnum.value));
dress('Hour2401');
dress('Hour0102');
dress('Hour0203');
dress('Hour0304');
dress('Hour0405');
dress('Hour0506');
}
//--></script>
</head>
<body text="#000000" bgcolor="#FFFFD5" link="#0000EE" vlink="#551A8B" alink="#FF0000" width="100%">
<center>
Clicking the button which displays the hourly portion's name enters the corresponding time into the input form.<br>
<form>
<table border="0" cellspacing="2" cellpadding="5" cols="1" width="600">
<tr>
<td align="center" style="vertical-align: top; width: 50%;" colspan="2">
<table BORDER=0 CELLSPACING=0 CELLPADDING=5 COLS=4 WIDTH="320">
<tr>
<td style="text-align: center; vertical-align: top; width: 60;"><input type="text" name="hrnum" value="0" size="1"></td>
<td></td>
<td style="text-align: center; vertical-align: top; width: 60;"><input type="text" name="minnum" value="0" size="1"></td>
<td></td>
<td style="text-align: center; vertical-align: top; width: 60;"><input type="text" name="secnum" value="30" size="1"></td>

<td style="text-align: center; vertical-align: top; width: 200;"><input type="button" value="Hourly Portion" onclick="makeList(this.form)"></td>
</tr>
<tr>
<td style="text-align: right; font-weight: bold; font-family: Tahoma; font-size: 1; color: #3333FF;">HH</td>
<td style="text-align: right; font-weight: bold; font-family: Tahoma; font-size: 1; color: #3333FF;">:</td>
<td style="text-align: center; font-weight: bold; font-family: Tahoma; font-size: 1; color: #3333FF;">MM</td>
<td style="text-align: left; font-weight: bold; font-family: Tahoma; font-size: 1; color: #3333FF;">:</td>
<td style="text-align: left; font-weight: bold; font-family: Tahoma; font-size: 1; color: #3333FF;">SS</td>
</tr>
</table>
</td>
</tr>
<tr>
<td style="text-align: right;">
<input type="text" name="Hour2401" size="5"><input type="button" name="apply_Hour2401" value="24/1">
</td>
<td style="text-align: left;">
<input type="text" name="Hour0102" size="5"><input type="button" name="apply_Hour0102" value="1/2">
</td>
</tr>
<tr>
<td style="text-align: right;">
<input type="text" name="Hour0203" size="5"><input type="button" name="apply_Hour0203" value="2/3">
</td>
<td style="text-align: left;">
<input type="text" name="Hour0304" size="5"><input type="button" name="apply_Hour0304" value="3/4">
</td>
</tr>
<tr>
<td style="text-align: right;">
<input type="text" name="Hour0405" size="5"><input type="button" name="apply_Hour0405" value="4/5">
</td>
<td style="text-align: left;">
<input type="text" name="Hour0506" size="5"><input type="button" name="apply_Hour0506" value="5/6">
</td>
</tr>
</table>
</form>
</center>
</body>
</html>

TimeTracker
08-02-2008, 03:03 AM
Chris, it is brilliant, except '24/1' is supposed to be the same time as the input text field. The incrementing appears first at '1/2'. And I do not need to press a portion button once the results appear in the text fields. There will be 24 of them. The job will be done.

However, if a link could be attached to them, that would be fantastic, because I could create a popup window with information on it. I told you that you are a genius! Could you do that for me please? It has applications beyond this exercise.

Jesdisciple
08-02-2008, 03:45 AM
Chris, it is brilliant, except '24/1' is supposed to be the same time as the input text field. The incrementing appears first at '1/2'.That's easy enough to fix; just move the first to lines in function dress (the comment and the function-call) to the bottom of the same function.


And I do not need to press a portion button once the results appear in the text fields. There will be 24 of them. The job will be done.Is that to make your job of copying them easier? If so, we really ought to ditch the output-fields altogether; we can just put the text directly in the table-cells and you can highlight them all at once.


However, if a link could be attached to them, that would be fantastic, because I could create a popup window with information on it. ... Could you do that for me please? It has applications beyond this exercise.If the info in the popup depends on the link being clicked, I need to know how. And does the window need a special size, appearance, etc.?


I told you that you are a genius!My brain majors on the minors and minors on the majors; if that's what you call genius, then sure I am... It's very frustrating despite the envy of "normal" people who don't see the struggles I endure to succeed in this society they built. (Note that I'm not offended - just expressing frustration.)

TimeTracker
08-02-2008, 07:17 AM
Chris, this is how I arranged the code for 2401 to reflected the input values. Also I re-established selectedIndex. For those who find this script interesting...

function makeList(df) {
function dress(name){
df[name].value = time.AsString();
df['apply_' + name].time = clone(time);
//prepare
time.AddMinutes(2.5); //change minutes to suit
df['apply_' + name].onclick = function () {
df.hrnum.selectedIndex = this.time.hours;
df.minnum.selectedIndex = this.time.minutes;
df.secnum.selectedIndex = this.time.seconds;
};
}

var hrnum = parseInt(df.hrnum.selectedIndex);
var minnum = parseInt(df.minnum.selectedIndex);
var secnum = parseInt(df.secnum.selectedIndex);
var time = new Time(parseFloat(df.hrnum.selectedIndex), parseFloat(df.minnum.selectedIndex), parseFloat(df.secnum.selectedIndex));
dress('Hour2401');

Rather than having a page with lots of buttons, I hid them (type="hidden") and added text links to open windows. As for the array of text field, style parameters deal with that.

<td><input type="text" name="Hour2401" style="width:55px;color:darkblue;border:0;background-color:#FFFFCC"><input type="hidden" name="apply_Hour2401" value="24/1">-
<a href="#null" onClick="newWindow('portion2401.html','','610','550','scrollbars')">'24/1'</a></td>

Thank you for all the time and effort you have put into this. I see that you are busy with other coders, so will leave it at that.

Generally the strugglers outlast the 'normal' people anyway. They are more in touch with their survival mode. As older people say, the best revenge for parents is to see their grandchildren for only a few hours at a time. So you have a handicap. Turn it into a positive and it becomes an asset. I understand a lot of where you are coming from, for I too have a cross to bear.

Till next time! Dynamic Drive is the best.