Path: csiph.com!usenet.pasdenom.info!weretis.net!feeder1.news.weretis.net!feeder.erje.net!eu.feeder.erje.net!xlned.com!feeder5.xlned.com!news2.euro.net!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.003 X-Spam-Evidence: '*H*': 0.99; '*S*': 0.00; 'try:': 0.07; 'cc:addr:googlegroups.com': 0.09; 'function:': 0.09; 'subject:skip:a 10': 0.09; 'cc:addr:python-list': 0.10; 'def': 0.10; ':-)': 0.13; '-tkc': 0.16; '1900': 0.16; '2100': 0.16; 'from:addr:python.list': 0.16; 'from:addr:tim.thechases.com': 0.16; 'from:name:tim chase': 0.16; 'len(parts)': 0.16; 'wrote:': 0.17; 'cc:2**1': 0.24; 'cc:addr:python.org': 0.25; 'header:In- Reply-To:1': 0.25; 'date.': 0.33; 'dates': 0.33; 'false': 0.35; 'there': 0.35; 'but': 0.36; 'cc:no real name:2**1': 0.36; 'charset :us-ascii': 0.36; 'being': 0.37; 'subject:: ': 0.38; 'things': 0.38; 'instead': 0.39; 'range': 0.60; 'received:50.22': 0.84; 'received:108': 0.91 Date: Fri, 22 Feb 2013 10:18:45 -0600 From: Tim Chase To: Ferrous Cranus Subject: Re: Checking for valid date input and convert appropriately In-Reply-To: <7c5dff1b-1dd1-494a-b774-47db1e55e329@googlegroups.com> References: <92536c34-cf00-4497-b646-ab79fa4ee062@googlegroups.com> <5bac38bb-df2e-47b8-96dd-2b1c090959e4@googlegroups.com> <49de0696-b6f6-42ce-9272-79dac37c9605@googlegroups.com> <0065de90-75e4-4a50-b084-be6c8c7e5f23@googlegroups.com> <7c5dff1b-1dd1-494a-b774-47db1e55e329@googlegroups.com> X-Mailer: Claws Mail 3.7.6 (GTK+ 2.20.1; x86_64-pc-linux-gnu) Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-AntiAbuse: This header was added to track abuse, please include it with any abuse report X-AntiAbuse: Primary Hostname - boston.accountservergroup.com X-AntiAbuse: Original Domain - python.org X-AntiAbuse: Originator/Caller UID/GID - [47 12] / [47 12] X-AntiAbuse: Sender Address Domain - tim.thechases.com Cc: python-list@python.org, comp.lang.python@googlegroups.com X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 20 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1361549847 news.xs4all.nl 6917 [2001:888:2000:d::a6]:37101 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:39585 On 2013-02-22 07:07, Ferrous Cranus wrote: > Actually it can, but instead of try: i have to create a function: > > def is_sane_date(date): > parts = [int(part) for part in date.split() if part.isdigit()] > if len(parts) == 3 and \ > 1 <= parts[0] <= 31 and \ > 1 <= parts[1] <= 12 and \ > 1900 <= parts[2] <= 2100: > return True > return False Then you have things like "31 2 2013" being a valid date. Also, the hard caps at 1900 and 2100 are both pretty short-sighted. To the best of my knowledge, there are valid dates outside that date range :-) -tkc