Jump to content

comparing strings


jimfog

Recommended Posts

I have made a dropdown menu where the options are times(in string format)...like this: http://jsfiddle.net/fiddlehunt/5WVKz/

 

How am I going to test if the user selected a value bigger than 10:00?

Since we are talking about strings here I do not think the inequality operators will do any good-I tried it anyway.

 

O do not know what I could do in a case such as this.

Link to comment
Share on other sites

The of the option should be something that refers to a specific date or time, like a Unix timestamp. Convert it to a date object then test.

I will consider what you say,it makes sense.Nonetheless,I do not know if it is the optimum solution for my case.

Anyway, I will do what you suggest.

 

Given the fact that each option must correspond to a different timestamp (and these must correspond to a specifc day/month) it will not be easy to do it,since I have to "tie" the logic with the one supplied by the jquery fullcalendar plugin http://arshaw.com/fullcalendar/

Edited by jimfog
Link to comment
Share on other sites

As I see it a must make a function that dynamically will populated the option values with the corresponding time stamps

 

The bottom line....do you have any idea how I could start this?

 

A representative piece of code maybe.

Link to comment
Share on other sites

I will try to be more specific...go to this fiddle here:http://jsfiddle.net/fiddlehunt/5xsxP/

 

Go to weekview of the calendar.When you click a time slot a popup appears with the times selected depicted in the dropdown menu.

Now,the option values of the dropdown menus are not timestamps (just look the HTML window).

 

How am I going to create timestamps that are dependent on the timeslots selected,taking into consideration also the day/month?

 

Is there a js method that can help me achieve that?

In PHP for example,if I recall correctly strtotime is used to covert textual datetime textual description into a UNIX timestamp.

 

Is there anything similar in JS? Is there any other alternative worth examining?

 

Do you understand now what I am trying to achieve?

Link to comment
Share on other sites

If you're trying to convert a string to a date object then it will need to be in a format that the date constructor understands, or else you need to parse the string and split it up into individual pieces for the constructor.http://stackoverflow.com/questions/5619202/converting-string-to-date-in-jshttps://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date

Link to comment
Share on other sites

If you're trying to convert a string to a date object then it will need to be in a format that the date constructor understands, or else you need to parse the string and split it up into individual pieces for the constructor.http://stackoverflow.com/questions/5619202/converting-string-to-date-in-jshttps://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date

You are saying "to convert a string to a date object". To be honest I do not know if that is even necessary.

 

 

Let me describe the problem again.I want to build a dropdown menu of times where each one will correspond to a different timestamp(and this will be depicted in the option value of the menu option selected.)

 

First of all I do not know if this must be done with JS or PHP...that is another issue to consider also.

Link to comment
Share on other sites

Well, then first you need to figure out exactly how you want your application to work. You posted this in the Javascript forum, so I gave you a Javascript solution. If you want to do it in PHP, there are options there also. I understand what the interface that you have is showing. Now you need to decide how you want the application to behave. That is your decision. You can do the conversion in Javascript, or you can do it in PHP. It doesn't matter to me.If it was me, the values for the dropdown options would be Unix timestamps instead of the same text that the user sees. I make it easy on the computer by using values that are easily understood by computers and showing text that is easily understood by people.There is no need to keep describing the problem. What you need to do is decide how you want to solve it.

Link to comment
Share on other sites

well...I decided to post in this forum cause the application uses backbone to send event data to the server(that includes the timestamp).

 

I am going to post in the PHP forum cause I thing the HTML rendering(the dropdown menu with the timestamps) must be PHP's job.

 

It is a thought I just made and the future will tell if it is the correct solution.

 

I agree of course that the dropdown menus must be unix timestamps.

Link to comment
Share on other sites

well...I just made some progress.In JS,I maybe able to pull this off with JS,it might not be necessary to resort to PHP.

 

