This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
surferpup's profile picture

Create RealWorld Time/Date function in os API

Started by surferpup, 02 February 2014 - 08:33 PM
surferpup #1
Posted 02 February 2014 - 09:33 PM
I know I just finished posting my Real World Time API and this suggestion if implemented will obviate the need for it BUT: Why not create a real world time/date interface is the OS API in the next next version of Computer Craft?

It should return the actual server time (or even an selectable time server time), and if possible all of the time parameters in table form for parsing: hours, minutes, seconds, day of month, month, year, offset from UTC, etc. My API already does this, but it would be nice to get away from the http call to do it.

This would certainly be better than having to poll a website to get time and might lead to some cool functionality in new programs.

Just a thought.
Edited on 02 February 2014 - 08:34 PM
Lyqyd #2
Posted 02 February 2014 - 10:20 PM
This has been suggested before. It breaks the fourth wall, and so is unlikely to happen.
surferpup #3
Posted 02 February 2014 - 11:26 PM
Okay, well then I will just keep using my Real World Time API

Thanks for the response.
ingie #4
Posted 03 February 2014 - 12:24 PM
this gives me an idea about using METAR data and command block control to set the weather to whatever the weather is outside [ within the limited weather parameters minecraft gives :)/> ]

i.e. http://aviationweather.gov/adds/metars/?station_ids=EGNS&chk_metars=on

will return current conditions for my local airport [ Ronaldsway, Isle of Man ] in a format such as this:

EGNS 031650Z 14021KT 9000 RA FEW015 OVC030 08/05 Q0992 NOSIG

the "RA" in that 5th field, means it's currently raining :)/>

the NOSIG means "no significant change" …. tell me about it…

some further METAR info here if you're interested in doing similar - and expand your API into "Real World of Things" :)/>
if you use linux, then there's two apps in standard debian apt sources for it, metar [commandline] and pymetar [python] - the latter gives a decoding library also.
surferpup #5
Posted 03 February 2014 - 01:45 PM
That would be cool.
ingie #6
Posted 03 February 2014 - 04:01 PM
i'll dig out some code i have already played with in python and see if i can knock up a basic METAR lua lib… i'll stick it in the utils section…

it may be very basic rather than a complete decoder tho, unless i can find a public domain lua decoder and wrap it - as the number of parameters in the decoding is redonkulous - and a lot of the codes are optional… [read: i can't be arsed typing all the decoding conditionals in] but to add it to, say, your "localised real world of things" stuff it'd be nice if it did do the whole decode and allowed the whole report to be displayed like your time zone display board
Cranium #7
Posted 03 February 2014 - 05:55 PM
One really easy implementation is using http://www.timeapi.org/
You can use the http api to get a value of the real time, specified by the arguments you put in your url. They even have proper documentation.
Edited on 03 February 2014 - 04:56 PM
ingie #8
Posted 03 February 2014 - 07:22 PM
One really easy implementation is using http://www.timeapi.org/
You can use the http api to get a value of the real time, specified by the arguments you put in your url. They even have proper documentation.

that's what surferpup's wrapper api does that he mentioned in the first post, it wraps that website into a handy set of functions… he was asking if that could become/was likely to become built-in…
oeed #9
Posted 04 February 2014 - 04:16 AM
This has been suggested before. It breaks the fourth wall, and so is unlikely to happen.

Is there anything directly wrong with doing so, or is it just out of Dan's preference for the feel of the mod?
Buho #10
Posted 04 February 2014 - 07:18 AM
I searched the API but didn't find it there. At one point I ran across something somewhere that said when Lua was implemented, os.time() was specifically overridden to provide game-time instead of real-time. I.e., this is intentional, not an oversight.

That said, os.day() returns a number and os.time() returns a number. A Minecraft day is 20 real-time minutes. I don't have my code in front of me right now, but I've written a simple function that returns elapsed real-time if you provide the start day and start time. That's useful for determining how many minutes (or hours) a mining operation took.

Extending further, you can write a time server that keeps the master time (I guess it would take human input) and broadcasts this to all other turtles, which would then sync their time to the master. Or aren't there real-world time RESTful servers that return time in XML or JSON or something? Your program can ping them to sync their internal time with real-time at the beginning and then do a conversion (0.0139 real-days to 1 Minecraft-day).

A quick search found this RESTful API: http://api.geonames.org/timezone?lat=47.01&lng=10.2&username=demo&style=full which returns, among other interesting things, <time>2014-02-04 13:28</time>.
surferpup #11
Posted 04 February 2014 - 01:28 PM
A quick search found this RESTful API: http://api.geonames....demo&amp;style=full which returns, among other interesting things, <time>2014-02-04 13:28</time>.

My Real World Time API does this, and you don't need to sign up to a service or create a login account. Just saying :)/>