Gossamer Forum
Home : Products : DBMan : Customization :

Establishing a current date environment

Quote Reply
Establishing a current date environment
With my "just learning" PERL abilities, I have run into a quirk that I can't understand. It's in assigning a date value to a URL within my PL file.

I have success when I add a sub to the PL to establish the date. I want to assign tomorrow's date, which allows one to view records that have not yet expired, including those that will expire "tomorrow". I use the following:
#-------------------------------------
sub search_date {
# Returns tomorrow's date in the correct format
my ($time) = $_[0];
($time) or ($time = time());
my ($sec, $min, $hour, $day, $mon, $year, $dweek, $dyear, $daylight) = localtime(($time + 86400));
my (@months) = qw!Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec!;
($day < 10) and ($day = "0$day");
$year = $year + 1900;
print qq|$day-$months[$mon]-$year|;
}

#--------------------------------------
I then call the date function within the "_home" sub inside of the PL file like this:

<area shape="rect" coords="303,89,391,111" href="$db_script_url?db=td&uid=default&view_records=1&expires-gt=|;
&search_date;
print qq|&sb=1&so=descend">

-----------------------------

This works great - initially. But, Once the program responds with "html_view_success," the value is a gonner! well, not quite - its new value is 1 Jan 1970 - big time warp[crazy]

What do I need to do to get the date back to its original value while inside of the html_view_success routine?

I tried to insert my date function inside of a separate routine that builds each page's top level lay out (the head, body tags, javascript/css source, etc - instead of repeating it in each sub routine). I did it this way:

sub html_pagebegin {
#This establishes the top format for each page
print qq|
<HTML>
<HEAD>
<TITLE>Training and Doctrine Directorate - </TITLE>
<LINK REL="stylesheet" TYPE="text/css"
HREF="$nimc/homepages.css">
<SCRIPT LANGUAGE="JavaScript1.2"
SRC="$nimc/nav.js">
<SCRIPT LANGUAGE="JavaScript1.2"
SRC="$nimc/nimc.js">
</SCRIPT>
</HEAD>
<BODY BGCOLOR="ffffff" ONLOAD="if (self != top) top.location = self.location">
(this goes on for a while until we get to the place where the value is needed, which begins now)
<area shape="rect" coords="303,89,391,111" href="$db_script_url?db=td&uid=default&view_records=1&expires-gt|;
# what is tomorrow's date?
my ($time) = $_[0];
($time) or ($time = time());
my ($sec, $min, $hour, $day, $mon, $year, $dweek, $dyear, $daylight) = localtime(($time + 86400));
my (@months) = qw!Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec!;
($day < 10) and ($day = "0$day");
$year = $year + 1900;
print qq|$day-$months[$mon]-$year|;# OK - back to html
print qq|&sb=1&so=descend" alt="Items of Interest" title="Items of Interest">
(and then the sub goes on until its ending)...

This sub is called at the beginning of the _home sub like this:

sub html_home {
# --------------------------------------------------------
# The database manager home page.
&html_print_headers;
&html_pagebegin;
print qq|
And the HTML stuff begins here...

Again, everything works fine, tomorrow's date is firmly established until one goes somewhere within the database - like html_view_success - POW! the time warp happens again.

What am I missing??? Can someone get me pointed in the right direction?

Thank you (sorry for the long dialog)

[;)]
Mike Ferris
Tech Integration Staff
Training and Doctrine Directorate
National Geo/Intel College
Wash DC
Quote Reply
Re: [Mike in DC] Establishing a current date environment In reply to
This is just a shot in the dark, so to speak but by looking at an example of choosing dates within another mod I would suggest changing:

($time) or ($time = time());
my ($sec, $min, $hour, $day, $mon, $year, $dweek, $dyear, $daylight) = localtime(($time + 86400));

to:

$time1 = time() - ($days * 86400);
my ($sec, $min, $hour, $day, $mon, $year, $dweek, $dyear, $daylight) = localtime($time1);

Notice you are changing $time to $time1

If that doesn't solve your problem you may want to view the threads in the FAQ under the section "Dates".

There is a thread called "Showing records in last week" which may help. I'm sure there may be others that will also provide ideas.

Hope this helps

Unoffical DBMan FAQ

http://creativecomputingweb.com/dbman/index.shtml/
Quote Reply
Re: [LoisC] Establishing a current date environment In reply to
Lois,

Works like a charm!!!Smile

Thanks so much for the advice - care to explain why this works when the other did not?

Thanks again
Mike Ferris
Tech Integration Staff
Training and Doctrine Directorate
National Geo/Intel College
Wash DC
Quote Reply
Re: [Mike in DC] Establishing a current date environment In reply to
I just know it has been used in other date functions and mods which use the date to prevent a conflict with the variable called $time.

I'm sure a search within some of the date threads in the FAQ may provide a more complete explaination.

Unoffical DBMan FAQ

http://creativecomputingweb.com/dbman/index.shtml/