×

Warning message

  • Cisco Support Forums is in Read Only mode while the site is being migrated.
  • Cisco Support Forums is in Read Only mode while the site is being migrated.

Time issue

Answered Question
Oct 12th, 2010
User Badges:
/* Style Definitions */ table.MsoNormalTable {mso-style-name:"Table Normal"; mso-tstyle-rowband-size:0; mso-tstyle-colband-size:0; mso-style-noshow:yes; mso-style-parent:""; mso-padding-alt:0in 5.4pt 0in 5.4pt; mso-para-margin:0in; mso-para-margin-bottom:.0001pt; mso-pagination:widow-orphan; font-size:10.0pt; font-family:"Times New Roman"; mso-ansi-language:#0400; mso-fareast-language:#0400; mso-bidi-language:#0400;}

Hey all!


I'm attempting to compare T[now] with other T[] values.  The issue here is the other T[] vales are in AM and PM format and the T[now] is in military.


The other T[] vales are pulled out of an XML file, placed in into values, and then constructed into a T[] format via a set statement (new Time() ).


So my question is...  How do i compare T[now] and my pulled XML values?


Please do not say make them strings.. 

Correct Answer by Anthony Holloway about 6 years 10 months ago

Have you read the Programming Guides?  Specifically the expression language reference guide?


There is a whole section on how to work with Time.  Just know that the ISO format HH-MM-SS it talks about is wrong, it's actually HH:MM:SS.


I promise you that this works, and is possible, you just need to get the syntax down.


Also, you don't have to use two If steps to check if it's within business hours.  You can do this instead.


if(t[now].after(open) && t[now].before(close))


Unless of course you care about before work hours, and after work hours separately.


i.e., "The early bird gets recording:  we haven't opened yet..."  VS  "Oh snap, you just missed us..."

  • 1
  • 2
  • 3
  • 4
  • 5
Overall Rating: 4 (3 ratings)
Loading.
rbblue234 Wed, 10/13/2010 - 04:45
User Badges:

If you have too..  you can say make them strings... 

Anthony Holloway Wed, 10/13/2010 - 05:45
User Badges:
  • Purple, 4500 points or more

The way you see or set the Time value, is independent of what it's actually holding.  It's holding the current date time stamp (albeit wrong by the Java spec.  more on that later).


Time is Time is Time....



So, if you are setting your returned String value from a Get XML Document Data step, in to a Time object:


set my_time_from_xml = "8:00 AM"


Where my_time_from_xml is a Time object created in the variable pane.



Then you could...



Do this if you have premium or enhanced:


if (t[now].after(my_time_from_xml))


OR


if (t[now].before(my_time_from_xml))



If you have standard or you like this syntax more than the above:


if (t[now] > my_time_from_xml))


OR


if (t[now] < my_time_from_xml))



To challenge what I am telling you, take both your variable that is assigned from an XML document, and t[now], and assign their ?.getTime() method results to a long variable.  You will see that no matter the displayed format, the internal value is the same.


set get_time_from_t_now = t[now].getTime()

set get_time_from_t_xml = my_time_from_xml.getTime()



The one exception is if you create a new Time object with the Time.valueOf() constructor.  It actually adheres to the Java spec and will produce a value whose date part is equal to January 1, 1970, and only holds the current time.  So, if you had a mixture of Time.valueOf() and Set steps that just type cast, you cannot compare these together like I showed you above.  You would have to resort to extracting out the Hour, Minute, and Second parts and comparing them as individual ints.


if (t[now].hour > my_time_from_xml.hour && t[now].min > my_time_from_xml.min && t[now].sec > my_time_from_xml.sec)
rbblue234 Wed, 10/13/2010 - 05:54
User Badges:

So if i understand you correctly...


My Open_Time is set as a value of T[08:00 AM]


In my script I update that value from XML int's

set Open_Time new time (XML_Open_Hour, XML_Open_Min, 00).


It would not be possible to compare T[now] >= Open_Time for @ times T[now] would be in military time thus always greater then 1-12 if open time is after 1pm

