Gossamer Forum
Home : Products : Gossamer Links : Discussions :

Date Widget

Quote Reply
Date Widget
What I would like, is a routine that accepts two integers, and returns a drop down list of dates that is between today+first_int and today+second_int.

This would allow a user to be presented with a form that would allow them to select a date from 1 to two weeks in the future, for example.

This would get past the problem of a user entering a typed date, or a date that is just waaay too funky for practicality. It would help guide them into the right frame of mind, and would just require a simple test on validation to make sure the date was in-range.

I think I'm starting to fry here, but this involves some math, and I was never any good at that... <G>

PUGDOGŪ
PUGDOGŪ Enterprises, Inc.
FAQ: http://postcards.com/FAQ


Quote Reply
Re: Date Widget In reply to
Hmm, how about:

Code:
Links::init_date();
my $widget = "<select name=foo>" . calc_date ($day1, $day2) . "</select>";

sub calc_date {
my ($time1, $time2) = @_;
my @dates;
while ($time2 > $time1) {
push (@dates, GT::Date::date_get ($time2));
$time2 = $time2 - 86400;
}
push (@dates, GT::Date::date_get ($time1));
return join "<option>$_", reverse @dates;
}
Cheers,

Alex

--
Gossamer Threads Inc.
Quote Reply
Re: Date Widget In reply to
I knew there had to be a way... :)

I'll let you know if it works <G>

The reason for some of this is that it makes the interface cleaner, and at the same time, makes validity and security checking easier. Users can't type in bogus data, or wild data you have to decide is real or not. You have a limited range of "OK" data, and users are guided into using it.

All the major hacking lately, I'm becoming compulsive about user data.

PUGDOGŪ
PUGDOGŪ Enterprises, Inc.
FAQ: http://postcards.com/FAQ


Quote Reply
Re: Date Widget In reply to
I've been playing with the date routines, and have had some problems.

I've modified the sub to do more of what I need, and I hit a very interesting bug. Take a look at what the output of this code is:

Code:
sub calc_date {
my ($time1) = @_;
print $IN->header();
print $time1, "<BR>";
my @dates;
my $widget;
if (GT::Date::date_is_valid ($time1)) {
my $end_date = GT::Date::date_add($time1, 14);
print $end_date, "<BR>";
while ($time1 <= $end_date) {
$widget .= "<option>" . GT::Date::date_get ($time1);
#$time2 = $time2 - 86400;
print $time1, " is going to change now: ";
$time1 = GT::Date::date_add ($time1, 1);
print $time1, "<BR>";
}
return;
} else {
print "Error, bad date";
return;
}
}
PUGDOGŪ
PUGDOGŪ Enterprises, Inc.
FAQ: http://postcards.com/FAQ


Quote Reply
Re: Date Widget In reply to
Hi,

I think this is where better examples would have helped. =) My main question is, what is $time1, a unix timestamp or a date string?

Cheers,

Alex

--
Gossamer Threads Inc.
Quote Reply
Re: Date Widget In reply to
Hi,

This is a really nice feature. Currently I use a javascript calender for, but it would be great to have a feature like this on my Links 2.0 (not SQL!)

So if someone would visit my website they would get a dropdownlist with the dates of the next 14 days (on the contactform, after the question: wich day would you like to be visited by our salespeople.)

(Yes, indeed I alsow use Links for my contactpage!)

- Chris


Quote Reply
Re: Date Widget In reply to
Well, the docs say to pass in the string in the current date/time format.

My test string has been "2000-12-06"

And YES! more examples! :)

PUGDOGŪ
PUGDOGŪ Enterprises, Inc.
FAQ: http://postcards.com/FAQ


Quote Reply
Re: Date Widget In reply to
Ah, I see what you mean. I've fixed that bug! Change in Date.pm, sub _format_date:

mm => sprintf ("% 02d", $mon),

to:

mm => sprintf ("% 02d", $mon + 1),

(Needs a space after the % sign for the forum only). Also, you need to replace:

while ($end_date > $time1) {

with:

while (GT::Date::date_is_greater($end_date, $time1)) {

as these are date strings, not numbers that can be compared with > or <.

Cheers,

Alex

--
Gossamer Threads Inc.