cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
1505
Views
15
Helpful
5
Replies

TIme Of Holidays

mightyking
Level 6
Level 6

Hi,

I am writing a Haliday script and need some help. The opening and closing time differs for each of our holidays shown in the below xml file. I need to verify the time of the day for each of them. How can I do that? Here's what I use for "desendant::child"

"/descendant::HOLIDAYS/child::HOLIDAY[attribute::ID='" + HolidayID.toString() + "']"

<?xml version="1.0" encoding="ISO-8859-1" ?>
<HOLIDAYS>
<HOLIDAY ID='1'>01/01/2015</HOLIDAY>
<HOLIDAY ID='2'>02/01/2015</HOLIDAY>
<HOLIDAY ID='3'>04/03/2015</HOLIDAY>
<HOLIDAY ID='4'>04/06/2015</HOLIDAY>
<HOLIDAY ID='5'>05/18/2015</HOLIDAY>
<HOLIDAY ID='6'>06/24/2015</HOLIDAY>
<HOLIDAY ID='7'>08/01/2015</HOLIDAY>
<HOLIDAY ID='8'>09/07/2015</HOLIDAY>
<HOLIDAY ID='9'>10/12/2015</HOLIDAY>
<HOLIDAY ID='10'>12/24/2015</HOLIDAY>
<HOLIDAY ID='11'>12/25/2015</HOLIDAY>
<HOLIDAY ID='12'>12/28/2015</HOLIDAY>
<HOLIDAY ID='13'>12/31/2015</HOLIDAY>
</HOLIDAYS>

Thanks,

MK

5 Replies 5

Bill Mungaven
Level 1
Level 1

MK,

This is how I would approach this. I would add a start time and end time tag to the XML file like this:

<HOLIDAY ID="1"><DATE>01/01/2015</DATE><STARTTIME>08:00 AM</STARTTIME><ENDTIME>05:00 PM</ENDTIME></HOLIDAY>

I would have date variables called startTime and endTime, currentDate, currentTime or variable names that make sense to you.

Once you figure out today is a holiday, you can read the start time and end time from the XML file. Using the /descendant format confuses me and I always seem to mess up the syntax so when I read something from an XML file using the Get XML Document Data step, I use a different method. In the XML path, I would use "//HOLIDAYS/HOLIDAY[@ID=" + counter + "]/STARTTIME" and the result data variable would be startTime. I would do the same with the end time ("//HOLIDAYS/HOLIDAY[@ID=" + counter + "]/ENDTIME".

Somewhere you have to keep a counter of which <HOLIDAY> tag you're reading like you do normally. Once you have this data, you can do your time of day check and continue with your script appropriately based on the current time and the startTime and endTime you read from the XML file.

I hope this helps.

Bill

Thanks to both of you. I really appreciate your help.

Bill

I am trying to follow you advise because it's closer to what I have done but don't seem to be able to make it work. I am doing something wrong at the last "if" where I am retreiving and comparing data. Please see attached the aef code. Let me know if you would code the aef differntely.

Thanks,

MK

MK,

Jonathan is a much more advanced programmer than I am; I'm still relatively new at this so I don't understand some of the more advanced techniques he used. I took some information from his post and modified it a bit. My solution is nowhere as nice as Jonathan's but it works. I'm sure my solution is more involved than it needs to be but it's simple for me to understand. I'm sure there's a much better way to do this but this works.

I changed the XML file a bit. Instead of using 24-hour format for the time, I could only get this to work using AM/PM format as shown below.

This is what I used in my example XML file:

<?xml version="1.0" encoding="ISO-8859-1"?>
<Holidays>
 <Holiday ID="1"><Start>12/10/2015 8:00 AM</Start><End>12/10/2015 5:00 PM</End></Holiday>
 <Holiday ID="2"><Start>12/11/2015 10:00 AM</Start><End>12/11/2015 4:00 PM</End></Holiday>
</Holidays>

I created 2 Date variables,holidayStartDate and holidayEndDate and 2 String variables, holidayStartDateString and holidayEndDateString. I also created 2 Document variables, holidayDocument and xmlDocument for the XML file reference and an integer to keep track of the holiday numbers in the XML file.

This isn't elegant but it worked. I tried to paste a picture of my code but I can't get it to paste inline for some reason. I pasted it into the attached document instead.

I hope this helps.

Bill

Thanks Bill,

Many thanks to Jonathan for sharing his own code with me.

MK

Jonathan Schulenberg
Hall of Fame
Hall of Fame

You will need both an XML file and AEF script that parses time and not just calendar date. To my knowledge there is not public example code of this. Here's a snippet from working code that I use if you want to use it as a starting point. You'll need to understand how calendars work in Java to succesfully code this and deal with gotchas such as daylight savings time or your CCX cluster nodes being in different time zones.

Example XML:

<?xml version="1.0" encoding="ISO-8859-1"?>
<!-- Date and time format is 'MM/DD/YYYY HH:MM:SS'. -->
<example>
<time_zone>America/New_York</time_zone>
<holidays>
<holiday>
<begin>01/01/2015 00:00:00</begin>
<end>01/01/2015 23:59:59</end>
</holiday>
<holiday>
<begin>05/25/2015 00:00:00</begin>
<end>05/25/2015 23:59:59</end>
</holiday>
</holidays>
</example>

Example AEF Code:

The variable I show opened in the upper-right corner is actually set to:

new java.text.SimpleDateFormat("MM/dd/yyyy HH:mm:ss", Locale.ENGLISH)

Getting Started

Find answers to your questions by entering keywords or phrases in the Search bar above. New here? Use these resources to familiarize yourself with the community: