Skip to content

Review the datetime helpers in gcloud._helpers. #1732

@rimey

Description

@rimey

gcloud._helpers has accumulated a collection of ~10 helper functions related to datetime handling. These could perhaps use a review to determine if they are all essential and maximally useful.

The particular situation in which this has come up is a proposal to update _datetime_to_rfc3339() to handle time zones as in the following module-private helper function appearing in #1691:

def _format_timestamp(timestamp):
    """Convert a datetime object to a string as required by the API.

    :type timestamp: :class:`datetime.datetime`
    :param timestamp: A datetime object.

    :rtype: string
    :returns: The formatted timestamp. For example:
        ``"2016-02-17T19:18:01.763000Z"``
    """
    if timestamp.tzinfo is not None:
        # Convert to UTC and remove the time zone info.
        timestamp = timestamp.replace(tzinfo=None) - timestamp.utcoffset()

    return timestamp.isoformat() + 'Z'

Metadata

Metadata

Labels

api: corepriority: p2Moderately-important priority. Fix may not be included in next release.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions