[python-uk] Last Thursday's meet - roll call.

Simon Brunning python-uk@python.org
Tue, 20 Aug 2002 12:03:39 +0100

This message is in MIME format. Since your mail reader does not understand
this format, some or all of this message may not be legible.

Content-Type: text/plain

Bah! That'll teach me to post code in progress. Somewhat cleaned up version

Simon Brunning
TriSystems Ltd.
>  <<boozeup.py>> 
The information in this email is confidential and may be legally privileged.
It is intended solely for the addressee. Access to this email by anyone else
is unauthorised. If you are not the intended recipient, any disclosure,
copying, distribution, or any action taken or omitted to be taken in
reliance on it, is prohibited and may be unlawful. TriSystems Ltd. cannot
accept liability for statements made which are clearly the senders own.

Content-Type: application/octet-stream;
Content-Disposition: attachment;

import mx.DateTime

def getNextBoozeupDate(relativeDate=None):
    """Return the date of the next Python South-East UK booze up as an
    mx.DateTime.DateTime object.

    Optional parameter relativeDate defaults to current date."""
    relativeDate = relativeDate or mx.DateTime.today()
    thisMonthsBoozeupDate = getMonthsBoozeupDate()
    if thisMonthsBoozeupDate >= relativeDate:
        return thisMonthsBoozeupDate
    nextMonthsBoozeupDate = getMonthsBoozeupDate(month=relativeDate.month+1)
    return nextMonthsBoozeupDate

def getMonthsBoozeupDate(year=0, month=0):
    """Return the date of the Python South-East UK booze up in a given month
    as an mx.DateTime.DateTime object.

    The booze up will be on the 2nd Thursday of the month, unless the 1st
    Thursday is the 1st day of the month, in which case the booze up will be
    on the 1st.

    Optional parameters year and month default to the current date."""
    today = mx.DateTime.today()
    year = year or today.year
    month = month or today.month

    boozeupDate = mx.DateTime.DateTimeFrom(year=year, month=month) \
                + mx.DateTime.RelativeDateTime(weekday=(mx.DateTime.Thursday, 2))
    if boozeupDate.day == 8:
        boozeupDate = boozeupDate - 7

    return boozeupDate        
if __name__ == '__main__':
    print getNextBoozeupDate()