Gnumed.pycommon.gmDateTime

Package Gnumed :: Package pycommon :: Module gmDateTime |
[frames] | no frames]

# Module gmDateTime

source code

    GNUmed date/time handling.

    This modules provides access to date/time handling
    and offers an fuzzy timestamp implementation

    It utilizes

            - Python time
            - Python datetime
            - mxDateTime

    Note that if you want locale-aware formatting you need to call

            locale.setlocale(locale.LC_ALL, '')

    somewhere before importing this script.

    Note regarding UTC offsets
    --------------------------

    Looking from Greenwich:
            WEST (IOW "behind"): negative values
            EAST (IOW "ahead"):  positive values

    This is in compliance with what datetime.tzinfo.utcoffset()
    does but NOT what time.altzone/time.timezone do !

    This module also implements a class which allows the
    programmer to define the degree of fuzziness, uncertainty
    or imprecision of the timestamp contained within.

    This is useful in fields such as medicine where only partial
    timestamps may be known for certain events.

    Other useful links:

            http://joda-time.sourceforge.net/key_instant.html

Author: K. Hilbert <Karsten.Hilbert@gmx.net>

License: GPL v2 or later (details at http://www.gnu.org)

Classes
| cPlatformLocalTimezone
| cFuzzyTimestamp A timestamp implementation with definable inaccuracy.

Functions
init() | source code
get_next_month(dt) | source code
get_last_month(dt) | source code
get_date_of_weekday_in_week_of_date(weekday, base_dt=None) | source code
get_date_of_weekday_following_date(weekday, base_dt=None) | source code
mxdt2py_dt(mxDateTime) | source code
format_dob(dob, format=`'``%Y %b %d``'`, none_string=None, dob_is_estimated=False) | source code
pydt_strftime(dt=None, format=`'``%Y %b %d %H:%M.%S``'`, accuracy=None, none_str=None) | source code
pydt_add(dt, years=0, months=0, weeks=0, days=0, hours=0, minutes=0, seconds=0, milliseconds=0, microseconds=0) | source code
pydt_replace(dt, strict=True, year=None, month=None, day=None, hour=None, minute=None, second=None, microsecond=None, tzinfo=None) | source code
pydt_is_today(dt) | source code
pydt_now_here() Returns NOW @ HERE (IOW, in the local timezone. | source code
pydt_max_here() | source code
wxDate2py_dt(wxDate=None) | source code
format_interval(interval=None, accuracy_wanted=None, none_string=None, verbose=False) | source code
format_interval_medically(interval=None) Formats an interval. | source code
format_pregnancy_weeks(age) | source code
format_pregnancy_months(age) | source code
is_leap_year(year) | source code
calculate_apparent_age(start=None, end=None) The result of this is a tuple (years, ..., seconds) as one would 'expect' an age to look like, that is, simple differences between the fields: | source code
format_apparent_age_medically(age=None) <age> must be a tuple as created by calculate_apparent_age() | source code
str2interval(str_interval=None) | source code
str2pydt_matches(str2parse=None, patterns=None) Turn a string into candidate dates and auto-completions the user is likely to type. | source code
str2fuzzy_timestamp_matches(str2parse=None, default_time=None, patterns=None) Turn a string into candidate fuzzy timestamps and auto-completions the user is likely to type. | source code

Variables
| __doc__ = ``...``
| dst_locally_in_use = `None`
| dst_currently_in_effect = `None`
| py_timezone_name = `None`
| py_dst_timezone_name = `None`
| current_local_utc_offset_in_seconds = `None`
| current_local_iso_numeric_timezone_string = `None`
| current_local_timezone_name = `None`
| gmCurrentLocalTimezone = ``'``gmCurrentLocalTimezone not initialized``'``
| gregorian_month_length = ``{`1`:` 31`,` 2`:` 28`,` 3`:` 31`,` 4`:` 30`,` 5`:` 31`,` 6`...``
| avg_days_per_gregorian_year = `365`
| avg_days_per_gregorian_month = `30`
| avg_seconds_per_day = `86400`
| days_per_week = `7`
| __package__ = ``'``Gnumed.pycommon``'``
| acc_days = `4`
| acc_hours = `5`
| acc_minutes = `6`
| acc_months = `2`
| acc_seconds = `7`
| acc_subseconds = `8`
| acc_weeks = `3`
| acc_years = `1`

Imports: sys, pyDT, time, os, regex, locale, logging

Function Details

### format_interval_medically(interval=None) | source code
Formats an interval. This isn't mathematically correct but close enough for display.

### calculate_apparent_age(start=None, end=None) | source code
    The result of this is a tuple (years, ..., seconds) as one would
    'expect' an age to look like, that is, simple differences between
    the fields:

            (years, months, days, hours, minutes, seconds)

    This does not take into account time zones which may
    shift the result by one day.

    <start> and <end> must by python datetime instances
    <end> is assumed to be "now" if not given

### str2pydt_matches(str2parse=None, patterns=None) | source code
Turn a string into candidate dates and auto-completions the user is likely to type. You MUST have called locale.setlocale(locale.LC_ALL, '') somewhere in your code previously. Parameters: `patterns` (list) - list of time.strptime compatible date pattern

### str2fuzzy_timestamp_matches(str2parse=None, default_time=None, patterns=None) | source code
Turn a string into candidate fuzzy timestamps and auto-completions the user is likely to type. You MUST have called locale.setlocale(locale.LC_ALL, '') somewhere in your code previously. Parameters: `default_time` (an mx.DateTime.DateTimeDelta instance) - if you want to force the time part of the time stamp to a given value and the user doesn't type any time part this value will be used `patterns` (list) - list of [time.strptime compatible date/time pattern, accuracy]

Variables Details

  ### __doc__ Value:
      """
      GNUmed date/time handling.

      This modules provides access to date/time handling
      and offers an fuzzy timestamp implementation

      It utilizes

      ...

  ### gregorian_month_length Value:
      {1: 31,
       2: 28,
       3: 31,
       4: 30,
       5: 31,
       6: 30,
       7: 31,
       8: 31,
      ...