[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

coldfusion server time / date reporting

Posted on 2014-08-13
47
Medium Priority
?
1,011 Views
Last Modified: 2014-08-17
Windows 2008 Server R2
ColdFusion 9

I need to know what time ColdFusion thinks it is. I use this:

 <cfoutput>#DateFormat(Now())#,
    #TimeFormat(Now())#</cfoutput>

And you can see the output here: http://nnvawi.org/datetime.cfm

That is strange, though. I have set my Windows 2008 Server R2 to UTC time -- or, GMT. According to Windows, the current time is 7:51 p.m.

However, ColdFusion thinks the time is 12:51 p.m.

I think I need ColdFusion to report a time of 7:51p.m., just as Windows Server does.

(I need to do this because my authorize.net application throws an error:

(97) This transaction cannot be accepted.

Which seems to indicate that authorize.net does not accept the timestamp provided by ColdFusion.)

Why do you think Coldfusion says the time is 12:51p.m.? Does ColdFusion derive its timestamp for function TimeFormat(Now()) from the server?

Thanks as always for your help.

Eric
0
Comment
Question by:Eric Bourland
  • 23
  • 23
47 Comments
 
LVL 52

Expert Comment

by:_agx_
ID: 40259332
> from the server?

Yes and no.  CF gets the time from the JVM. The JVM time is based on the server o/s, but it can be changed to use a different timezone. For example, some hosts add JVM arguments to change the time zone to GMT/UTC, so everyone is using the same time.

                 -Duser.timezone=GMT

That means if you are on the East Coast, the time returned by now() will several hours ahead of what you were expecting.  I don't know if you have access to createObject("java"). If not, try dumping the TZ information:

       <cfdump var="#GetTimeZoneInfo()#">
0
 
LVL 6

Expert Comment

by:rjohnsonjr
ID: 40259333
0
 
LVL 52

Expert Comment

by:_agx_
ID: 40259358
Haha, I just searched for that old thread  and couldn't find it. You'd think I'd be able to find my own posts ;-)  Anyway, I wasn't sure if Eric has createObject() access. If not, GetTimeZoneInfo() is a quick and easy way to determine if the server is using UTC time.  For the details, you'd need java though.
0
Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

 
LVL 52

Expert Comment

by:_agx_
ID: 40259394
> (97) This transaction cannot be accepted.

Out of curiosity, what made you conclude the date was the cause? It's certainly possible, of course, but that message sounds rather generic.

EDIT: Never mind, I found a link from 2011 which mentions code 97 means a date problem:

Error 97s occur when we receive an invalid timestamp from your Web server. Your Web server would use its clock to generate a timestamp which is used to generate a fingerprint hash for security reasons. When your script submits a transaction to us, the fingerprint hash and the timestamp are sent to us. If the timestamp is either fifteen minutes ahead or fifteen minutes behind the current time in Greenwich Mean Time (GMT)--also called Coordinated Universal Time (UTC)--this error would occur.
0
 
LVL 3

Author Comment

by:Eric Bourland
ID: 40259415
Here's an update.

1) thank you for these very helpful comments. =)

2) after a lot of research, and a phone conversation with authorize.net tech support, and tearing out what little hair I have left, I am pretty sure that the (97) error is caused because my JVM timestamp is 13-Aug-14, 01:49 PM ; but, the UTC time is 13-Aug-14, 08:49 PM.

3) This gives me two options: change the time in JVM to UTC time; or, do something in my code to add seven hours to the timestamp of the transaction.

How difficult is it to change the time in the JVM?

Or, should I work with the (fairly simple) ColdFusion code (see below) to send a timestamp with +7 hours?

Thanks again. =)

Eric

<cfsetting enablecfoutputonly="true">
<cfoutput>
<!--
This sample code is designed to connect to Authorize.net using the SIM method.
For API documentation or additional sample code, please visit:
http://developer.authorize.net

Most of this page below (and including) this comment can be modified using any
standard html. The parts of the page that cannot be modified are noted in the
comments.  This file can be renamed as long as the file extension remains .cfm
-->

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" 
  "http://www.w3.org/TR/html4/loose.dtd">
<HTML lang='en'>
<HEAD>
	<TITLE> Sample SIM Implementation </TITLE>
</HEAD>
<BODY>


<!-- This section generates the "Submit Payment" button using Coldfusion     -->
</cfoutput>
<!--- the parameters for the payment can be configured here --->
<!--- the API Login ID and Transaction Key must be replaced with valid values --->
<cfset loginID="xxxx">
<cfset transactionKey="xxxx">
<cfset amount="19.99">
<cfset description="Sample Transaction">
<cfset label="Submit Payment"> <!--- This is the label on the 'submit' button --->
<cfset testMode="false">


<cfset posturl="https://secure.authorize.net/gateway/transact.dll">

<!--- If an amount or description were posted to this page, the defaults are overidden --->
<cfif IsDefined("FORM.amount")>
  <cfset amount=FORM.amount>
</cfif>
<cfif IsDefined("FORM.description")>
  <cfset description=FORM.description>
</cfif>
<!--- also check to see if the amount or description were sent using the GET method --->
<cfif IsDefined("URL.amount")>
  <cfset amount=URL.amount>
</cfif>
<cfif IsDefined("URL.description")>
  <cfset description=URL.description>
</cfif>

<!--- an invoice is generated using the date and time --->
<cfset invoice=DateFormat(Now(),"yyyymmdd") & TimeFormat(Now(),"HHmmss")>

<!--- a sequence number is randomly generated --->
<cfset sequence=RandRange(1, 1000)>

<!--- a timestamp is generated --->
<cfset timestamp=DateDiff("s", "January 1 1970 00:00", DateConvert('local2UTC', Now())) >

<!--- The following lines generate the SIM fingerprint --->

<cf_hmac data="#loginID#^#sequence#^#timestamp#^#amount#^" key="#transactionKey#">

<cfset fingerprint=#digest#>

<cfoutput>

<!--- Print the Amount and Description to the screen.--->
Amount: #amount# <br />
Description: #description# <br />

<!--- Create the HTML form containing necessary SIM post values --->
<FORM method='post' action='#posturl#' >
<!--- Additional fields can be added here as outlined in the SIM integration
guide at http://developer.authorize.net --->
<INPUT type='hidden' name='x_login' value='#loginID#' />
	<INPUT type='hidden' name='x_amount' value='#amount#' />
	<INPUT type='hidden' name='x_description' value='#description#' />
	<INPUT type='hidden' name='x_invoice_num' value='#invoice#' />
	<INPUT type='hidden' name='x_fp_sequence' value='#sequence#' />
	<INPUT type='hidden' name='x_fp_timestamp' value='#timeStamp#' />
	<INPUT type='hidden' name='x_fp_hash' value='#fingerprint#' />
	<INPUT type='hidden' name='x_test_request' value='#testMode#' />
	<INPUT type='hidden' name='x_show_form' value='PAYMENT_FORM' />
	<input type='submit' value='#label#' />
</FORM>
<!-- This is the end of the code generating the "submit payment" button.    -->

</BODY>
</HTML>
<!-- The last line is a necessary part of the coldfusion script -->
</cfoutput>

Open in new window

0
 
LVL 52

Expert Comment

by:_agx_
ID: 40259460
EDIT:

If it's *your* server that's off from UTC, you may be in luck. You should be able to use DateConvert to convert your local server time ie now() into UTC:

     <cfset timestamp = dateConvert( now(), "local2Utc")>

> I am pretty sure that the (97) error is caused because my JVM timestamp

Agreed.  I searched a bit after posting that comment and found a link which also confirmed 97 means the timestamp is off from what they were expecting. See updates
0
 
LVL 52

Expert Comment

by:_agx_
ID: 40259479
> How difficult is it to change the time in the JVM?

In this case try using dateConvert() first. It's the simpler option.

But to answer your question, as long as it's not a shared server, then it's not difficult. In short, you change the timezone setting in either the CF Admin OR the jvm.config file. Then restart CF.  My preference is using jvm.config.

Note: It's a global setting, so it will affect ALL applications running in that JVM

Here's a summary from an old thread

The best way is to edit your jvm.config file add it to the jvm arguments section.  Make a backup copy first! For single server installs the file's located: C:\ColdFusion9\runtime\bin\jvm.config). Save the settings and restart CF.

# Arguments to VM
java.args=-server -Xmx512m -Duser.timezone="your tz ID goes here"  ... other settings

Open in new window


http://forums.adobe.com/thread/552963?tstart=0
0
 
LVL 3

Author Comment

by:Eric Bourland
ID: 40259522
Got it. Makes sense. I am going to back up, then edit the JVM.config file; restart ColdFusion; and see if that fixes the authorize.net (97) problem.

I will have to do this tomorrow because my ISP (Viviotech.net) is applying a number of patches to my server right now; and, I have to go cook dinner and tidy the house. =)

I'll report my discoveries tomorrow. As always, thanks, _agx_.

E
0
 
LVL 52

Expert Comment

by:_agx_
ID: 40259532
EDIT:

Eric - Actually I recommend trying DateConvert() first.  It's much simpler. From what you described, it should do the trick. If not, you can always modify the JVM settings. Just note the important caveats:

- ALWAYS make a backup of jvm.config first. A bad jvm.config file can prevent the CF server from starting. As long as you have a backup, just restore it and you're good to go.

- Changing the timezone affects ALL apps sharing that JVM
0
 
LVL 3

Author Comment

by:Eric Bourland
ID: 40259802
I tried DateConvert(). I got this error at first:

 Parameter validation error for the DATECONVERT function.
The value of parameter 2, which is currently local2Utc, must be a class java.util.Date value.

So I changed the parameters to this: <cfset timestamp = dateConvert("local2Utc", now() )>

and that removed the error. But I am still getting the "(97) This transaction cannot be accepted." from authorize.net, which means (according to them) that my server is still outputting a Pacific Time timestamp.

A look at my timestamp test page: http://nnvawi.org/datetime.cfm

confirms this.

I am a little nervous about changing the JVM config file.

Am I using the DateConvert() function correctly?

<!--- an invoice is generated using the date and time --->
<cfset invoice=DateFormat(Now(),"yyyymmdd") & TimeFormat(Now(),"HHmmss")>

<!--- a sequence number is randomly generated --->
<cfset sequence=RandRange(1, 1000)>

<!--- a timestamp is generated --->

<!--- old cfset timestamp --->
<!---<cfset timestamp=DateDiff("s", "January 1 1970 07:00", DateConvert('local2UTC', Now())) >--->

<!--- new cfset timestamp, per _agx_ --->
<cfset timestamp = dateConvert("local2Utc", now() )>

<!--- The following lines generate the SIM fingerprint --->

<cf_hmac data="#loginID#^#sequence#^#timestamp#^#amount#^" key="#transactionKey#">

<cfset fingerprint=#digest#>

Open in new window


Hope you have a great evening. Thanks as always.

Eric
0
 
LVL 52

Expert Comment

by:_agx_
ID: 40260558
which means (according to them) that my server is still outputting a Pacific Time timestamp

Well specifically, it means that the time sent is off by more than +/- 15 minutes than what authorize.net expected. At least according to what I read.

EDIT:
EE was down last night when I went to reply. However, when I ran the test page, the displayed date and time was off by +5 hours. At that point, it was around 3:00 AM GMT. But the test page displayed something like 8:00 AM.  Right now the test page seems to be displaying Eastern time, ie GMT -4 hours

Can you run the following and post the results?

<cfoutput>
  now #now()#<br>
  gmt #dateConvert("local2utc", now())#<br>
</cfoutput>     

<cfset prop =createObject('java', 'java.lang.System').getProperties()>
<cfdump var="user.timezone = #prop['user.timezone']#">	
<cfdump var="#GetTimeZoneInfo()#">

Open in new window

0
 
LVL 3

Author Comment

by:Eric Bourland
ID: 40260896
Good morning!

I ran the test here: http://nnvawi.org/timezone.cfm

But, I should report a few notes:

1. my server is in Walla Walla Washington, at Viviotech.
2. the server clock is set to the UTC timezone -- GMT
3. total UTC offset should be seven hours

>>>Well specifically, it means that the time sent is off by more than +/- 15 minutes than what authorize.net expected. At least according to what I read.

I agree.

I also agree about the odd behavior of my datetime test http://nnvawi.org/datetime.cfm

datetime.cfm is simply this: <cfoutput>#DateFormat(Now())#, #TimeFormat(Now())#</cfoutput>

I wonder why datetime.cfm reports Eastern Standard Time? That's my current timezone; I am in DC. But I thought the Now() function reported the time on the server?

Thanks again for your help with managing time. =)

Eric
0
 
LVL 52

Expert Comment

by:_agx_
ID: 40260901
I still think this can be done with DateConvert, but wanted to comment on this:

> I am a little nervous about changing the JVM config file

Once you've done it a few times, you'll see it's not really a big deal.  It basically amounts to changing a text file ;-) BUT ... I completely understand your caution. I always try stuff like that locally first, with the CF developer version. That way I can see the results and get comfortable with it.  

It can also be changed via the CF Admin: Server Settings > Java and JVM > Java Arguments. The end result is the same. You're just making jvm.config modifications through a web interface instead of notepad. Though I'd still recommend making a  backup first. "Better safe than sorry" and all that ;-)
0
 
LVL 52

Expert Comment

by:_agx_
ID: 40260982
>> managing time. =)

Haha. Wish we could do the same in real life. "Don't have enough time? Run this simple CF code to instantly add or subtract time from your day!"


>> 1. my server is in Walla Walla Washington, at Viviotech.
>> 2. the server clock is set to the UTC timezone -- GMT

Okay

>> 3. total UTC offset should be seven hours

Not necessarily. The offset will only be 7 hours IF the JVM on that server (not the o/s) is set to use the "Pacific" time zone. Remember you can set the JVM time zone to be anything you want. So it may not using the "Pacific" time zone.


>> I wonder why datetime.cfm reports Eastern Standard Time? That's my current timezone; I am in DC.
>> But I thought the Now() function reported the time on the server?

Not exactly. It reports the current time on the server, but .... adjusted for whatever timezone is set by the JVM.  Based on the results, I'd say the JVM is set to use "Eastern", not "Pacific".  


>> I ran the test here: http://nnvawi.org/timezone.cfm
>> now {ts '2014-08-14 11:36:58'}
>> user.timezone = America/New_York


Yep.  The dumps confirm it's set to the "Eastern" time zone and that DateConvert is working correctly:

       gmt {ts '2014-08-14 15:36:58'}

That's the current time in GMT. I'm not sure why you're still getting the 97 error, if this is how you're generating the value:

     <cfset timestamp = dateConvert("local2Utc", now() )>

Are you positive you're not accidentally using #now()# somewhere else instead of #timestamp#?
0
 
LVL 3

Author Comment

by:Eric Bourland
ID: 40261262
Hmmm.

I give the full code of the test page -- test.cfm -- below.

The test page is set up here: http://nnvawi.org/test.cfm

So, here is what (I think) we know:

1) DateConvert is working correctly
2) Web server (Windows 2008 R2) is set to UTC / GMT time -- not eastern time, not Pacific time -- but this does not matter too much
3) JVM is apparently set to EST -- correct?
4) the (97) error persists and authorize.net chortles at my failure ;-)

>>>Not necessarily. The offset will only be 7 hours IF the JVM on that server (not the o/s) is set to use the "Pacific" time zone. Remember you can change the JVM time zone to be anything you want. So it may not using the "Pacific" time zone.

Got it. This makes sense.

I do not think the Now() function appears elsewhere ... wait. On line 52:

<!--- an invoice is generated using the date and time --->
<cfset invoice=DateFormat(Now(),"yyyymmdd") & TimeFormat(Now(),"HHmmss")>

Could that be the problem?

Thanks again! This is an interesting problem. (In a way.) =)

Eric




<cfsetting enablecfoutputonly="true">
<cfoutput>
<!--
This sample code is designed to connect to Authorize.net using the SIM method.
For API documentation or additional sample code, please visit:
http://developer.authorize.net

Most of this page below (and including) this comment can be modified using any
standard html. The parts of the page that cannot be modified are noted in the
comments.  This file can be renamed as long as the file extension remains .cfm
-->

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" 
  "http://www.w3.org/TR/html4/loose.dtd">
<HTML lang='en'>
<HEAD>
	<TITLE> Sample SIM Implementation </TITLE>
</HEAD>
<BODY>


<!-- This section generates the "Submit Payment" button using Coldfusion     -->
</cfoutput>
<!--- the parameters for the payment can be configured here --->
<!--- the API Login ID and Transaction Key must be replaced with valid values --->
<cfset loginID="xxxxxx">
<cfset transactionKey="yyyyyy">
<cfset amount="19.99">
<cfset description="Sample Transaction">
<cfset label="Submit Payment"> <!--- This is the label on the 'submit' button --->
<cfset testMode="false">


<cfset posturl="https://secure.authorize.net/gateway/transact.dll">

<!--- If an amount or description were posted to this page, the defaults are overidden --->
<cfif IsDefined("FORM.amount")>
  <cfset amount=FORM.amount>
</cfif>
<cfif IsDefined("FORM.description")>
  <cfset description=FORM.description>
</cfif>
<!--- also check to see if the amount or description were sent using the GET method --->
<cfif IsDefined("URL.amount")>
  <cfset amount=URL.amount>
</cfif>
<cfif IsDefined("URL.description")>
  <cfset description=URL.description>
</cfif>

<!--- an invoice is generated using the date and time --->
<cfset invoice=DateFormat(Now(),"yyyymmdd") & TimeFormat(Now(),"HHmmss")>

<!--- a sequence number is randomly generated --->
<cfset sequence=RandRange(1, 1000)>

<!--- a timestamp is generated --->

<!--- old cfset timestamp --->
<!---<cfset timestamp=DateDiff("s", "January 1 1970 07:00", DateConvert('local2UTC', Now())) >--->

<!--- new cfset timestamp, per _agx_ --->
<cfset timestamp = dateConvert("local2Utc", now() )>

<!--- The following lines generate the SIM fingerprint --->

<cf_hmac data="#loginID#^#sequence#^#timestamp#^#amount#^" key="#transactionKey#">

<cfset fingerprint=#digest#>

<cfoutput>

<!--- Print the Amount and Description to the screen.--->
Amount: #amount# <br />
Description: #description# <br />

<!--- Create the HTML form containing necessary SIM post values --->
<FORM method='post' action='#posturl#' >
<!--- Additional fields can be added here as outlined in the SIM integration
guide at http://developer.authorize.net --->
<INPUT type='hidden' name='x_login' value='#loginID#' />
	<INPUT type='hidden' name='x_amount' value='#amount#' />
	<INPUT type='hidden' name='x_description' value='#description#' />
	<INPUT type='hidden' name='x_invoice_num' value='#invoice#' />
	<INPUT type='hidden' name='x_fp_sequence' value='#sequence#' />
	<INPUT type='hidden' name='x_fp_timestamp' value='#timeStamp#' />
	<INPUT type='hidden' name='x_fp_hash' value='#fingerprint#' />
	<INPUT type='hidden' name='x_test_request' value='#testMode#' />
	<INPUT type='hidden' name='x_show_form' value='PAYMENT_FORM' />
	<input type='submit' value='#label#' />
</FORM>
<!-- This is the end of the code generating the "submit payment" button.    -->

</BODY>
</HTML>
<!-- The last line is a necessary part of the coldfusion script -->
</cfoutput>

Open in new window

0
 
LVL 3

Author Comment

by:Eric Bourland
ID: 40261264
p.s. your notes about editing the JVM file make sense.
0
 
LVL 52

Expert Comment

by:_agx_
ID: 40261414
>> 2) Web server (Windows 2008 R2) is set to UTC ....

Yes, I don't *think* it should matter since the time value is coming from CF, which seems correct at this point.


>> 3) JVM is apparently set to EST -- correct?

Correct


>> 4) the (97) error persists and authorize.net chortles at my failure ;-)

Maybe the URL is left over April fool's joke, that's not supposed to work ;-)



>> Could that be the problem?

I'm not sure. It depends on their API? Do you have link to the API field definitions (ie what each field should contain)? I did a cursory search but did not find anything.
0
 
LVL 52

Expert Comment

by:_agx_
ID: 40261429
>> <INPUT type='hidden' name='x_fp_timestamp' value='{ts '2014-08-14 18:11:47'}' />

Hm... that's CF's special format for date objects.  I'm wondering if that's what's causing the current problem. Usually API's are expecting something like YYYY-MM-DD HH:MM:SS" - without the "{ts.." and "}".  So you'll probably need to use Date/TimeFormat on the #timestamp# value first.

What does the API say?
0
 
LVL 52

Expert Comment

by:_agx_
ID: 40261598
Found the docs. It says this about the x_fp_timestamp:

       Format : UTC time in seconds since January 1, 1970

I think that's the problem. (I also understand why you were using DateDiff in the commented line of code now).  Hate to say it, but what you had originally should work. Just get rid of the 7+ hour offset, ie

<cfset timestamp=DateDiff("s", "January 1 1970", DateConvert('local2UTC', Now())) >
0
 
LVL 3

Author Comment

by:Eric Bourland
ID: 40261867
I just got back; sorry; been doing six things at once today.

I have been perusing the descriptions of the API fields:

http://developer.authorize.net/guides/SIM/wwhelp/wwhimpl/js/html/wwhelp.htm#href=SIM_Submitting_transactions.06.3.html

"x_fp_timestamp
Value: The timestamp at the time of fingerprint generation.

Format: UTC time in seconds since January 1, 1970

Notes: Coordinated Universal Time (UTC) is an international atomic standard of time (sometimes referred to as GMT). Using a local time zone timestamp will cause fingerprint authentication to fail. If the fingerprint is more than one hour old or more than 15 minutes into the future, it is rejected. "

I think we found the same thing.

<cfset timestamp=DateDiff("s", "January 1 1970", DateConvert('local2UTC', Now())) > 


Hmmm.

OK. I'll go back to this and see what happens. I'll try this now. More soon. E
0
 
LVL 52

Expert Comment

by:_agx_
ID: 40261902
Yes, the earlier version used 7AM

             "January 1 1970 07:00"

instead of midnight

              "January 1 1970"

That combined with DateConvert('local2UTC', Now()) - which you already added - should make things work properly.
0
 
LVL 3

Author Comment

by:Eric Bourland
ID: 40261955
So, I should use this:
<!--- a timestamp is generated --->

<!--- old cfset timestamp --->
<cfset timestamp=DateDiff("s", "January 1 1970 07:00", DateConvert('local2UTC', Now())) >

<!--- new cfset timestamp, per _agx_ --->
<!---<cfset timestamp = dateConvert("local2Utc", now() )>--->

I tried an offset of 7 hours (07:00) and 4 hours (04:00). Both are still giving me the (97) error.

I'll play with this some more.
0
 
LVL 52

Expert Comment

by:_agx_
ID: 40261992
No, remove the "07:00" entirely.  You want to calculate the dateDiff from January 1, 1970 at midnight, not some other time of day.  Do something like this:


<cfset timestamp=DateDiff("s", "January 1 1970", DateConvert('local2UTC', Now())) > 


EDIT: By omitting the time portion ie HH:MM, CF implicitly uses midnight. That's the start of the UNIX epoch, ie what the API specifies you should use.
0
 
LVL 3

Author Comment

by:Eric Bourland
ID: 40262020
Got it.

I miss UNIX. Those were the days. Maybe I should go back. =)

Hmm. Darn. I tried this:

<!--- a timestamp is generated --->

<!--- set cfset timestamp --->
<cfset timestamp=DateDiff("s", "January 1 1970", dateConvert("local2Utc", now()))>

<!--- new cfset timestamp, per _agx_ --->
<!---<cfset timestamp = dateConvert("local2Utc", now() )>--->

<!--- The following lines generate the SIM fingerprint --->

<cf_hmac data="#loginID#^#sequence#^#timestamp#^#amount#^" key="#transactionKey#">

<cfset fingerprint=#digest#>

I am still getting the (97) error.

Think I should try to edit the JVM file?
0
 
LVL 3

Author Comment

by:Eric Bourland
ID: 40262036
What do you think "s" means in the DateDiff function?

<cfset timestamp=DateDiff("s", "January 1 1970", dateConvert("local2Utc", now()))>
0
 
LVL 52

Expert Comment

by:_agx_
ID: 40262070
"s"  is the date part: ie seconds.

So like the API mentions, you are calculating the "UTC time (elapsed) in seconds since January 1, 1970 (at midnight)".
0
 
LVL 52

Expert Comment

by:_agx_
ID: 40262220
I get the feeling I'm missing something obvious, but my brain is too fried to see it.  

Did they give you an example you can match? Like "If it's 08/14/2014 04:52 PM in Eastern daylight time, the current GMT would be  MM/DD/YYYY HH:MM". So the expected timestamp value is xxxxxxx"
0
 
LVL 3

Author Comment

by:Eric Bourland
ID: 40262226
Dear _agx_,

They did not give me an example like that, though it would have been helpful.

I am going to do some more research on this. I am also going to call authorize.net again tomorrow and ask about it.

My brain is pretty fried too. =) Long day.

I hope this finds you well and that a restful evening, free of coding and problems and such, awaits you.

I will work on this a little more this evening, and check in here tomorrow. Take care.

Eric
0
 
LVL 3

Author Comment

by:Eric Bourland
ID: 40263133
Good morning, _agx_,

I submitted this question to the developer's forum at authorize.net.

In the meantime I think I am going to get Viviotech to do a backup of my server and ColdFusion settings, and then I am going to change the JVM datetime in ColdFusion admin.

Just to see what happens. =)

I will let you know. Thank you again for your help. Have a great Friday.

Eric
0
 
LVL 3

Author Comment

by:Eric Bourland
ID: 40263482
I've been reading up on your notes, and the documentation, about changing the time zone in JVM.

In the meantime I've found this tool:

http://developer.authorize.net/tools/responsecode97/

Though I am not sure about some things:
1) how to derive a value in seconds from the timestamp from my web server
2) if this is even useful to use, since we know there is a difference of four hours, since the JVM is set to EST; thus, we can predict the output of the tool
3) Would this tool answer your question:

Did they give you an example you can match? Like "If it's 08/14/2014 04:52 PM in Eastern daylight time, the current GMT would be  MM/DD/YYYY HH:MM". So the expected timestamp value is xxxxxxx"

4) If so, can we set a value for variable #timestamp# that is +14400 seconds (four hours)?

<cfset timestamp= .... add 14400s ....>

I'm wandering here, and might be on the wrong track.

E
0
 
LVL 3

Author Comment

by:Eric Bourland
ID: 40263687
I've made these results appear:

Your timestamp = 1408119798 seconds.
The Authorize.Net system timestamp is 1408123416 seconds.
The difference is -3618 seconds.

So, my server is offset by -3618 s.

Is there some way I can use DateConvert or DateDiff to make up this difference?

I am researching this. I feel like I am making progress.

E
0
 
LVL 52

Expert Comment

by:_agx_
ID: 40264084
Sorry. On a deadline today.  

Good find with the response code tool.  I can't test it right now, but it sounds like your server time is off by 1hr +/- a partial minute.  Possibly the whole DST thing.  Which is curious because I would have thought local2utc would account for DST.

Let me try a real quick test.. then I've got to get back to work.
0
 
LVL 3

Author Comment

by:Eric Bourland
ID: 40264091
I tried replacing

<cfset timestamp=DateDiff("s", "January 1 1970 00:00", DateConvert('local2UTC', Now())) >

with a value, in seconds, for four hours (14400 seconds):

<!--- set cfset timestamp --->
<cfset timestamp=DateDiff("s", "January 1 1970 00:00", 14400) >

That did not work. I feel like I am missing a core concept here. =)

At this point I wonder if it is easier to edit the timezone in the JVM.config?

# Arguments to VM
java.args=-server -Xmx512m -Duser.timezone=America/Los_Angeles -Dsun.io.useCanonCaches=false
0
 
LVL 3

Author Comment

by:Eric Bourland
ID: 40264093
_agx_ if you have a lot to do, please don't spend time on this. You've been a hero already. =) It can wait till later.
0
 
LVL 52

Expert Comment

by:_agx_
ID: 40264109
Thanks, it's been one of those weeks ;-) For you too I'm sure.

If you're going to try changing the jvm.config file (or the Java and JVM settings in the CF Admin), you might just go with GMT all around. Like I mentioned, changing it is easy.  Just keep in mind that will affect anything using the time ie now(). I don't know what (if any) impact that will have on your app. Of course you can always change it back. Just make the modification and restart CF.
0
 
LVL 3

Author Comment

by:Eric Bourland
ID: 40264120
So I just add this at the end of JVM.config:
# Arguments to VM
java.args=-server -Xmx512m -Duser.timezone=America/New_York -Dsun.io.useCanonCaches=false

Open in new window


.... does that look right?

I've been reviewing post and the adobe forum page you referred me to.
0
 
LVL 52

Expert Comment

by:_agx_
ID: 40264130
I just tried adding the "-Duser.timezone..." part to my CF10 install and it didn't crash it :)  So it should be ok.  

Just be sure you have your backup file and all's good with the world.
0
 
LVL 3

Author Comment

by:Eric Bourland
ID: 40264151
Here is the original, current JVM.config:
# Arguments to VM
java.args=-server -Xmx512m -Dsun.io.useCanonCaches=false -XX:MaxPermSize=192m -XX:+UseParallelGC -Xbatch -Dcoldfusion.rootDir={application.home}/../ -Djava.security.policy={application.home}/../lib/coldfusion.policy -Djava.security.auth.policy={application.home}/../lib/neo_jaas.policy -Dcoldfusion.classPath={application.home}/../lib/updates,{application.home}/../lib,{application.home}/../gateway/lib/,{application.home}/../wwwroot/WEB-INF/cfform/jars,{application.home}/../wwwroot/WEB-INF/flex/jars -Dcoldfusion.libPath={application.home}/../lib

Open in new window


I think that is all one line!

So, the new JVM.config will be:

# Arguments to VM
java.args=-server -Xmx512m -Dsun.io.useCanonCaches=false -XX:MaxPermSize=192m -XX:+UseParallelGC -Xbatch -Dcoldfusion.rootDir={application.home}/../ -Djava.security.policy={application.home}/../lib/coldfusion.policy -Djava.security.auth.policy={application.home}/../lib/neo_jaas.policy -Dcoldfusion.classPath={application.home}/../lib/updates,{application.home}/../lib,{application.home}/../gateway/lib/,{application.home}/../wwwroot/WEB-INF/cfform/jars,{application.home}/../wwwroot/WEB-INF/flex/jars -Dcoldfusion.libPath={application.home}/../lib 
-Duser.timezone=America/New_York -Dsun.io.useCanonCaches=false

Open in new window


Think that will work?

I'm so sorry to interrupt you when you are under deadline.
# Arguments to VM
java.args=-server -Xmx512m -Dsun.io.useCanonCaches=false -XX:MaxPermSize=192m -XX:+UseParallelGC -Xbatch -Dcoldfusion.rootDir={application.home}/../ -Djava.security.policy={application.home}/../lib/coldfusion.policy -Djava.security.auth.policy={application.home}/../lib/neo_jaas.policy -Dcoldfusion.classPath={application.home}/../lib/updates,{application.home}/../lib,{application.home}/../gateway/lib/,{application.home}/../wwwroot/WEB-INF/cfform/jars,{application.home}/../wwwroot/WEB-INF/flex/jars -Dcoldfusion.libPath={application.home}/../lib

Open in new window

0
 
LVL 3

Author Comment

by:Eric Bourland
ID: 40264160
rather:

# Arguments to VM
java.args=-server -Xmx512m -Duser.timezone=America/New_York -Dsun.io.useCanonCaches=false -Dsun.io.useCanonCaches=false -XX:MaxPermSize=192m -XX:+UseParallelGC -Xbatch -Dcoldfusion.rootDir={application.home}/../ -Djava.security.policy={application.home}/../lib/coldfusion.policy -Djava.security.auth.policy={application.home}/../lib/neo_jaas.policy -Dcoldfusion.classPath={application.home}/../lib/updates,{application.home}/../lib,{application.home}/../gateway/lib/,{application.home}/../wwwroot/WEB-INF/cfform/jars,{application.home}/../wwwroot/WEB-INF/flex/jars -Dcoldfusion.libPath={application.home}/../lib
# Arguments to VM
java.args=-server -Xmx512m -Dsun.io.useCanonCaches=false -XX:MaxPermSize=192m -XX:+UseParallelGC -Xbatch -Dcoldfusion.rootDir={application.home}/../ -Djava.security.policy={application.home}/../lib/coldfusion.policy -Djava.security.auth.policy={application.home}/../lib/neo_jaas.policy -Dcoldfusion.classPath={application.home}/../lib/updates,{application.home}/../lib,{application.home}/../gateway/lib/,{application.home}/../wwwroot/WEB-INF/cfform/jars,{application.home}/../wwwroot/WEB-INF/flex/jars -Dcoldfusion.libPath={application.home}/../lib

Open in new window

0
 
LVL 52

Expert Comment

by:_agx_
ID: 40264196
EDIT:

It's important to keep it all on one line. Also, I think the -XX arguments should come 1st.

The trick I use when adding an argument that starts with "-D..." is to look for the 1st one that starts with that prefix, then put my new argument in front of it.  So if my old CF10 config line started like this:

# Arguments to VM
java.args=-server -Xms256m -Xmx512m -XX:MaxPermSize=192m -XX:+UseParallelGC -Xbatch -Dcoldfusion.home={application.home} .... etctera ....

Open in new window


The 1st "-D" arg is "-Dcoldfusion.home={application.home}". So I just paste in the new arg before " it like so:

# Arguments to VM
java.args=-server -Xms256m -Xmx512m -XX:MaxPermSize=192m -XX:+UseParallelGC -Xbatch  -Duser.timezone=GMT  -Dcoldfusion.home={application.home} .... etctera ....

Open in new window

0
 
LVL 3

Author Comment

by:Eric Bourland
ID: 40264209
Got it. I will try this late tonight so if anything goes ka-boom, I can fix it back.

Wishing you a lot of luck with your current project. May all go smoothly.

I'll work on this over the weekend and get back to you.

Thanks very much, as always. Take care,

Eric
0
 
LVL 3

Author Comment

by:Eric Bourland
ID: 40265632
Update: I edited jvm.config very carefully, using your notes above. I restarted CF. Web sites are all OK.

But .... I have a silly question ... what is the correct syntax to use for UTC / GMT time? The below argument works for EST.

Some places I have found indicate -Duser.timezone=UTC is the correct syntax. What do you think?

Hope you are enjoying the weekend.

Eric

# Arguments to VM
java.args=-server -Xmx512m -XX:MaxPermSize=192m -XX:+UseParallelGC -Duser.timezone=America/New_York -Dsun.io.useCanonCaches=false -Xbatch -Dcoldfusion.rootDir={application.home}/../ -Djava.security.policy={application.home}/../lib/coldfusion.policy -Djava.security.auth.policy={application.home}/../lib/neo_jaas.policy -Dcoldfusion.classPath={application.home}/../lib/updates,{application.home}/../lib,{application.home}/../gateway/lib/,{application.home}/../wwwroot/WEB-INF/cfform/jars,{application.home}/../wwwroot/WEB-INF/flex/jars -Dcoldfusion.libPath={application.home}/../lib

Open in new window

0
 
LVL 3

Author Comment

by:Eric Bourland
ID: 40265647
It's -Duser.timezone=GMT.

I edited jvm.config and restarted CF and web sites are working. Testing the authorize.net application....

Holy moly, it works.

I'll follow up tomorrow, but it looks like that was it.

=)

Just did a little cheer and fist pump, like a college student.
0
 
LVL 52

Expert Comment

by:_agx_
ID: 40265840
Yep. that's what I used here. :) Not sure if UTC works too.

> Holy moly, it works.

Awesome. Finally!

Though I'm still curious why DateConvert didn't work. I must be missing something... Otherwise, what's the point of having a "local2UTC" option if you still end up having to change the jvm time zone. If this week ever ends ... I'll have to try and figure it out ;-)
0
 
LVL 52

Accepted Solution

by:
_agx_ earned 2000 total points
ID: 40266375
Wow... think I finally figured out the "why" of it.  Definitely not the behavior I expected ...

Anyway, something in the dateDiff() logic seems to be aware of the local JVM timezone, whatever it might be. So if it is "Eastern", the result will be off by 5 hours. The same difference between EST and GMT. That's why you kept getting a (97) error code.  

A simple solution that doesn't require changing the jvm timezone:

* Convert now() to UTC. then use the internal getTime() method. It returns the numbers of milliseconds elapsed since the unix epoch. Just divide by 1000 to get seconds:

    <cfset utcTimeNow = dateConvert("local2Utc", now())>
    <cfset timestamp = int(utcTimeNow.getTime()/1000)>

Open in new window


It could also be done with java objects (see getAuthorizeNetTimeStamp function below), but the above is a lot simpler.

Test Code:
<cfscript>
    //sdf = createObject("java","java.text.SimpleDateFormat").init("yyyy.MM.dd G 'at' HH:mm:ss z");
    // Get the three dates involved
    localTimeNow = now();
    utcTimeNow = dateConvert("local2Utc", localTimeNow);
    unixEpoch = createDate(1970,1,1);

    // calculate offset with dateDiff
    timestampDateDiff = DateDiff("s", unixEpoch, utcTimeNow);
    // calculate offset using internal methods. 
    // getTime() return milliseconds. Divide by 1000 to get seconds
    // http://docs.oracle.com/javase/7/docs/api/java/util/Date.html#getTime%28%29
    timestampInternal = int(utcTimeNow.getTime()/1000);
    
    // calculate offset without ANY UTC stuff at all
    timestampLocal = dateDiff("s", unixEpoch, localTimeNow);

    // calculate the number of seconds difference between the offsets
    timestampDifference = timestampInternal - timestampDateDiff;
    
    // display base dates
    WriteOutput("<h3>Base Dates</h3>");
    WriteOutput("unixEpoch = "& unixEpoch);
    WriteOutput("<br>localTimeNow = "& localTimeNow);
    WriteOutput("<br>utcTimeNow = "& utcTimeNow);

    // display calculated timestamps
    WriteOutput("<h3>Calculated timestamps</h3>");
    WriteOutput("timestampDateDiff = "& timestampDateDiff);
    WriteOutput("<br><strong style='color:blue'>timestampInternal = "& timestampInternal &"</strong>");
    WriteOutput("<br>timestampLocal = "& timestampLocal);

    WriteOutput("<h3>Internal versus DateDiff TimeStamps</h3>");
    WriteOutput("<hr>difference (sec) = "& timestampDifference);
    WriteOutput("<br>difference (min) = "& timestampDifference/60);
    WriteOutput("<br>difference (hrs) = "& timestampDifference/60/60);
    
    WriteOutput("<h3>GetTimeZoneInfo</h3>");
    WriteDump(GetTimeZoneInfo());

    // alternative method for calcuating the timestamp
    WriteOutput("<h3>Alternative method for Timestamp</h3>");
    WriteOutput("authorize timestamp="& getAuthorizeNetTimeStamp());
    
    function getAuthorizeNetTimeStamp() {
        var utcTimeNow = "";
        var utcEpoc = "";
        // get UTC time zone
        var timeZone = createObject("java", "java.util.TimeZone").getTimeZone("GMT");
        
        // Get current UTC time. MUST change the time zone or CF uses the JVM default 
        var utcTimeNow = createObject("java", "java.util.GregorianCalendar").init();
        utcTimeNow.setTimeZone(timeZone);

        // Get Unix Epoch. MUST change the time zone or CF uses the JVM default 
        utcEpoch = createObject("java", "java.util.GregorianCalendar").init();
        utcEpoch.setTimeZone(timeZone);
        
        // clear everything to truncate the "time" portion
        utcEpoch.clear();
        // **NOTE** Month numbers are 0-based ie January = 0 
        utcEpoch.set(1970, 0, 1);

        return dateDiff("s", utcEpoch, utcTimeNow);
    }
</cfscript>

Open in new window






Test Results:

Base Dates
unixEpoch = {ts '1970-01-01 00:00:00'}
localTimeNow = {ts '2014-08-17 13:19:21'}
utcTimeNow = {ts '2014-08-17 17:19:21'}

Calculated timestamps
timestampDateDiff = 1408277961
timestampInternal = 1408295961  <=== this is correct
timestampLocal = 1408277961

Internal versus DateDiff TimeStamps
difference (sec) = 18000
difference (min) = 300
difference (hrs) = 5
0
 
LVL 3

Author Closing Comment

by:Eric Bourland
ID: 40266394
Elegant, simple solution. Working perfectly.

I have learned a tremendous amount about JVM, authorize.net, and new ColdFusion functions.

Many thanks, as always, to _agx_, for patience and investigation and guidance. This question required a lot of research and perseverance. I'm deeply grateful.

_agx_, hope your weekend is going very well. Take care. =)

Eric
0
 
LVL 52

Expert Comment

by:_agx_
ID: 40266568
Hope you enjoy the remainder of the weekend Eric :) Try not to work too much!
0

Featured Post

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article  is about submitting  form through  ColdFusion.Ajax.submitForm to the action page and send a response back in JSON format which later can be decoded using ColdFusion.JSON.decode. By this way you can avoid the usual page refresh for subm…
PROBLEM:  How to open a cfwindow or run a function on double click of a cfgrid row. One of my clients wanted to be able to double click on a row item to get more detailed information about a transaction and to be able to modify the line items i…
this video summaries big data hadoop online training demo (http://onlineitguru.com/big-data-hadoop-online-training-placement.html) , and covers basics in big data hadoop .
Are you ready to place your question in front of subject-matter experts for more timely responses? With the release of Priority Question, Premium Members, Team Accounts and Qualified Experts can now identify the emergent level of their issue, signal…
Suggested Courses
Course of the Month18 days, 1 hour left to enroll

831 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question