Skip to content

Commit

Permalink
[AIRFLOW-5664] Store timestamps with microseconds precision (#6354)
Browse files Browse the repository at this point in the history
Microseconds value is lost in the conversion to timestamp
using time.mktime.

Timestamp is now computed to be precise up to microseconds.
  • Loading branch information
osule committed Mar 16, 2020
1 parent 8f417e5 commit 51161db
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion airflow/providers/google/cloud/operators/postgres_to_gcs.py
Expand Up @@ -24,6 +24,8 @@
import time
from decimal import Decimal

import pendulum

from airflow.providers.google.cloud.operators.sql_to_gcs import BaseSQLToGCSOperator
from airflow.providers.postgres.hooks.postgres import PostgresHook
from airflow.utils.decorators import apply_defaults
Expand Down Expand Up @@ -88,7 +90,7 @@ def convert_type(self, value, schema_type):
Decimals are converted to floats. Times are converted to seconds.
"""
if isinstance(value, (datetime.datetime, datetime.date)):
return time.mktime(value.timetuple())
return pendulum.parse(value.isoformat()).float_timestamp
if isinstance(value, datetime.time):
formated_time = time.strptime(str(value), "%H:%M:%S")
return int(datetime.timedelta(
Expand Down

0 comments on commit 51161db

Please sign in to comment.