Skip to main content

Custom VuC functions: parse_date

Scott Barber, Performance testing consultant, AuthenTec

Currently, Scott Barber serves as the lead Systems Test Engineer for AuthenTec. AuthenTec is the leading semiconductor provider of fingerprint sensors for PCs, wireless devices, PDAs, embedded access control devices and automotive markets. He is also member of the Technical Advisory Board for Stanley-Reid Consulting, Inc.

With a background in consulting, training, network architecture, systems design, database design and administration, programming, and management, Scott has become a recognized thought leader in the field of performance testing and analysis. Before joining AuthenTec, he was a software testing consultant, a company commander in the United States Army and a government contractor in the transportation industry.

Scott is a co-founder of WOPR (the Workshop on Performance and Reliability), a semi-annual gathering of performance testing experts from around the world, a member of the Context-Driven School of Software Testing and a signatory of the Agile Manifesto. He is a discussion facilitator for the Performance and VU Testing forum on Rational DeveloperWorks and a moderator for the performance testing and Rational TestStudio related forums on QAForums.com. Scott speaks regularly at a variety of venues about relevant and timely testing topics. Scott’'||CHR(59)||'s Web site complements this series and contains much of the rest of his public work. You can address questions/comments to him on either forum or contact him directly via e-mail.

Summary:  The custom VuC procedure described here retrieves the current date and time from the Web server and populates a series of strings in formats suitable for input into Web forms or as parameters for other functions. This function is part of a library of customized utilities and VuC functions created by experts in the testing community.

Date:  30 Jun 2005
Level:  Introductory
Activity:  160 views
Comments:  

Editor's note: This article is part of a library of custom VuC functions developed by performance test engineers to handle special situations encountered in scripting applications. For an overview of the library and links to other custom functions, see "A Library of Custom VuC Functions."

The parsedate procedure retrieves the current date and time from the Web server and populates a series of strings in formats suitable for input into Web forms or as parameters for other functions.

Purpose/use

When you build performance test scripts for Web-based applications, you sometimes need to capture all or portions of the current date and/or time. It's possible to parse the date from the local machine using the built-in tod library routine, but in the all-too-common case where the local host and the Web server aren't in sync, parsing from tod can yield results that cause unexpected errors. For this reason, I wrote the parsedate procedure to parse the date and time from the Web server rather than the local machine.

Calling the procedure results in ten strings being populated with date/time data that can be used later in your script. Those ten strings and their output are as follows:

  • str_time is populated with the current time in the form hh:mm:ssAM in the correct time zone.
  • str_ampm is populated with either AM or PM as appropriate.
  • str_hour is populated with the one- or two-digit hour (1-12).
  • str_min is populated with the two-digit minute (00-59).
  • str_sec is populated with the two-digit second (00-59).
  • str_day is populated with the two-digit date (01-31).
  • str_month_num is populated with the two-digit month (01-12).
  • str_month_ltr is populated with the three-letter month abbreviation (Jan, Feb).
  • str_year is populated with the four-digit year (for example, 2001).
  • str_zone is populated with the time zone of the Web server (for example, GMT).

Requirements

This procedure works only in conjunction with HTTP scripts and requires at least one successful server connection to collect the data.


Procedure code

Here's the code for the parsedate procedure, to be included in the script:

string str_time, str_ampm, str_hour, str_min, str_sec, str_date, 
   str_day, str_month_num, str_month_ltr, str_year, str_zone;

proc parsedate(str_date)
string str_date; 

{
int int_start; 

      int_start = strstr(str_date, ",");
      str_day = substr(str_date, int_start + 2, 2);
      int_start = strstr(str_date, ":");
      str_year = substr(str_date, int_start - 7, 4);
      str_month_ltr = substr(str_date, int_start - 11, 3);
      if (str_month_ltr == "Jan") 
            str_month_num = "01";
      else if (str_month_ltr == "Feb") 
            str_month_num = "02";
      else if (str_month_ltr == "Mar") 
            str_month_num = "03";
      else if (str_month_ltr == "Apr") 
            str_month_num = "04";
      else if (str_month_ltr == "May") 
            str_month_num = "05";
      else if (str_month_ltr == "Jun") 
            str_month_num = "06";
      else if (str_month_ltr == "Jul") 
            str_month_num = "07";
      else if (str_month_ltr == "Aug") 
            str_month_num = "08";
      else if (str_month_ltr == "Sep") 
            str_month_num = "09";
      else if (str_month_ltr == "Oct") 
            str_month_num = "10";
      else if (str_month_ltr == "Nov") 
            str_month_num = "11";
      else 
            str_month_num = "12";

   str_sec = substr(str_date, (lcindex(str_date, ':')) +1, 2);
   str_min = substr(str_date, (lcindex(str_date, ':')) -2, 2);
   str_zone = substr(str_date, (lcindex(str_date, ':')) +4, 3);
   str_hour = substr(str_date, (lcindex(str_date, ':')) -5, 2);
   if (str_zone == "GMT") str_hour = itoa(atoi(str_hour)-5);
   if (atoi(str_hour) >=13){
      str_hour = itoa(atoi(str_hour)-12);	
      str_ampm = "PM";
   }
   else str_ampm = "AM";

str_time = str_hour+":"+str_min+":"+str_sec+str_ampm; 
 
}

This line of the procedure may need to be modified based on the time zone of the local machine:

if (str_zone == "GMT") str_hour = itoa(atoi(str_hour)-5);

The line as it appears above is written to convert GMT (the default time zone for Web servers) to EST (the time zone of the local machine) by subtracting five hours from GMT. To change the output, simply modify the -5 to reflect the real difference between your machine's time zone and GMT.

The parsedate procedure can be placed in each calling script immediately following the #include command, or it can go in a separate .h file referenced by an additional #include command. The procedure can then be put in either the test script section of the repository or the Rational Test include directory. Putting it in the latter location will give you the benefit of not having to copy this procedure into every repository you work with.


Command syntax

str parsedate(http_header_info("Date"))

where http_header_info("Date") passes in the Date: line from the Web server's response to the most recent successful server connection.


Examples of use

I've most often used the parsedate procedure to create strings that I then use as inputs into Web-based forms. I've found that this procedure is particularly useful when scripting applications with data that must follow a specific series of steps (workflow) as performed by a variety of users.

For example, in an accounting system I recently tested, financial journals are entered into the system by a data entry specialist and then become associated with their effective dates. Managers typically search for new journals by running reports on journals with effective dates in, say, the last seven days. If I made no modification to the journal entry script as recorded, this would be fine for the first seven days after the script was recorded, but when I executed the related journal search execution script eight days later, it would return no journals because I would still in effect be entering journals eight days ago. I could overcome this by putting the effective date in a datapool and updating that datapool each day before tests are executed.

Following is the relevant section of the original script as recorded to do this (modified slightly to remove client identification). This script segment doesn't stand alone and is only intended to demonstrate how the procedure and resulting strings can be used.

set Server_connection = hq2unx144_12;

http_header_recv \\\["Journal~2.035"\\\] 200;    /* OK */

http_nrecv \\\["Journal~2.036"\\\] 100 %% ; /* 5812 bytes */

http_disconnect(hq2unx144_12);

stop_time \\\["tmr_journal_save"\\\];

start_time\\\["tmr_journal_run"\\\];

set Think_avg = 145;

hq2unx144_13 = http_request \\\["Journal ~2.037"\\\] "myurl.com",
   HTTP_CONN_DIRECT,
   "POST /psc/host/EMPLOYEE/ERP/c/PROCESS_JOURNALS.JOURNAL_EDIT_REQ.G"
      "BL HTTP/1.1\r\n"
   "Accept: image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, applicat"
      "ion/vnd.ms-powerpoint, application/vnd.ms-excel, 
      application/msword, */"
   "*\r\n"
   "Referer: http://myurl.jsp"
   "Accept-Language: en-us\r\n"
   "Content-Type: application/x-www-form-urlencoded\r\n"
   "Accept-Encoding: gzip, deflate\r\n"
   "User-Agent: Mozilla/4.0 (compatible; MSIE 5.5; Windows NT 5.0; T312461)"
   "\r\n"
   "Host: myurl.com\r\n"
   "Content-Length: 689\r\n"
   "Connection: Keep-Alive\r\n"
   "Cache-Control: no-cache\r\n"
   "Cookie: JSESSIONID=PJkAkyNiYzWSPWY3QRf2u9bWXeBz6qOE5EDa2hH3nxqIhqIra0tz"
   "!817206577!180373556!80!7002!NONE\r\n"
   "\r\n";
"JRNL_REQ_FREQUENCY="+http_url_encode(datapool_value(DP1, "Frequency"))+
"JOURNAL_ID="+http_url_encode(datapool_value(DP1, "JID"))+
"JRNL_EFFECTIVE_DATE=" + http_url_encode(datapool_value(DP1, "Edate"))+
"\r\n";

You can see that the JRNL_EFFECTIVE_DATE is included in the datapool. The problem with this is that if I forget to update the datapool each day before tests are executed, I'm in trouble. To modify this to use the parsedate procedure, I simply added one line of code and substituted the strings to replace the datapool value with today's date, as follows:

set Server_connection = hq2unx144_12;

http_header_recv \\\["Journal~2.035"\\\] 200;    /* OK */

parsedate(http_header_info("Date"));

http_nrecv \\\["Journal~2.036"\\\] 100 %% ; /* 5812 bytes */

http_disconnect(hq2unx144_12);

stop_time \\\["tmr_journal_save"\\\];

start_time\\\["tmr_journal_run"\\\];

set Think_avg = 145;
	
hq2unx144_13 = http_request \\\["Journal ~2.037"\\\] "myurl.com",
HTTP_CONN_DIRECT,
   "POST /psc/host/EMPLOYEE/ERP/c/PROCESS_JOURNALS.JOURNAL_EDIT_REQ.G"
      "BL HTTP/1.1\r\n"
   "Accept: image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, applicat"
      "ion/vnd.ms-powerpoint, application/vnd.ms-excel, 
      application/msword, */"
   "*\r\n"
   "Referer: http://myurl.jsp"
   "Accept-Language: en-us\r\n"
   "Content-Type: application/x-www-form-urlencoded\r\n"
   "Accept-Encoding: gzip, deflate\r\n"
   "User-Agent: Mozilla/4.0 (compatible; MSIE 5.5; Windows NT 5.0; T312461)"
   "\r\n"
   "Host: myurl.com\r\n"
   "Content-Length: 689\r\n"
   "Connection: Keep-Alive\r\n"
   "Cache-Control: no-cache\r\n"
   "Cookie: JSESSIONID=PJkAkyNiYzWSPWY3QRf2u9bWXeBz6qOE5EDa2hH3nxqIhqIra0tz"
   "!817206577!180373556!80!7002!NONE\r\n"
   "\r\n";
"JRNL_REQ_FREQUENCY="+http_url_encode(datapool_value(DP1, "Frequency"))+
"JOURNAL_ID="+http_url_encode(datapool_value(DP1, "JID"))+
"JRNL_EFFECTIVE_DATE="+str_month_num+"/"+str_day+"/"+str_year+""
"\r\n";


About the author

Currently, Scott Barber serves as the lead Systems Test Engineer for AuthenTec. AuthenTec is the leading semiconductor provider of fingerprint sensors for PCs, wireless devices, PDAs, embedded access control devices and automotive markets. He is also member of the Technical Advisory Board for Stanley-Reid Consulting, Inc.

With a background in consulting, training, network architecture, systems design, database design and administration, programming, and management, Scott has become a recognized thought leader in the field of performance testing and analysis. Before joining AuthenTec, he was a software testing consultant, a company commander in the United States Army and a government contractor in the transportation industry.

Scott is a co-founder of WOPR (the Workshop on Performance and Reliability), a semi-annual gathering of performance testing experts from around the world, a member of the Context-Driven School of Software Testing and a signatory of the Agile Manifesto. He is a discussion facilitator for the Performance and VU Testing forum on Rational DeveloperWorks and a moderator for the performance testing and Rational TestStudio related forums on QAForums.com. Scott speaks regularly at a variety of venues about relevant and timely testing topics. Scott’'||CHR(59)||'s Web site complements this series and contains much of the rest of his public work. You can address questions/comments to him on either forum or contact him directly via e-mail.

Comments



Trademarks  |  My developerWorks terms and conditions

Help: Update or add to My dW interests

What's this?

This little timesaver lets you update your My developerWorks profile with just one click! The general subject of this content (AIX and UNIX, Information Management, Lotus, Rational, Tivoli, WebSphere, Java, Linux, Open source, SOA and Web services, Web development, or XML) will be added to the interests section of your profile, if it's not there already. You only need to be logged in to My developerWorks.

And what's the point of adding your interests to your profile? That's how you find other users with the same interests as yours, and see what they're reading and contributing to the community. Your interests also help us recommend relevant developerWorks content to you.

View your My developerWorks profile

Return from help

Help: Remove from My dW interests

What's this?

Removing this interest does not alter your profile, but rather removes this piece of content from a list of all content for which you've indicated interest. In a future enhancement to My developerWorks, you'll be able to see a record of that content.

View your My developerWorks profile

Return from help

static.content.url=http://www.ibm.com/developerworks/js/artrating/
SITE_ID=1
Zone=Rational
ArticleID=4277
ArticleTitle=Custom VuC functions: parse_date
publish-date=06302005
author1-email=dwinfo@us.ibm.com
author1-email-cc=

My developerWorks community

Tags

Help
Use the search field to find all types of content in My developerWorks with that tag.

Use the slider bar to see more or fewer tags.

Popular tags shows the top tags for this particular content zone (for example, Java technology, Linux, WebSphere).

My tags shows your tags for this particular content zone (for example, Java technology, Linux, WebSphere).

Use the search field to find all types of content in My developerWorks with that tag. Popular tags shows the top tags for this particular content zone (for example, Java technology, Linux, WebSphere). My tags shows your tags for this particular content zone (for example, Java technology, Linux, WebSphere).

Rate a product. Write a review.

Special offers