Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.javascript > #19449 > unrolled thread

How to best check if a time hh:mm is within a range

Started by"Tony Johansson" <johansson.andersson@telia.com>
First post2013-04-24 23:57 +0200
Last post2013-04-26 21:03 +0100
Articles 4 — 3 participants

Back to article view | Back to comp.lang.javascript


Contents

  How to best check if  a time hh:mm is within a range "Tony Johansson" <johansson.andersson@telia.com> - 2013-04-24 23:57 +0200
    Re: How to best check if  a time hh:mm is within a range Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2013-04-25 01:42 +0200
      Re: How to best check if  a time hh:mm is within a range Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2013-04-25 13:02 +0200
    Re: How to best check if  a time hh:mm is within a range Dr J R Stockton <reply1300@merlyn.demon.co.uk.invalid> - 2013-04-26 21:03 +0100

#19449 — How to best check if a time hh:mm is within a range

From"Tony Johansson" <johansson.andersson@telia.com>
Date2013-04-24 23:57 +0200
SubjectHow to best check if a time hh:mm is within a range
Message-ID<kl9kba$nlb$1@dont-email.me>
I have three radio buttons where I can choose between
60 min, 30 min and 15 min.

I write 8 time header. If radio 60 min has been selected I write 8 hour 
starting
with the current hour rounded back.If current time is for example 15:20 I 
write
15:00     16:00     17:00     18:00     19:00     20:00     21:00     22:00

If radio 30 min has been selected I write 8 30 min starting
with the current half hour rounded back.If current time is for example 15:40 
I write
15:30     16:00     16:30     17:00     17:30     18:00     18:30     19:00

If radio 15 min has been selected I write 8 15 min starting
with the current quarer  rounded back.If current time is for example 15:55 I 
write
15:45     16:00     16:15     16:30     16:45     17:00     17:15     17:30

When I get data according to format yyyy-mm-dd hh:mm from db I know that 
date is always correct.
Now what is the best algoritm to check if the hh:mm that I get from db lies 
within the time header range.
For example if hh:mm from db is 23:05 and for example my header range is 
this
15:00     16:00     17:00     18:00     19:00     20:00     21:00     22:00
then hh:mm is not within the  time header range.

//Tony



[toc] | [next] | [standalone]


#19454

FromThomas 'PointedEars' Lahn <PointedEars@web.de>
Date2013-04-25 01:42 +0200
Message-ID<1776447.jtyAQvLSIL@PointedEars.de>
In reply to#19449
Tony Johansson wrote:

> When I get data according to format yyyy-mm-dd hh:mm from db I know that
> date is always correct.
> Now what is the best algoritm to check if the hh:mm that I get from db
> lies within the time header range.
> For example if hh:mm from db is 23:05 and for example my header range is
> this
> 15:00     16:00     17:00     18:00     19:00     20:00     21:00    
> 22:00
> then hh:mm is not within the  time header range.

Assuming your headers are in an Array, (if necessary) sort that Array using 
a string comparator (which should be the default, but you can be sure that 
way).  Then compare the first element and the last element of the resulting 
Array against the time value string.  Or, if you already know the smallest 
and the greatest value, skip the Array sorting step and compare against 
those values.

Because there are leading zeroes in the time format, string comparison is 
the same as numeric comparison of the atoms, so conversion (to Number, or 
Date) is unnecessary.

-- 
PointedEars

Twitter: @PointedEars2
Please do not Cc: me. / Bitte keine Kopien per E-Mail.

[toc] | [prev] | [next] | [standalone]


#19466

FromThomas 'PointedEars' Lahn <PointedEars@web.de>
Date2013-04-25 13:02 +0200
Message-ID<85443254.jIUFstNyxt@PointedEars.de>
In reply to#19454
Thomas 'PointedEars' Lahn wrote:

> Tony Johansson wrote:
>> […]
>> For example if hh:mm from db is 23:05 and for example my header range is
>> this
>> 15:00     16:00     17:00     18:00     19:00     20:00     21:00
>> 22:00
>> […]
> 
> […]
> Because there are leading zeroes in the time format,

… *and* it is a 24-hours format …

> string comparison is the same as numeric comparison of the atoms, so
> conversion (to Number, or Date) is unnecessary.

-- 
PointedEars

Twitter: @PointedEars2
Please do not Cc: me. / Bitte keine Kopien per E-Mail.

[toc] | [prev] | [next] | [standalone]


#19498

FromDr J R Stockton <reply1300@merlyn.demon.co.uk.invalid>
Date2013-04-26 21:03 +0100
Message-ID<x9k6EPFa2teRFwa+@invalid.uk.co.demon.merlyn.invalid>
In reply to#19449
In comp.lang.javascript message <kl9kba$nlb$1@dont-email.me>, Wed, 24
Apr 2013 23:57:55, Tony Johansson <johansson.andersson@telia.com>
posted:

>Now what is the best algoritm to check if the hh:mm that I get from db
>lies within the time header range.

Before that can be answered, it is necessary to know the meaning of
"best".

Sometimes shortest is best, sometimes fastest is best (until a new
browser version alters relative speeds of different algorithms).
Sometimes simplest is best; but perceived simplicity depends on the
experience of the perceiver.  Sometimes, cheapest to write is best.

For such an easy task, the performance of the overall system will depend
only very slightly on which algorithm is chosen, provided that it is
reasonable and infallible.

-- 
 (c) John Stockton, nr London, UK.  Mail via homepage.  Turnpike v6.05  MIME.
  Web  <http://www.merlyn.demon.co.uk/> - FAQqish topics, acronyms and links;
  Astro stuff via astron-1.htm, gravity0.htm ; quotings.htm, pascal.htm, etc.
 No Encoding. Quotes before replies. Snip well. Write clearly. Don't Mail News.

[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.javascript


csiph-web