### Computing The Time Elements (hh, mm, ss)

There are slightly different procedures for computing the time elements (`hh,mm,ss`) depending on the starting argument and the type of time we are computing.  e.g. is it an actual time of day or a fraction of a day converted into equivalent time elements.

All times used here will be expressed in the universal standard `00`h to `24`h format.

There are three basic sources of fractions that will be converted into time elements.
• If the starting argument is a general Julian Day number ((`JD`), to compute the time elements from its decimal part, Algorithm 2a applies.

• If the starting argument is a time interval expressed as a fraction of a day (`DayFrac`), then Algorithm 2b applies.

• If the starting argument is a time interval expressed in decimal (`hours`), then Algorithm 2c applies.

Algorithm 2a:

Given any general JD number, compute the time elements (`hh,mm,ss`) from its decimal part.  These time elements are will all equate to integer values with the seconds value (`ss`) rounded-off to the nearest second.

```     uu = JD + 0.5
hours = 24*(uu - floor(uu))
hh = floor(hours)
minutes = 60*(hours - hh)
mm = floor(minutes)
seconds = 60*(minutes - mm)
ss = floor(seconds + 0.5)
```

RANDOM EXAMPLE 1:
Given:
`JD = 2448103.872299210834`

To find the time of day elements (`hh,mm,ss`) from the decimal part of any general JD number:
```     JD = 2448103.872299210834
uu = JD + 0.5 = 2448104.372299210834
hours = 24*(uu - floor(uu)) = 8.93518105522

hh = floor(hours) = 08
minutes = 60*(hours - hh) = 56.1108633131
mm = floor(minutes) = 56
seconds = 60*(minutes - mm) = 06.652
ss = floor(seconds + 0.5) = 07
```
So the time of day elements, in this case, work out to:
`hh:mm:ss = 08:56:07 = 08h 56m 07s`
resolved to the nearest second.

Algorithm 2b:

Given a (±`DayFrac`) value, compute the corresponding time elements (`TimeSignVal, hh, mm, ss`)

``` if DayFrac < 0 then TimeSignVal = -1 else TimeSignVal = 1

hours = TimeSignVal * 24 * DayFrac
hh = floor(hours)
minutes = 60*(hours - hh)
mm = floor(minutes)
seconds = 60*(minutes - mm)
ss = floor(seconds + 0.5)
```
or
``` TimeSignVal = (DayFrac < 0)? -1:1

hours = TimeSignVal * 24 * DayFrac
hh = floor(hours)
minutes = 60*(hours - hh)
mm = floor(minutes)
seconds = 60*(minutes - mm)
ss = floor(seconds + 0.5)
```

RANDOM EXAMPLE 2:
Given:
`DayFrac = 0.4039646880429179`

To find the time elements (`TimeSignVal, hh,mm,ss`) corresponding to day fraction (`±DayFrac`):
``` TimeSignVal = (DayFrac < 0)? -1:1 = 1
hours = TimeSignVal * 24 * DayFrac = 9.69515251303
hh = floor(hours) = 09
minutes = 60*(hours - hh) = 41.7091507818
mm = floor(minutes) = 41
seconds = 60*(minutes - mm) = 42.549
ss = floor(seconds + 0.5) = 43
```
So the time elements corresponding to the fraction of a day, in this case, work out to:
`hh:mm:ss = 09:41:43 = 09h 41m 43s`
resolved to the nearest second.

Algorithm 2c:

Given an (`±hours`) value, compute the corresponding time elements (`TimeSignVal, hh,mm,ss`).

``` if hours < 0 then TimeSignVal = -1 else TimeSignVal = 1

uu = TimeSignVal * hours
hh = floor(uu)
ww = 60*(uu - hh)
mm = floor(ww)
ss = 60*(ww - mm)
```
or
``` TimeSignVal = (hours < 0)? -1:1

uu = TimeSignVal * hours
hh = floor(uu)
ww = 60*(uu - hh)
mm = floor(ww)
ss = 60*(ww - mm)
```

RANDOM EXAMPLE 3:
Given:
`hours = 1.40803817175960`

To find the time elements (`hh,mm,ss`) corresponding to the decimal (`hours`) value:
``` TimeSign = (1.40803817175960 < 0)? -1:1 = 1
hours = 1.40803817175960
hh = floor(hours) = 01
ww = 60*(hours - hh) = 24.4822903056
mm = floor(ww) = 24
ss = 60*(ww - mm) = 28.937
```
So the time elements, corresponding to the hours value, in this case, work out to:
`hh:mm:ss = 01:24:28.937 = 01h 24m 28.937s`
resolved to the nearest millisecond.