Skip to main content
`Ctrl`+`K`

# ObsTime

This module contains the class to manage timestamps

class tracklib.core.ObsTime.ObsTime(year=1970, month=1, day=1, hour=0, min=0, sec=0, ms=0, zone=0)

  Class to represent the phenomenom time of an observation.

  BASE_YEAR = 2000
  UNIX_BASE_YEAR = 1970
  ROUND_TO_SEC = 1
  __READ_FMT = '2D/2M/4Y 2h:2m:2s'
  __PRINT_FMT = '2D/2M/4Y 2h:2m:2s'
  __PRECOMPILED_READ_FMT = [('2D', 0), ('2M', 3), ('4Y', 6), ('2h', 11), ('2m', 14), ('2s', 17)]
  __fmt_nd = ['{:01d}', '{:02d}', '{:03d}', '{:04d}']
  __codes = ['1D', '2D', '1M', '2M', '2Y', '4Y', '1h', '2h', '1m', '2m', '1s', '2s', '1z', '2z', '3z']
  __day_per_month = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
  __month_names = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec']
  __day_names = ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun']
  __day_of_base_date = 3
  __init__(year=1970, month=1, day=1, hour=0, min=0, sec=0, ms=0, zone=0)

    __init__ Constructor of `ObsTime` class

    Default value : 01/01/1970 00:00:00.000

    Parameters

      - year (`int`) – Year, defaults to 1970

      - month (`int`) – month defaults to 1

      - day (`int`) – day of month, defaults to 1

      - hour (`int`) – your, defaults to 0

      - min (`int`) – minute, defaults to 0

      - sec (`int`) – second, defaults to 0

      - ms (`int`) – millisecond, defaults to 0

      - zone (`int`) – time zone, defaults to 0

  copy()

    Copy the object

    Return type

      `ObsTime`

    Returns

      copy of current object

  static setPrintFormat(format)

    Set the format for printing a ObsTime object

    The print format is use by the `ObsTime.__str__()` method

    Parameters

      format (`str`) – Format for printing ObsTime

  static setReadFormat(format)

    Set the format for reading a ObsTime object

    Parameters

      format (`str`) – Format for reading

  static getPrintFormat()

    Return the print format

    Return type

      `str`

    Returns

      The print format

  static getReadFormat()

    Return the read format

    Return type

      `str`

    Returns

      The read format

  static readUnixTime(elapsed_seconds)

    Converting elapsed float seconds since 01/01/1970 in ObsTime

    Warning: does not consider leap seconds (31 since 1970)

    Parameters

      elapsed_seconds (`float`) – Elapsed seconds

    Return type

      `ObsTime`

    Returns

      Coverted time

  toAbsTime()

    Converting to elapsed float seconds since 01/01/1970 (or 01/01/UNIX_BASE_YEAR)

    Warning: does not consider leap seconds since 1972

    Return type

      `float`

    Returns

      elapsed float seconds

  static random()

    Generate random date between 01/01/1970 and 01/01/2050

    Return type

      `ObsTime`

  static now()

    Get Current Date and Time

    Return type

      `ObsTime`

  printZone()

    Print zone code (Z if greenwhich) ISO 8601

    Return type

      `str`

  timeWithZone()

    Print as Gpx time

    Return type

      `str`

  convertToZone(zone)

    Zone conversion

    Parameters

      zone (`int`) – Time zone

    Return type

      `ObsTime`

    Returns

      Time for the set time zone

  getDayOfWeek()

    Return the current day of week

    Return type

      `str`

  __fillMember(value, code)

    Adding value in a field according to code

  __takeSecond()

    Methods to prepare reading timestamp format

  __rep(char, n)

    Generate a string repeting a char

    Parameters

      - char (`str`) – Caracter to repeate

      - n (`int`) – Number or repetitions

    Retunr

      A string of n repetitions of c

    Return type

      `str`

  __precompileReadFmt(format)

    Precompile the reader

    Parameters

      format (`str`) – A format string

    Return type

      `list`[`tuple`[`str`, `int`]]

    Returns

      A list of precompiled symbols

  static readTimestamp(timeAsString)

    Build timestamp from string according to READ_FMT

    Parameters

      timeAsString (`str`) – Timestamp in string format

    Return type

      `ObsTime`

  __replace(chaine, id, length, new)

    Remplacing substring of length length, starting at pos id in string chaine with new string new

    Parameters

      - chaine (`str`) – String to remplace

      - id (`int`) – Starting position of replacement

      - length (`int`) – Length of substring to remplace

      - new (`str`) – String of replacement

    Return type

      `str`

    Returns

      Replaced string

  __str__()

    Prints timestamp according to PRINT_FMT specification

    Retunr

      the timestamp to print

    Return type

      `str`

  addSec(nb)

    Add nb seconds to current time

    Parameters

      nb (`int`) – Number of seconds to add

    Return type

      `ObsTime`

    Returns

      A `ObsTime` incremented of nb second(s)

  addMin(nb)

    Add nb minutes to current time

    Parameters

      nb (`int`) – Number of minutes to add

    Return type

      `ObsTime`

    Returns

      A `ObsTime` incremented of nb minute(s)

  addHour(nb)

    Add nb hours to current time

    Parameters

      nb – Number of hours to add

    Returns

      A `ObsTime` incremented of nb hour(s)

  addDay(nb)

    Add nb days to current time

    Parameters

      nb – Number of days to add

    Returns

      A `ObsTime` incremented of nb day(s)