Anthony Holloway Wed, 10/13/2010 - 07:25
User Badges:
  • Purple, 4500 points or more

rbblue234 wrote:


In my script I update that value from XML int's

set Open_Time new time (XML_Open_Hour, XML_Open_Min, 00).


What do you mean by "XML int's"?  XML has no idea about types.  And a Get XML Document Data (GXDD) step only ever returns a String.


What does your XML look like?  I was thinking you were using something like this:


8:00 AM


In which case, when you grabbed that via the GXDD step, it would return the following string "8:00 AM".


You could then use a Set step to type cast that String into Time.


Here is the key take away from both of my posts:  If you have two Time objects, it doesn't matter how you created them or what they hold, you can *always compare them together with the less than, or greater than comparison operators, or the ?.before(), or ?.after() methods.


*Except when creating Time object from the Time.valueOf() constructor.  See my above post on why.


rbblue234 wrote:


It would not be possible to compare T[now] >= Open_Time for @ times T[now] would be in military time thus always greater then 1-12 if open time is after 1pm


Yes, even if one is in military time, and the other is not.

rbblue234 Wed, 10/13/2010 - 12:09
User Badges:

Hey,


I have the open time working fine as long as it's before 1pm.


My close time is all messed up.


in my XML file i have Close_Hour and Close_Min.


I yank them out of an XML file and store them sepertly into two different int field's.  I then use the above set command to pull them together into a Time field.  Because I store them in military time...  it auto populates the AM and PM field.  In this case It's 3:30 PM.


When calling in at 3:06pm and doing a debug on the script...  It passes the branch of open hours but fails closed hours.


rbblue234 Thu, 10/14/2010 - 06:18
User Badges:

Hey,


In my XML file i now have the values as 09:00:00 AM and 15:00:00 PM.


When i use a set step to configure Open_Time from the XML value I get an error message that says java.lang.NumberFormatException: For input string: "00 AM"



rbblue234 Thu, 10/14/2010 - 07:57
User Badges:

I have made a few changes to the script.


It's attached.  Can anyone help here?


It looks as if i set the time manually in a time statment value in the script it works.

It's only when values are entered via the XML file it mucks it up

Correct Answer
Anthony Holloway Thu, 10/14/2010 - 16:08
User Badges:
  • Purple, 4500 points or more

Have you read the Programming Guides?  Specifically the expression language reference guide?


There is a whole section on how to work with Time.  Just know that the ISO format HH-MM-SS it talks about is wrong, it's actually HH:MM:SS.


I promise you that this works, and is possible, you just need to get the syntax down.


Also, you don't have to use two If steps to check if it's within business hours.  You can do this instead.


if(t[now].after(open) && t[now].before(close))


Unless of course you care about before work hours, and after work hours separately.


i.e., "The early bird gets recording:  we haven't opened yet..."  VS  "Oh snap, you just missed us..."

rbblue234 Fri, 10/15/2010 - 04:34
User Badges:

Hey,


Please take a look at the updated script that's attached.


now.after(Open_Time) works fine.  But now.before(Close_Time) always releates to false.


Like i said...  When I enter the values manually it's fine.  But something is wrong when i pull the data out of the XML file and place it into a T value.  Reguardless if i do it via int's or string.  It's always failing.


Like you suggested before...  I had to break it out and compare hours and mins.

rbblue234 Fri, 10/15/2010 - 09:28
User Badges:

I'm so totally lost here...


I made a simple script which is now attached.


I have my start time set to 10:00:00 which is converted to 10:00 AM via time.valueOf set step.

I have my close set to 17:00:00 which is convered to 5:00 PM via time.valueOf set step.


My if statments pass now.after(Open) and fail if i set it too now.before(Open). Which is should since i'm runnig the scrip at 12:26pm.


My if statments returns false on the now.before(close) but returns true if i set it to now.after(close).


why does it work for open string and not my close string?

Attachment: 

Actions

This Discussion