# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

# from https://docs.python.org/3/library/datetime.html
from datetime import timedelta, tzinfo, date, datetime


ZERO_TIME = timedelta(0)


class UTC(tzinfo):
    def utcoffset(self, dt):
        return ZERO_TIME

    def tzname(self, dt):
        return "UTC"

    def dst(self, dt):
        return ZERO_TIME

    def __reduce__(self, *args, **kwargs):
        return UTC, ()

    def __repr__(self):
        return self.__class__.__name__


def ms_timestamp(value):
    if isinstance(value, datetime):
        return int((value - datetime(1970, 1, 1)).total_seconds() * 1000)
    elif isinstance(value, date):
        return int((value - date(1970, 1, 1)).total_seconds() * 1000)
    else:
        raise ValueError(type(value) + ' unsupported')

@@ -988,11 +988,8 @@
 def 
-ms_
 time
@@ -993,16 +993,23 @@
 imestamp
+_micros
 (value):
@@ -1109,32 +1109,35 @@
 seconds() * 1000
+000
 )%0A    elif isins
@@ -1224,16 +1224,19 @@
 ) * 1000
+000
 )%0A    el
@@ -1294,8 +1294,114 @@
 orted')%0A
+%0Adef timestamp_millis(value):%0A    return timestamp_micros(value) // 1000%0A%0Ams_timestamp = timestamp_millis%0A

add datetime/date to micro second resolution