Jump to content




Real World Time API (Ver. 1.0)

api

  • You cannot reply to this topic
11 replies to this topic

#1 surferpup

  • Members
  • 286 posts
  • LocationUnited States

Posted 01 February 2014 - 06:25 PM

Real World Time API (Version 1.0)



This API is in now in its release version.

As promised, I have created an API which allows for obtaining real world time and date from the timeapi.org servers.

The idea for the API came from the suggestions I received after posting my Real World / MinecraftWorld Time Display Program

This API will allow you to retrieve current real world date/time information for use within your ComputerCraft creations. The public functions are as follows:

getTime,printTime

There are two functions which either get or print time based on a time zone parameter (default = UTC), an hours offset parameter (default = 0), a format parameter and a timeout variable (which will abandon the request if it is taking too long. The default timeout is 0 (infinite).
getTime(timeZone,offset,dateTimeFormat,timeOut)
printTime(timeZone,offset,dateTimeFormat,timeOut)

Pre-Defined Date/Time Formats

getTimeTable,printTimeTable

The following are two additional functions which either get or print a table of time elements (day, hour, day of week, week of year, year ...) using the parameters for time zone and offset and timeOut as above, plus an additional boolean parameter to return numbers instead of strings for certain values (like minutes for example). This would allow a programmer to use individualized elements of date and time in whatever custom format desired. The printTimeTable function will pause to allow for screen scrolling, as there are 22 different date time elements in the table.

getTimeTable(timeZone,offset,makeNumeric,timeOut)
printTimeTable(timeZone,offset,makeNumeric,timeOut)

Date/Time Table Elements

Finally, there are two utility functions for help with the API: printZones() and printFormats(). These will print the pre-defined zones and time format enumerations for reference. There is a publicly exposed enumeration called format which allows for easily specifying pre-defined formats.

Code

To Do List

Change Log

Potential Uses in Your Code


PASTEBIN CODE: TNLjCCKq

Edited by surferpup, 04 February 2014 - 04:10 PM.


#2 SeaLife

  • Members
  • 23 posts

Posted 02 February 2014 - 04:12 AM

Are i'm allowed to use this API in my SG-Control System? For the Log-System :D?

http://www.computerc...rol-system-v13/


Nice Api :)

#3 oeed

    Oversimplifier

  • Members
  • 2,095 posts
  • LocationAuckland, New Zealand

Posted 02 February 2014 - 05:22 AM

Nice to see you made this in to an API. I'll take a further look in to it soon.

#4 surferpup

  • Members
  • 286 posts
  • LocationUnited States

Posted 02 February 2014 - 01:41 PM

View PostSeaLife, on 02 February 2014 - 04:12 AM, said:

Are i'm allowed to use this API in my SG-Control System? For the Log-System :D?


I don't see why not -- let me know how it works for you.

#5 surferpup

  • Members
  • 286 posts
  • LocationUnited States

Posted 02 February 2014 - 04:48 PM

View Postsurferpup, on 01 February 2014 - 06:25 PM, said:

  • Derp-A-Lert!!!! -- use textutils.urlEncode for creating url-friendly strings rather than doing it myself. This will change the dateSeparator functions and make the format strings a lot easier to create and read.

Google is my friend. Google is my friend....

Actually, a very handy function. Thanks to whomever thunked it up.

Edited by surferpup, 02 February 2014 - 04:49 PM.


#6 surferpup

  • Members
  • 286 posts
  • LocationUnited States

Posted 03 February 2014 - 01:17 AM

This is now in its release version. I added a timeout feature running in parallel with the http.get function. Whichever finishes first will return the result value. I also changed the code to take advantage of the textutils.urlEncode function.

Let me know if you have any suggestions or if you encounter any bugs.

#7 surferpup

  • Members
  • 286 posts
  • LocationUnited States

Posted 04 February 2014 - 04:08 PM

There was an error in the timeout function. It is now fixed. Thanks to mibac138 for catching it.

#8 Akirad0e

  • New Members
  • 1 posts

Posted 21 March 2014 - 07:43 AM

I've just tried using the script and the output seems to ignore the Date/Time Formats I select and shows the following (even when using default),

2014-03-21T07:35:24+00:00

The command I used for this test is below however I've tried tayloring it for my timezone and chosen format with the same output,

printTime(default,default,default,default)
printTime(default,10,dateTime12_ddmmyy,15)

I'm sure I'm doing something wrong, got any advice?

Thanks.

#9 Reciprocaterman

  • Members
  • 8 posts

Posted 29 March 2014 - 05:02 PM

I'm wanting to use this API as part of a sign-in program on my server. I downloaded from pastebin named it "time". But whenever I call the function

time.getTime("UTC",0,time.format.dateLong,0) Or any other combination, even tried just using time.getTime(), I always get an attempt to call or index a nil value.

Help please?

#10 LayZee

  • Members
  • 15 posts

Posted 13 April 2014 - 10:40 PM

How is this for a use case? :-)

http://pastebin.com/4brRx86j

Modified version of this http://www.computerc...gue-clock-face/ by Ramdor

#11 lebalusch

  • Members
  • 49 posts

Posted 08 June 2014 - 08:07 PM

View PostAkirad0e, on 21 March 2014 - 07:43 AM, said:

I've just tried using the script and the output seems to ignore the Date/Time Formats I select and shows the following (even when using default),

2014-03-21T07:35:24+00:00

The command I used for this test is below however I've tried tayloring it for my timezone and chosen format with the same output,

printTime(default,default,default,default)
printTime(default,10,dateTime12_ddmmyy,15)

I'm sure I'm doing something wrong, got any advice?

Thanks.

I agree I am also getting this problem. could a code snip it be posted on how to just get and print "dateTime12_ddmmyyyy".
Maybe a little script with how you would get and print each of the different formats. then I could easily cut and paste and also see how they are all done. If this is not too much to ask somebody that's understanding this API to do.

This is a great API and the amount of data you can get from it is overwhelming to say the least but I can see some great uses for it already. Maybe the ability for the API to only go get the data i request would be nice as this might speed it up.(if this is possible).

Once again thank you for making this API :)

#12 jfgcf

  • New Members
  • 1 posts

Posted 05 September 2015 - 04:38 PM

I need help, it's my first time working with computercraft so how do I make this run on a monitor so that I can show the timezone, I already tried but with no success.





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users