473,382 Members | 1,387 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,382 software developers and data experts.

Validate time where start time should be less than end time

20
Hello im using dhtmlx grid in this cells i have from time and to time (i.e ind==1 and ind==2) i need to validate time where to-time must be greater than from-time else it should alert an message,i have writeen a normal Regular expression for the time validation.as the time is i string format i.e[05:00],please can any one send me code for that.thank you

Expand|Select|Wrap|Line Numbers
  1. var err_str="";
  2. function validate_grid(value,id,ind)
  3.     {
  4.     if(ind==1 || ind==2)
  5.         {
  6.             var patt=/^([0][0-9]|[1][0-9]|[2][0-3])[:]{1}[0-5][0-9]$/;
  7.             if(!patt.test(value))
  8.             {
  9.                 mygrid.setCellTextStyle(id,ind,"background-color:yellow;");
  10.                 if(err_str!="")
  11.                     err_str+="\n"+(ind+1)+".Enter numbers and : only..";
  12.                 else
  13.                     err_str=(ind+1)+".Enter numbers and : only";
  14.                 return false;
  15.             }
  16.             else
  17.             {
  18.                 mygrid.setCellTextStyle(id,ind,"background-color:white;");
  19.                 return true;
  20.             }
  21.         }
  22. }
  23.  
Jan 19 '12 #1
16 11900
C CSR
144 100+
Are you saying your parameter for time is a string? Was it always a string or did you convert it before you passed it to this function?

How is it "gathered"(user input?, database?, list?).

For good measure, please list the values and types of the arguments (value, id, ind) for this function, and , show the types before and after any conversion was made prior to this function call.

That may be helpful in providing a shortcut to your issue.
Jan 19 '12 #2
C CSR
144 100+
And I forgot: Are you using AM & PM with these values?
Jan 19 '12 #3
narinas
20
Actually the concept is dhtmlxgrid http://docs.dhtmlx.com/doku.php?id=d...ing#validation
im not checking AM and PM,its 24hr format,im checking regular expression for that ind==1 and 2
Jan 19 '12 #4
C CSR
144 100+
I went to the site and it did not explain the type of values it contains. I have to assume they are put there as strings from wherever they come from. The problem with that is we can't compare their values as is for several reasons. But here's two reasons:

1) As strings, 12 < 5 and 22 < 19. (based on the first chars)

2) We have to make sure they are in a "controllable" format, even if it is a string (same size and shape). That is because we would need to perform some operations on them to create "comparable" values. Otherwise the code gets messy.

Also, if you are planning on doing this inside the function you sent, I only see one value coming in! If I'm wrong, clearly explain to me how.

The only nice way to compare date/time strings is if they can be converted to a Date/Time variable "type." Then we can evaluate them within a few steps.

Any more information or ideas?
Jan 19 '12 #5
C CSR
144 100+
Correction: 22 is not less than 19, but you see what I mean :)
Jan 19 '12 #6
C CSR
144 100+
Here's one possibility:

Get the length of the string, so that if its less that 5 add a zero (0) to the front. You get both strings with a length of 5. If there all in this shape ( hh:nn ) then you can compare them with:

example:
x = "5:00"; y = "12:00"; length of x is < 5, so x = "0" & x;

now you have:
x = "05:00"; y = "12:00";

In terms of strings, x would be less than y, as it should be. Note: if these string cross over into 2 separate days, it messes it up without the AM & PM designators to test. What do you think?
Jan 19 '12 #7
narinas
20
yes if i take 08:00 and 8:00 its showing error.look at this code
Expand|Select|Wrap|Line Numbers
  1. <script type = "text/javascript">
  2.  
  3. var fromTime = "05:50";  // format hh:mm
  4. var toTime = "06:21";
  5. var ft = fromTime.split(":");
  6. var tt = toTime.split(":");
  7. var OK = false;
  8. if (tt[0] > ft[0]) {OK=true}
  9. if ((tt[0] == ft[0]) && (tt[1] > ft[1])) {OK = true}
  10. if (OK) {
  11. alert ("The second time is after the first time");
  12. var hr = tt[0] - ft[0];
  13. var mn = tt[1] - ft[1];
  14. if (mn < 0) {mn= mn+60; hr = hr-1}
  15. if (mn <10) {mn = "0" + mn}
  16. alert ("Difference is " + hr + ":" + mn);
  17. }
  18. else {alert ("The second time is NOT after the first time")}
  19.  
  20. </script>
  21.  
Jan 19 '12 #8
narinas
20
how to set this variables to indexes in grid and compare b/w those two cells.
Jan 19 '12 #9
C CSR
144 100+
Your code seems to work okay. I don't think you need the "split" part in there, but it does work. The Results should be the same because as strings "05:50" is less that "6:21". And "05:50" is less than "05"55". But the way you did it gave you the datatype "number" to use for things like "the difference." Good Job!

I can't see the calling function for the code you sent at the top. What does that look like? Maybe we can create a similar function, but bring in both values and run your test, and then loop them through the code you already have, one at a time. Then return.

Maybe nest the old code inside your new code as a function. Not sure without see original call to "function validate_grid(value,id,ind)".
Jan 19 '12 #10
C CSR
144 100+
I'm starting to write poorly. Taking a break for a while! Hang in there.
Jan 19 '12 #11
narinas
20
as im new to grid i dont know how to get the value of the cells i.e.indexhttp://www.dhtmlx.com/docs/products/...h_message.html
so that i can use the value in the variables
Jan 19 '12 #12
narinas
20
thank you for helping me.
Jan 19 '12 #13
C CSR
144 100+
Do you have access to the "calling" procedure? I mean, something is calling the function you showed me at the top of this thread, not the one you wrote. What is calling "function validate_grid(value,id,ind)"???
Jan 19 '12 #14
narinas
20
i have sent u an link about that function its used for validation part.& please find the attachment of my program.
Attached Files
File Type: doc ta_canteen_rates_grid(main page).doc (52.0 KB, 588 views)
Jan 20 '12 #15
C CSR
144 100+
Narinas:

After looking around at the DHX site and the code piece you have, I have to say this is fairly big project altogether--lots of components. But sticking to what we've been discussing I made a few observations. First, the "value" appears to be any length of string, basically whatever you want to type in. And there's only one (1) value per set of coordinates (indexes). That means the entire string would have to be parsed just to determine where a time-string might be, if there was one, before comparing it in any way. In other words, the grid itself does not specifically have any "time controls" in it (like From: & To:); but I did notice "time-controls" on another page on a "scheduler" component, where outside of its grid there were startTime & endTime controls to set up a time block attached to a string value for "notes" in each location. But those controls, where you set the time block, have built-in validation and you wouldn't be responsible for coding that.

I know I'm talking about 2 different parts of a scalable project, and you're only working on 1 of these two (I think) based on the design sheet I got from you. The one you are working on does not have any time-controls (and I don't know exactly how you would insert them), so the user would be able to input anything they want with no restrictions, and as a "string" value the application doesn't care if there are numbers separated by colons in the middle of it (e.g., 00:00:00) and it doesn't keep track of where they might be inside its string. The cell (e.g., x1,y1), or let's just call it a "box," only allows a single Value at this point, and that's a problem if you want 2 distinct strings to compare.

Now, I saw in there where you can specify the Value's format for input, so you could set up a "mask" according to their formatting constants (or make some custom constant if its allowed) and at least get some control over the input (like xx:xx_xx:xx) and then parse that. But then thats all the grid were be good for.

So, I'm dissecting this as best I can, but its obviously daunting and a rather time consuming project. My advice is to get with the creators of this product and get some real good answers. The code is also a little beyond me with the PHP and its proprietary objects.

I hope some of this makes sense and forgive me where I might be confused--there are a lot of applets and libraries to study at the DHX site to build your application. You have to start there for the best information.

I'll watch this post to see how it goes. Thank you.
Jan 20 '12 #16
narinas
20
Thanks a lot csr,im also totally confused by this grid structure.please help me out as soon as possible.thank you.
Jan 20 '12 #17

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: engsol | last post by:
I'm using Python to parse a bunch of s/w test files and make csv files for later report generation by MS ACCESS....(my boss loves the quick turn-around compared to C). Each log file may contain one...
1
by: softengine | last post by:
What are the pros and cons of Design-Time binding versus Run-Time binding controls? Our senior engineer is adamant about not binding control during design-time. Are there differences in...
3
by: Dan | last post by:
Question on how to do this. I'm trying to make a script that has 3 text fields in a form. When a start time is entered in a text field in the form the other 2 fields display the time with a set...
18
by: swaroophr | last post by:
Which of switch statement and if-else statement takes less time to execute?
2
by: idealfellow | last post by:
I am using the following to get the time: puts Time.now --> starting of my script <MY CODE> puts Time.now --> end of my script I want to get the Time difference between two Time.now...
1
by: JAS1503 | last post by:
Hi SQL friends, We're using a proximity card for logging in the attendance. I have a field for door access and field also for its corresponding log date and time. Since there are several logs of...
1
by: tmdan | last post by:
Hi, I am looking for some help with an MS Access query. I need to change my start of day time from the default 00:00 to 06:00. Is there any way to do this in a query? I am using the below...
1
by: vikrant2108243 | last post by:
i wanna know some creative,easier and less time consuming ideas for creating project. i am a new user...
1
by: mabiriizihudson | last post by:
how do i use server 2003 to manage login start and end time for other devices in my internet cafe. hudson
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.