About Monkey 2 › Forums › Monkey 2 Programming Help › Time, CurrentTime & etc
Tagged: currentDate, currenttime, time
This topic contains 4 replies, has 3 voices, and was last updated by
nerobot 2 years ago.
-
AuthorPosts
-
July 3, 2016 at 7:56 am #1632
Hi
just found (thanks to Therevills) that CurrentTime() & CurrentDate() are implemented (sort of) in the Class Time.
I have looked at the source code but I have some questions
1
I would implement my CurrentDate() function (ala BlitzMax, so 02 jul 2016 as returned string). As some fields are Private I can’t (without changing the main source code) create a thing like this (or I didn’t found the correct way to do it)
I’ve hacked the CurrentDate() function in BlitzMax to use the standard Posix (I believe it’s called so) use of %d %m %Y to use them in combination
I suspect I need to buid something for my own, no a big problem
2.
Looking at the source code I found this in the comment for the documentation
Monkey12345678910#rem monkeydoc Overloaded compare operator.Time x is 'less than' time y if time x represents a time 'earlier' than time y.#endOperator<=>:Int( time:Time )Return libc.difftime( _timer,time._timer )<=>0EndAny example of this operator should work?
3.
And what does mean the @hidden parameter in the #rem comment
Monkey12#rem monkeydoc @hidden Time class.#endIn the documentation there’s no reference about the fieds/properties Hour, Minutes, etc so I can think that this @hidden parameter it’s related.
Or I’m wrong?
ps: I know there is a .ToString() method and I can extract the info I need, it’s only to learn a bit MX2 code (and its limitations).
Monkey123456789101112Function CurrentDate:String()Local t:Time=Time.Now()Local ts:String=t.ToString()Return ts.Slice(4,15)EndFunction CurrentTime:String()Local t:Time=Time.Now()Local ts:String=t.ToString()Return ts.Slice(15,25)EndHi
July 3, 2016 at 11:03 pm #1674Time is ‘@hidden’ because it needs more work. See my blog entry re: hidden stuff.
In particular, I want to implement a ‘TimeSpan’ or ‘DeltaTime’ struct to go along with ‘Time’ (for use with +/- operators) but this needs a bit more thought/planning.
So use at your own risk! The interface will probably remain much the same but the implementation could change…
July 5, 2016 at 7:05 pm #1763Thanks!
I’ll keep track of future changes on this.
March 25, 2017 at 7:39 am #7609How I can convert a Unix Timestamp (the value returned from GetFileTime() for example) in a ‘human ready thing’?
I tried to toy around with Time Class, tried to convert blitzmax code to MX2, but it seems I can’t convert a Ulong to anything needed in Time.ps: about the Time Class I suggest
* add some methods to convert from/to timestamp
* make days/months public as anyone should get a ‘local’ (=in their own language) date/time
* add STRFTIME support… it is so useful to get ‘date/time’ in the own/required string formatUnfortunately I get stuck with type conversion between time-class & etc
March 27, 2017 at 4:13 am #7621(I’ve removed previous post)
Hm. Work with time isn’t trivial because of leap year.
IMO, the easiest way is to extend ‘time’ module to get values directly from c++.
-
AuthorPosts
You must be logged in to reply to this topic.