Gossamer Forum
Home : Products : DBMan : Customization :

another post Date & Time issue

Quote Reply
another post Date & Time issue
Hi all,

For I have the following setting in default.cfg:

%db_def = (
'ID' => [ 0, 'numer', 5, 8, 1, '', ''],
'Number' => [ 1, 'numer', 8, 10, 1, '', '\d{1}'],
'Name' => [ 2, 'alpha', 20, 20, 1, '', ''],
'Date' => [ 3, 'date', 11, 11, 1, &get_date(), ''],
'Time' => [ 4, 'alpha', 8, 8, 1, &get_time(), ''],
'Maxsize' => [ 5, 'numer', 8, 10, 1, '1', '\d{1}'],
'Userid' => [ 6, 'alpha', -2, 15, 1, '', '']
);


I find that there is validation check for Date field, however, no Time field. I mean I can input 33:00:00 in Time field.

Any suggestion?

Cary
Quote Reply
Re: [caryhung] another post Date & Time issue In reply to
>>I find that there is validation check for Date field, however, no Time field.<<

There is no validation for either field.

What formats do you want to check for?
Quote Reply
Re: [Paul] another post Date & Time issue In reply to
Hi Paul,

Quote:
There is no validation for either field.

However, I cannot enter 33-Mar-2002? It seems that there is validation check for Date field.

For Time field I can enter 33:30:30, obviously, 'hh' cannot exceed 24, agree? (currently, I am using hh:mm:ss format in 24hr)

Any suggestion?

Cary
Quote Reply
Re: [caryhung] another post Date & Time issue In reply to
You could make this a hidden field since you are getting the time from your server. You set the format for the display.

Or, you could provide an example next to the field entry to specify the accepted format.

Unoffical DBMan FAQ

http://creativecomputingweb.com/dbman/index.shtml/
Quote Reply
Re: [LoisC] another post Date & Time issue In reply to
Hi LoisC,

Quote:
You could make this a hidden field since you are getting the time from your server. You set the format for the
display.

Hidden field is not possible for user have to enter time parameter. I get the time from server is mainly for reference to users.



Quote:
Or, you could provide an example next to the field entry to specify the accepted format.

I've already done that, however, I am afraid some users make careless mistake. Any other suggestion?

Thanks
Cary
Quote Reply
Re: [caryhung] another post Date & Time issue In reply to
For time field of format: hh:mm:ss

try setting your time field within your .cfg file to this:

'Time' => [ 4, 'alpha', 8, 8, 1, &get_time(),'\d{1,2}:\d{2}:\d{2}'],

I came up with this from some perl notes, so it is not tested. Try it and see if works and then let me know.

There are also regular expressions in the FAQ under 'dates' or 'syntax' to specify the acceptable format.

Unoffical DBMan FAQ

http://creativecomputingweb.com/dbman/index.shtml/
Quote Reply
Re: [LoisC] another post Date & Time issue In reply to
Hi LoisC,

Quote:
'Time' => [ 4, 'alpha', 8, 8, 1, &get_time(),'\d{1,2}:\d{2}:\d{2}'],

I've put this statement on my .cfg, however, it doesn't work. For I still can enter 33:30:30...

Any suggestion?

Cary
Quote Reply
Re: [caryhung] another post Date & Time issue In reply to
Hi all,

After reading Unofficial FAQ by LoisC: Category: Syntax, Validated, I've learn some regular expression and tested the following...

'Time' => [ 4, 'alpha', 8, 8, 1, &get_time(),'[0-2]d{1}\[0-4]d{1}:\d{2}:\d{2}'],

I tried to restrict the first digit to 0,1,2 and the second digit to 0,1,2,3,4.

However, it doesn't work, therefore, I would like to ask some comment for this statement.

Regard
Cary

Last edited by:

caryhung: Mar 21, 2002, 11:11 PM
Quote Reply
Re: [caryhung] another post Date & Time issue In reply to
I believe what I provided does work but only to check for the amount of numbers in the defined spaces.

If you are using:

sub get_time {
# --------------------------------------------------------
# Returns the time in the format "hh-mm-ss".

#### added to show AM/PM format
my ($AMPM);
my (@hours) = qw!12 1 2 3 4 5 6 7 8 9 10 11 12 1 2 3 4 5 6 7 8 9 10 11!;
if ($hour > 12) { $AMPM = "AM"; } else { $AMPM = "PM"; }
#### end of addition ####
my ($sec, $min, $hour, $day, $mon, $year, $dweek, $dyear, $daylight) = localtime(time());
($sec < 10) and ($sec = "0$sec");
($min < 10) and ($min = "0$min");
($hour < 10) and ($hour = "0$hour");

#### return "$hour:$min:$sec"; ### replaced with below - left off seconds
return "$hours[$hour]:$min $AMPM";
}

You'll notice the hours are defined to not exceed 12, so the higher numbers wouldn't be accepted. That is where you would need to make adjustments for the validation your are wanting.

Try uncommenting the lines and use:

return "$hour:$min:$sec";

rather than:

return "$hours[$hour]:$min $AMPM";

and perhaps you will get the results you are looking for.

Unoffical DBMan FAQ

http://creativecomputingweb.com/dbman/index.shtml/
Quote Reply
Re: [LoisC] another post Date & Time issue In reply to
Hi LoisC,

I've copied the entire sub to my db.cgi. However, I still can enter 25:00pm. No validation has been done.

Any suggestion?
Cary
Quote Reply
Re: [caryhung] another post Date & Time issue In reply to
For anyone trying to assist on this request, Cary is allowing the USER to enter the time (pulling system time as a default display in field) and wants to prevent USERS from entering anything higher than 24 hours, higher than 60 minutes or anything higher than 60 seconds.

I don't know how to set those checks - just chiming in on the explanation of what he's trying to do.
Quote Reply
Re: [Karen] another post Date & Time issue In reply to
Thanks you Karen.

Is there anybody who can tell me what's wrong with the following statement??

Quote:
'Time' => [ 4, 'alpha', 8, 8, 1, &get_time(),'[0-2]d{1}\[0-4]d{1}:\d{2}:\d{2}'],

Please help.

Cary
Quote Reply
Re: [caryhung] another post Date & Time issue In reply to
[0-2]d{1}\[0-4]d{1}:\d{2}:\d{2}

The d is mising a \ the \[0-4] should have no \ at the beginning.

What if I want to enter: 19:38:25 ? ....that code would reject it. Also I could enter 12:99:99

Last edited by:

Paul: Mar 24, 2002, 2:16 AM
Quote Reply
Re: [Paul] another post Date & Time issue In reply to
Quote:
What if I want to enter: 19:38:25 ? ....that code would reject it. Also I could enter 12:99:99


Although I could be mistaken, it seems that's pretty close to the same thing Cary said in an earlier post. Would you by any chance know how he would prepare a regex which would allow:

1 or 2 digits (min 01 max 24):1 or 2 digits (min 00 max 59):1 or 2 digits (min 00 max 59)

to end up with possible combinations that may result in a valid time display (hh:mm:ss)?

Thanks!

~ Karen
Quote Reply
Re: [Paul] another post Date & Time issue In reply to
Hi Paul,

I've done the following in .cfg file:

Quote:
'Time' => [ 4, 'alpha', 8, 8, 1, &get_time(),'[0-2]\d{1}[0-4]\d{1}:[0-59]\d{2}:[0-59]\d{2}'],

However, I also find 'Time (Invalid format)' no matter what I enter (even the time entry is normal).

Any suggestion?

Cary
Quote Reply
Re: [caryhung] another post Date & Time issue In reply to
Try:

'[0-2][0-4]:[0-6][0-9]:[0-6][0-9]'

Thats about as close as you'll get without writing something long. It will allow 60-69 for the minutes and seconds but without writing something longer I can't think of a way to get round it.

Last edited by:

Paul: Mar 26, 2002, 2:27 AM
Quote Reply
Re: [Paul] another post Date & Time issue In reply to
Hi Paul,

I've changed the following:

Quote:
'Time' => [ 4, 'alpha', 8, 8, 1, &get_time(),'[0-2][0-3]:[0-59]:[0-59]'],

However, it always 'Time (Invalid format)'.

Unsure
Cary
Quote Reply
Re: [caryhung] another post Date & Time issue In reply to
You can't enter any number inside the [ ] - it only allows 0 to a maximum of 9.

Also why do you have [0-3] when the 24 hour clock goes up to 24.

Try what I suggested.

Last edited by:

Paul: Mar 27, 2002, 1:56 AM
Quote Reply
Re: [Paul] another post Date & Time issue In reply to
Hi Paul,

I've changed this:

Quote:
'Time' => [ 4, 'alpha', 8, 8, 1, &get_time(),'[0-2][0-4]:[0-6][0-9]:[0-6][0-9]'],

But it returns 'Time (Invalid format)'.

Frown

Cary
Quote Reply
Re: [caryhung] another post Date & Time issue In reply to
What exactly are you entering for the time?
Quote Reply
Re: [Paul] another post Date & Time issue In reply to
Cary:

You should also post your current sub get_time for Paul to see. If you are still using the version I provided above then it is setup to use am/pm and not entering military time formats.

That could be why you are getting the invalid format error.

Unoffical DBMan FAQ

http://creativecomputingweb.com/dbman/index.shtml/
Quote Reply
Re: [LoisC] another post Date & Time issue In reply to
Hi LoisC,

Thank you for reminding me. (in fact, I'm going to be crazy now!) Crazy

I am still using the original get_time:

Quote:
sub get_time {
# --------------------------------------------------------
# Returns the time in the format "hh-mm-ss".
#
my ($sec, $min, $hour, $day, $mon, $year, $dweek, $dyear, $daylight) = localtime(time());
($sec < 10) and ($sec = "0$sec");
($min < 10) and ($min = "0$min");
($hour < 10) and ($hour = "0$hour");

return "$hour:$min:$sec";
}

And what I've enter is:

09:35:35 or 19:35:35 or 25:35:35

All of them give invalid error messages...

Except: 22:35:35 and 23:35:35, it's quit strange??

Any idea?

Cary
Quote Reply
Re: [caryhung] another post Date & Time issue In reply to
I don't see any reason for it to say invalid. For the date rotuine I'd use:

Code:
sub get_time {
# --------------------------------------------------------
# Returns the time in the format "hh-mm-ss".
#

require POSIX; import POSIX qw/strftime/;
return POSIX::strftime("%H:%m:%s", localtime);
}

The regex shouldn't tell you the format is wrong.