cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Try the Materials Informatics Toolkit, which is designed to easily handle SMILES data. This and other helpful add-ins are available in the JMP® Marketplace
Choose Language Hide Translation Bar
Craige_Hales
Super User
UTC Time Zone

Your computer's clock shows you time for your local time zone.  You probably know your time zone as a three letter code like EST (Eastern Standard Time) or EDT (Eastern Daylight Time) or maybe GMT (Greenwich Mean Time).  GMT has several other names: UTC is a compromise acronym for scientists and Zulu is a military designation (Z, for zero). 


GMT has an offset of zero; EDT is GMT-4 and EST is GMT-5.  This post is about calculating the -4 or -5 value, in a JSL script, without knowing what time zone your computer is in.  Once you have that value, you can convert JMP date-time values from local time to GMT.  If you collect and share data across time zones, GMT might be a good choice. 


Rather than trying to make a system call through the JSL-DLL interface, I'm going to ask a web site what the current GMT time is.  This will be part of the header information in the web site's response.


(There is a JSL attachment, below, with a little bit more error checking than you see here.)

(If there is a temporal discontinuity below, it's because this post was constructed over several hours.)

(JSL sockets do NOT support SSL or HTTPS connections.  You can use internetOpen() for most HTTPS work.)

(Tested only in EDT so far.  Let me know what you discover.)


First, create a JSL socket and connect to a web site:

// open a socket connection to a web site

tCall = Socket();

RC = tcall << connect( "www.jmp.com", "80" ); // pretty much any site will work.  this is a short redirect answer...


{"connect", "ok"}


the socket methods, like <<connect, return a list.  The first value in the list repeats the method name, and the 2nd value is a return code, "ok" above.  This connection will stay alive for a minute or so, waiting for you to ask for something.  Let's ask for the root page of the web site:


// request the root page of the site

RC = tcall << Send( Char To Blob( "GET / HTTP/1.0~0d~0a~0d~0a", "ASCII~HEX" ) );

// grab the local time between sending the request and getting the response

localTime = As Date( Today() );


{"Send", "ok", Char To Blob( "", "ascii~hex" )}

Another ok return code, great!  Now lets get the result:

// prepare a buffer to collect the results

receivedData = charToblob("");

while(RC[2] == "ok", // a loop to receive data

    RC = tCall << Recv( 1000 ); // receive up to 1000 bytes at a time

    if( RC[2] == "ok", receivedData ||= rc[3]; ); // concatenate if got some

);

Char To Blob(

    "HTTP/1.1 301 Moved Permanently~0D~0ADate: Fri, 30 Oct 2015 16:57:43 GMT~0D~0AServer: Apache~0D~0ALocation: http://www.jmp.com/~0D~0AContent-Length: 227~0D~0AConnection: close~0D~0AContent-Type: text/html; charset=iso-8859-1~0D~0ASet-Cookie: BIGipServerwww.jmp.com-pool=201698709.20480.0000; path=/~0D~0A~0D~0A<~21DOCTYPE HTML PUBLIC ~22-//IETF//DTD HTML 2.0//EN~22>~0A<html><head>~0A<title>301 Moved Permanently</title>~0A</head><body>~0A<h1>Moved Permanently</h1>~0A<p>The document has moved <a href=~22http://www.jmp.com/~22>here</a>.</p>~0A</body></html>~0A",

    "ascii~hex"

)

There's a lot going on there.  Just focus on the ~0D~0ADate: Fri, 30 Oct 2015 16:57:43 GMT~0D~0A part buried in the receivedData.  (It's 12:57 local (EDT) time.)  A Regex will pick out the date:

GMT = Informat( Regex( Char( receivedData ), "~0D~0ADate: [A-Za-z]+, (.*?) GMT~0D~0A", "\1" ) );

30Oct2015:16:57:43

Convert to a time zone offset, you can add a minus if it makes sense...

tz = Round( (GMT - localTime) / In Hours( 1 ), 3 );

4


(if you build a production system around this, consider alternate ways to validate this number.  There is no guarantee that a web site is going to have the correct time or be available.)

So, knowing my computer clock is GMT-4, I can add 4 to a local time and have GMT:

Format( Today() + In Hours( tz ), "y/m/d h:m:s" )

"2015/10/30 5:05:33 PM"

InHours converts the 4 hours (in tz) to seconds so it can be added to the date-time value (also in seconds) and then reformatted.  It's just after one here; I see my UK co-workers are headed home for the weekend already.

Next time: the day/night map.

GMT.png

Last Modified: Oct 30, 2015 2:12 PM
Comments