The first obstacle to create the dropdown menu is to get UNIX timestamps. Now, I managed to get the timestamps(start/end date of an event,it's duration in other words).

 

So this is the first step.

Now,,,,having these new data,how I could proceed and construct the dropdown?

The point being is that after the popup appears(with the selected dates) the user will be able to alter the start/end dates.just like in outlook.com calendar.

 

In other words....by having 2 timestamps is it possible to construct the other timestamps that will correspond to different times-there must be 30min intervals?

 

And these(of course) newly constructed timestamps will be placed in the option values of the menu.

 

Can JS help in the above?

Link to comment
Share on other sites

It sounds like you're asking for a for loop that starts at the first timestamp, ends at the last, and each time through the loop it gets incremented by 30 minutes.

Yes,you are correct. Timestamps for the whole 24h-and always based on a specific day/month.The one the user clicked.

The already present timestamps I suppose can help somehow-revealing some info about the day/month.

Link to comment
Share on other sites

Dividing by 1000 will fix this.That is not the problem here.

Link to comment
Share on other sites

I know that, I'm just pointing it out. I don't see a problem here, you just make a for loop to create the options, that's it. The value of each option is a timestamp that refers to a specific date and time. That's all the information you need, in one value.

Link to comment
Share on other sites

...The value of each option is a timestamp that refers to a specific date and time. That's all the information you need, in one value.

And this is the point where I am stuck,

Link to comment
Share on other sites

Ι do understand the logic but I am having difficulty implementing it.

So far I have concluded that the first step will be this:

 var inmilise=1401840000*1000;//this is a timestamp multiplied by 1000...        var d = new Date(inmilise);

The above prints a date...in this specific example it is this:

6/4/2014 3:00:00 AM

 

The above info must somehow be used in the loop...but the question is how specifically I must do this?

Link to comment
Share on other sites

are you asking how to loop through your data to dynamically generate an select tag with options, setting the value to a timestamp, and the display value to the formatted date? Because if you have the data, then I'm not sure what you're stuck on?

Link to comment
Share on other sites

are you asking how to loop through your data to dynamically generate an select tag with options, setting the value to a timestamp, and the display value to the formatted date? Because if you have the data, then I'm not sure what you're stuck on?

Yes...what you describe above is what I want to achieve.

Now to the problem itself.

 

I have one piece of data...a specific point in time(the specific timestamp)...I do not know how to use that and construct the loop-that is the problem.

 

It might simple to you but not to me.I am trying to find a solution to it myself too.

Link to comment
Share on other sites

i think we were all under the impression that you had an array, but if you don't then you don't need a loop.

 

Either way, it sounds like you need to learn how to create a select element with javascript and populate it with options. (Or have the select option on the page and append options to it, whatever suits your needs. I can find lots of examples of that online. Have you looked? What have you tried? Which part specifically are you stuck with?

Link to comment
Share on other sites

It's just like I described here:

It sounds like you're asking for a for loop that starts at the first timestamp, ends at the last, and each time through the loop it gets incremented by 30 minutes.

If you have 2 date objects for the start and end, that's all you need. It's just a basic for loop. The valueOf method of a date object returns the timestamp. Each time through the loop you increment the loop counter by the number of milliseconds in a half hour.
Link to comment
Share on other sites

i think we were all under the impression that you had an array, but if you don't then you don't need a loop.

 

 

No...I do not have an array...but I still think a loop is needed

 

It's just like I described here:If you have 2 date objects for the start and end, that's all you need. It's just a basic for loop. The valueOf method of a date object returns the timestamp. Each time through the loop you increment the loop counter by the number of milliseconds in a half hour.

There is a misunderstanding here.The start and end date are not the start and end of the 24h period as the dropdown option values must cover but

the start and end of an event...that can be 10:00 to 11:00 for example.

Link to comment
Share on other sites

Oh I get it. Your timestamp is the starting point and you need to show a bunch of dates in intervals after that till a determined endtime.

 

Well, then it's just like JSG said. Your starting condition is the starting timestamp, and the ending condition of the loop is the terminating condition. The increment in this case would just be the interval your application needs (30minutes, 60 minutes, whatever, in milliseconds).

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...