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


Groups > comp.lang.javascript > #19454

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

Path csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!newsreader4.netcologne.de!news.netcologne.de!newsfeed.arcor.de!newsspool2.arcor-online.net!news.arcor.de.POSTED!not-for-mail
Content-Type text/plain; charset="ISO-8859-1"
Message-ID <1776447.jtyAQvLSIL@PointedEars.de> (permalink)
From Thomas 'PointedEars' Lahn <PointedEars@web.de>
Reply-To Thomas 'PointedEars' Lahn <usenet@PointedEars.de>
Organization PointedEars Software (PES)
Date Thu, 25 Apr 2013 01:42:52 +0200
User-Agent KNode/4.8.5
Content-Transfer-Encoding 7Bit
X-Face %i>XG-yXR'\"2P/C_aO%~;2o~?g0pPKmbOw^=NT`tprDEf++D.m7"}HW6.#=U:?2GGctkL,f89@H46O$ASoW&?s}.k+&.<b';Md8`dH6iqhT)6C^.Px|[=M@7=Ik[_w<%n1Up"LPQNu2m8|L!/3iby{-]A+#YE}Kl{Cw$\U!kD%K}\2jz"QQP6Uqr],./"?;=4v
Face iVBORw0KGgoAAAANSUhEUgAAADAAAAAwBAMAAAClLOS0AAAAGFBMVEXTxa4RFk5dUWANED8PFEfy7+MGBiW+n3ZNF/QuAAACaElEQVQ4jVXUwVOcMBQG8Dc7Rc4PUntdWV2uxjDpGaGeozOp1woar4jd5t/v9wLstMwsA/ntlxdCAgUc1hjTc9/JCZfGoo3wG3HdmdAWrIJRHe7GM/TmpY5VFefuVcAkkPbLIaN8rmPmjloyZxgyR3GuJ4K0AGtJ2htz8o7yqikm759fldQXaMpbDzjKAG+8v+AugVTOPO5DOjLvGtUYQwh0CPjnVMyGd+8/GfUB5nLKJDD2aLDh5HYyMDJGDwQIo2ZmZcKbowNmAdB/AzyFhrmF2MHRb0QJJfaAnwGB6orZhoykLzJtGwF/xpYxI1dswomiUj3gTuAIqCn/4C7cULwGNBtwMTk3Y4LfKB5YUaOKBKYtpplm7u0vip8tU1NWWyI/7XdcSuIDoMt6rVHMWT0DbjHPGqDqZVSa6zleLcUTcIKLoMv3ueJluALtAo9B302zPPlrtiVScRdCjXvVh3e3JpYa/jjkuC9N+LrBMlz/eAN4eQijX2EdLo6c5tGGHwLyHFtXk89dDGHwCVhG9T0S/j55AhRZgkMCmUQXJ49TnS1wnQDvw0eAh9ICeMmEFbCnPMFzjAvsWoEWEFdYEx+S0MoUZ1gT1wId8+AF3Bl2OoEu906AUHx5VLw/gXYg/x84loOah/2UYNrgiwSwGO7RfUzVBbx/kgpckumGOi6QirtD6gkLTitbnxNol47S2jVc2vsN5kPqaAHT8uUdAJM4v/DanjYOwmUjWznGfwB7sGtAtor5BgofDuzaRj4kSQAqDakTsKORa3Q3xKi3gE1fhl71KRMqrdZ2AWNNg/YOhQyrVBnb+i+nEg4bsDA+egAAAABJRU5ErkJggg==
Subject Re: How to best check if a time hh:mm is within a range
Newsgroups comp.lang.javascript
References <kl9kba$nlb$1@dont-email.me>
MIME-Version 1.0
Lines 28
NNTP-Posting-Date 25 Apr 2013 01:42:52 CEST
NNTP-Posting-Host 34f9b61a.newsspool1.arcor-online.net
X-Trace DXC=Ek[H2Z?m<K5^8FBo0_81f>ic==]BZ:af>4Fo<]lROoR1nkgeX?EC@@0:HSIQ^WeST2DZm8W4\YJN<b@mF9jNikd5IQbgJMhLo07Si_;K1:i7\>
X-Complaints-To usenet-abuse@arcor.de
Xref csiph.com comp.lang.javascript:19454

Show key headers only | View raw


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.

Back to comp.lang.javascript | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

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

csiph-web