Determining the time, and date in turing
Author |
Message |
xXInsanityXx
|
Posted: Sun Nov 27, 2005 8:14 am Post subject: 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 |
|
|
|
|
|
Sponsor Sponsor
|
|
|
Cervantes
|
Posted: Sun Nov 27, 2005 9:31 am Post subject: (No subject) |
|
|
There is. Check out the Time module in the Turing Help manual. |
|
|
|
|
|
xXInsanityXx
|
Posted: Sun Nov 27, 2005 11:05 am Post subject: (No subject) |
|
|
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:
code: |
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
|
Posted: Sun Nov 27, 2005 11:23 am Post subject: (No subject) |
|
|
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:
code: |
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:
code: |
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.
code: |
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
|
Posted: Sun Nov 27, 2005 11:30 am Post subject: (No subject) |
|
|
Note: Pseudocode!
code: | 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
|
Posted: Sun Nov 27, 2005 1:09 pm Post subject: (No subject) |
|
|
MysticVegeta wrote:
code: | 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
|
Posted: Sun Nov 27, 2005 2:22 pm Post subject: (No subject) |
|
|
subtract 12 then instead of making 2 arrays. |
|
|
|
|
|
Cervantes
|
Posted: Sun Nov 27, 2005 2:54 pm Post subject: (No subject) |
|
|
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. |
|
|
|
|
|
Sponsor Sponsor
|
|
|
|
|