Skip to content

getml.data.time

Convenience functions for the handling of time stamps.

In getML, time stamps are always expressed as a floating point value. This float measures the number of seconds since UNIX time (January 1, 1970, 00:00:00). Smaller units of time are expressed as fractions of a second.

To make this a bit easier to handle, this module contains simple convenience functions that express other time units in terms of seconds.

seconds

seconds(num: float) -> float

Returns the number of seconds.

PARAMETER DESCRIPTION
num

The number of seconds.

TYPE: float

RETURNS DESCRIPTION
float

num

Source code in getml/data/time.py
23
24
25
26
27
28
29
30
31
32
33
34
def seconds(num: float) -> float:
    """
    Returns the number of seconds.

    Args:
        num:
            The number of seconds.

    Returns:
        *num*
    """
    return num

minutes

minutes(num: float) -> float

Expresses num minutes in terms of seconds.

PARAMETER DESCRIPTION
num

The number of minutes.

TYPE: float

RETURNS DESCRIPTION
float

num minutes expressed in terms of seconds.

Source code in getml/data/time.py
40
41
42
43
44
45
46
47
48
49
50
51
def minutes(num: float) -> float:
    """
    Expresses *num* minutes in terms of seconds.

    Args:
        num:
            The number of minutes.

    Returns:
        *num* minutes expressed in terms of seconds.
    """
    return seconds(num) * 60.0

hours

hours(num: float) -> float

Expresses num hours in terms of seconds.

PARAMETER DESCRIPTION
num

The number of hours.

TYPE: float

RETURNS DESCRIPTION
float

num hours expressed in terms of seconds.

Source code in getml/data/time.py
57
58
59
60
61
62
63
64
65
66
67
68
def hours(num: float) -> float:
    """
    Expresses *num* hours in terms of seconds.

    Args:
        num:
            The number of hours.

    Returns:
        *num* hours expressed in terms of seconds.
    """
    return minutes(num) * 60.0

days

days(num: float) -> float

Expresses num days in terms of seconds.

PARAMETER DESCRIPTION
num

The number of days.

TYPE: float

RETURNS DESCRIPTION
float

num days expressed in terms of seconds.

Source code in getml/data/time.py
74
75
76
77
78
79
80
81
82
83
84
85
def days(num: float) -> float:
    """
    Expresses *num* days in terms of seconds.

    Args:
        num:
            The number of days.

    Returns:
        *num* days expressed in terms of seconds.
    """
    return hours(num) * 24.0

weeks

weeks(num: float) -> float

Expresses num weeks in terms of seconds.

PARAMETER DESCRIPTION
num

The number of weeks.

TYPE: float

RETURNS DESCRIPTION
float

num weeks expressed in terms of seconds.

Source code in getml/data/time.py
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
def weeks(num: float) -> float:
    """
    Expresses *num* weeks in terms of seconds.

    Args:
        num:
            The number of weeks.

    Returns:
        *num* weeks expressed in terms of seconds.
    """
    return days(num) * 7.0

milliseconds

milliseconds(num: float) -> float

Expresses num milliseconds in terms of fractions of a second.

PARAMETER DESCRIPTION
num

The number of milliseconds.

TYPE: float

RETURNS DESCRIPTION
float

num milliseconds expressed in terms of seconds.

Source code in getml/data/time.py
108
109
110
111
112
113
114
115
116
117
118
119
def milliseconds(num: float) -> float:
    """
    Expresses *num* milliseconds in terms of fractions of a second.

    Args:
        num:
            The number of milliseconds.

    Returns:
        *num* milliseconds expressed in terms of seconds.
    """
    return seconds(num) / 1000.0

microseconds

microseconds(num: float) -> float

Expresses num microseconds in terms of fractions of a second.

PARAMETER DESCRIPTION
num

The number of microseconds.

TYPE: float

RETURNS DESCRIPTION
float

num microseconds expressed in terms of seconds.

Source code in getml/data/time.py
125
126
127
128
129
130
131
132
133
134
135
136
def microseconds(num: float) -> float:
    """
    Expresses *num* microseconds in terms of fractions of a second.

    Args:
        num:
            The number of microseconds.

    Returns:
        *num* microseconds expressed in terms of seconds.
    """
    return milliseconds(num) / 1000.0

datetime

datetime(
    year: int,
    month: int,
    day: int,
    hour: int = 0,
    minute: int = 0,
    second: int = 0,
    microsecond: int = 0,
) -> float

Returns the number of seconds since UNIX time (January 1, 1970, 00:00:00).

PARAMETER DESCRIPTION
year

Year component of the date.

TYPE: int

month

Month component of the date.

TYPE: int

day

Day component of the date.

TYPE: int

hour

Hour component of the date.

TYPE: int DEFAULT: 0

minute

Minute component of the date.

TYPE: int DEFAULT: 0

second

Second component of the date.

TYPE: int DEFAULT: 0

microsecond

Microsecond component of the date.

TYPE: int DEFAULT: 0

RETURNS DESCRIPTION
float

The number of seconds since UNIX time (January 1, 1970, 00:00:00).

Source code in getml/data/time.py
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
def datetime(
    year: int,
    month: int,
    day: int,
    hour: int = 0,
    minute: int = 0,
    second: int = 0,
    microsecond: int = 0,
) -> float:
    """
    Returns the number of seconds since UNIX time (January 1, 1970, 00:00:00).

    Args:
        year:
            Year component of the date.

        month:
            Month component of the date.

        day:
            Day component of the date.

        hour:
            Hour component of the date.

        minute:
            Minute component of the date.

        second:
            Second component of the date.

        microsecond:
            Microsecond component of the date.

    Returns:
        The number of seconds since UNIX time (January 1, 1970, 00:00:00).
    """
    return dt.datetime(
        year,
        month,
        day,
        hour,
        minute,
        second,
        microsecond,
        tzinfo=dt.timezone.utc,
    ).timestamp()