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> From: Thomas 'PointedEars' Lahn Reply-To: Thomas 'PointedEars' Lahn 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+&. 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?mic==]BZ:af>4Fo<]lROoR1nkgeX?EC@@0:HSIQ^WeST2DZm8W4\YJN X-Complaints-To: usenet-abuse@arcor.de Xref: csiph.com comp.lang.javascript:19454 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.