
-----------------------------------
xXInsanityXx
Sun Nov 27, 2005 8:14 am

Determining the time, and date in turing
-----------------------------------
Hello, I was wondering if there is a way to determine the time and date of a PC (The one on the taskbar) in Turing?

Please and Thank you

-----------------------------------
Cervantes
Sun Nov 27, 2005 9:31 am


-----------------------------------
There is.  Check out the Time module in the Turing Help manual.

-----------------------------------
xXInsanityXx
Sun Nov 27, 2005 11:05 am


-----------------------------------
I checked the time module in turing help file, but im still not satified, Time.Date gives out the time and date in this format "27 Nov 05 10:59:37"
but what if i want "Nov" in full form "November", do i have to make a bunch of if statements?

like:

var dateTime,month: string
dateTime:= Time.Date
month:= dateTime(4..6)

if month = "Nov" or month = "Dec"
then
month+= "ember"
end if 


Or is there a way to simplify it?

-----------------------------------
Cervantes
Sun Nov 27, 2005 11:23 am


-----------------------------------
Generally, creating a bunch of if statements is not the way to go about things.

A hash would be great for this.  But alas, Turing does not support hashes.

Well, you can create two arrays:

const abbreviated_months : array 1 .. 12 of string := init ("Jan", "Feb" ... )
const full_months : array 1 .. 12 of string := init ("January", "February" ... )

Better yet, create an array of a record.  I'm not exactly sure how the initing goes for this, so I'm just taking a guess:

const month_names : array 1 .. 12 of
      record
            abbreviation, full : string
      end record
      := init ("Jan", "January", "Feb", "February" ... )


Then to switch, you'll match the abbreviation with the string you're given, then convert that into a full month name.


var this_month := "Nov"
for i : 1 .. 12
    if this_month = month_names (i).abbreviation then
        this_month := month_names (i).full
        exit
     end if
end for


-----------------------------------
MysticVegeta
Sun Nov 27, 2005 11:30 am


-----------------------------------
Note: Pseudocode!

var month := "Nov"
var months : array 1..24 of string := init("Jan", "Feb"...."Dec", "January"...
"December"
for x : 1..24
if month = months(x) then
month := months (x+12)
end if
end for


-----------------------------------
Cervantes
Sun Nov 27, 2005 1:09 pm


-----------------------------------

var month := "Nov"
var months : array 1..24 of string := init("Jan", "Feb"...."Dec", "January"...
"December"
for x : 1..24
if month = months(x) then
month := months (x+12)
end if
end for

That for loop should only go from 1 to 12.  Otherwise, if month is something like "February", your program will crash.

-----------------------------------
MysticVegeta
Sun Nov 27, 2005 2:22 pm


-----------------------------------
subtract 12 then instead of making 2 arrays.

-----------------------------------
Cervantes
Sun Nov 27, 2005 2:54 pm


-----------------------------------
I think even two arrays is better than this approach.  It more effectively conveys what the arrays are storing.  One array containing two different sets of data can confuse people.  And the one array of a record is definately the most expressive way to do this, thus far.
