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

Username:   Password: 
 RegisterRegister   
 defining time
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
iluvchairs112




PostPosted: Mon Aug 18, 2008 8:13 pm   Post subject: defining time

is it possible to definine a variable using a unit of time?
ex. minutes, seconds, miliseconds?
so that it is entered 1.22.89
thanks Smile
Sponsor
Sponsor
Sponsor
sponsor
CodeMonkey2000




PostPosted: Mon Aug 18, 2008 9:23 pm   Post subject: RE:defining time

I'm not sure what you mean. You could define a class or structure Time, if that' what you mean.
Tony




PostPosted: Mon Aug 18, 2008 11:14 pm   Post subject: RE:defining time

Well time is interpreted (depending on where you get it from) as a number of seconds as either an integer or a float-point number.
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
btiffin




PostPosted: Tue Aug 19, 2008 2:15 am   Post subject: RE:defining time

Use REBOL Smile
code:

>> t: 03:08:01
== 3:08:01
>> t/hour
== 3
>> t/minute
== 8
>> t/second
== 1.0
>> d: 19-Aug-2008
== 19-Aug-2008
>> d/day
== 19
>> d/month
== 8
>> d/year
== 2008
>> dt: 19-Aug-2008/03:08:15
== 19-Aug-2008/3:08:15
>> now
== 19-Aug-2008/3:11:28-4:00
>> t: make time! [1 2 3]
== 1:02:03
>> t: make date! [1 2 3]
== 1-Feb-0003

One of the few languages I know of with a time! and date! datatype.

Excuse the interruption to the Turing forum.

Cheers
DemonWasp




PostPosted: Tue Aug 19, 2008 8:27 am   Post subject: RE:defining time

Erm...don't most languages have either Date and Time classes or something like a DateTime? Java, C# and Javascript certainly do, and as I recall, C++ has about 7 of each (because that's how C++ rolls).
SNIPERDUDE




PostPosted: Tue Aug 19, 2008 9:26 am   Post subject: RE:defining time

lol. The language I've been meaning to learn for a good while now...

Already know Turing, Java, VB, HTML.

But on topic: Yea, turing should have a built in time function, look it up on help.
iluvchairs112




PostPosted: Tue Aug 19, 2008 9:27 am   Post subject: RE:defining time

I know time is measured in seconds and I could just use integers. However that will take a lot longer.
What I want to do is get a certain amount of times from the user and sort them from least time to most time.
DemonWasp




PostPosted: Tue Aug 19, 2008 9:40 am   Post subject: RE:defining time

Well, you could do it the right way, or the cheap way.

The Right Way:
Parse the input you're given (hours.minutes.seconds?) and convert entirely to seconds or somesuch. Store that information and use those to do the sorts. Have a function that outputs the time corresponding to that number.

The Cheap Way:
Make sure all your input is in the form like the following:
08.06.15 (for 8 hours, 6 minutes, 15 seconds)
12.52.01 (for 12 hours, 52 minutes, 1 second)
Then you can just use string-based comparisons to sort them into their overall order. The leading zeros are important so that the digits with the same magnitude are being compared.

I'd do the Right Way myself, since it's actually probably easier and is guaranteed to work better (don't need any funny leading zeros or other nonsense).
Sponsor
Sponsor
Sponsor
sponsor
iluvchairs112




PostPosted: Tue Aug 19, 2008 9:50 am   Post subject: RE:defining time

Thanks. Why I didn't think of "The Right Way" myself, I don't know Razz
That is how I will do it ... that actually makes everything a whole lot easier. I was overthinking it all :S
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  [ 9 Posts ]
Jump to:   


Style:  
Search: