Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 Determining the time, and date in turing
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
xXInsanityXx




PostPosted: 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
Sponsor
sponsor
Cervantes




PostPosted: Sun Nov 27, 2005 9:31 am   Post subject: (No subject)

There is. Check out the Time module in the Turing Help manual.
xXInsanityXx




PostPosted: 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




PostPosted: 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




PostPosted: 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




PostPosted: 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




PostPosted: Sun Nov 27, 2005 2:22 pm   Post subject: (No subject)

subtract 12 then instead of making 2 arrays.
Cervantes




PostPosted: 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
Sponsor
sponsor
Display posts from previous:   
   Index -> Programming, Turing -> Turing Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 8 Posts ]
Jump to:   


Style:  
Search: