-
-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Inline API documentation + ModuleType refactoring #133
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
…ry within the scope of a context manager
Codecov ReportAll modified lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## master #133 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 8 8
Lines 549 568 +19
=========================================
+ Hits 549 568 +19
☔ View full report in Codecov by Sentry. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Inline API documentation
NAME
utcnow
- Package for formatting arbitrary timestamps as strict RFC 3339.DESCRIPTION
Timestamps as RFC 3339 (Date & Time on the Internet) formatted strings with conversion functionality from other timestamp formats or for timestamps on other timezones. Additionally converts timestamps from datetime objects and other common date utilities.
value
— A value representing a timestamp in any of the allowed input formats, or "now" if left unset.modifier
— An optional modifier to be added to the Unix timestamp of the value. Defaults to 0. Can be specified in seconds (int or float) or as string, for example "+10d" (10 days => 864000 seconds). Can also be set to a negative value, for example "-1h" (1 hour => -3600 seconds).Examples:
A few examples of transforming an arbitrary timestamp value to a RFC 3339 timestamp string.
Returned timestamps follow RFC 3339 (Date and Time on the Internet: Timestamps): https://tools.ietf.org/html/rfc3339.
Timestamps are converted to UTC timezone which we'll note in the timestamp with the "Z" syntax instead of the also accepted "+00:00". "Z" stands for UTC+0 or "Zulu time" and refers to the zone description of zero hours.
Timestamps are expressed as a date-time (not a Python datetime object), including the full date (the "T" between the date and the time is optional in RFC 3339 (but not in ISO 8601) and usually describes the beginning of the time part.
Timestamps are 27 characters long in the format: "YYYY-MM-DDTHH:mm:ss.ffffffZ". 4 digit year, 2 digit month, 2 digit days, "T", 2 digit hours, 2 digit minutes, 2 digit seconds, 6 fractional second digits (microseconds -> nanoseconds), followed by the timezone identifier for UTC: "Z".
The library is specified to return timestamps with 6 fractional second digits, which means timestamps down to the microsecond level. Having a six-digit fraction of a second is currently the most common way that timestamps are shown at this date.
See also:
Precision in
modifier
andutcnow.timediff
Added modifier and timediff support for milliseconds, microseconds and nanoseconds (although nanosecond precision will currently not use native nanoseconds, and will return microseconds * 1000).
Common modifier multipliers:
Precision modifier multiplicers (new):
Deprecation warnings
Added deprecation warnings to all other non-standard transformation functions (that will still work for the time being) – for example
utcnow.as_str
,utcnow.get_unixtime
orutcnow.datetime
, etc.Refactoring
Major refactoring of the library to actually use a
ModuleType
instead of creating a class object (that was used as a faked module) when importingutcnow
.Previously
After refactoring
Freeze the current time in
utcnow
withutcnow.synchronizer
There's a context manager available at
utcnow.synchronizer
to freeze the current time ofutcnow
to a specific value of your choice or to the current time when entering the context manager.This has been added to accomodate for the use-case of needing to fetch the current time in different places as part of a call chain, where it's also either difficult or you're unable to pass the initial timestamp value as an argument down the chain, but you want to receive the exact same timestamp from
utcnow
to be returned for each call, although some microseconds would have passed since last call.The
utcnow.synchronizer(value, modifier)
can also be initialized with a specific timestamp value to freeze the current time to, instead of the current time when entering the context manager. The same kind of arguments as forutcnow.rfc3339_timestamp()
(utcnow.get()
) can be used also forutcnow.synchronizer
.An example of how
utcnow.synchronizer
can be used to freeze the creation time of an object and its childrenA common use-case for
utcnow.synchronizer
is to freeze the creation time of an object and its children, for example when creating a bunch of objects in a chunk, if we are expected to apply the exact same creation time of all objects in the chunk using the same value.SomeModel
is a simple class that storescreated_at
when the object is initiated. Objects of the type may also contain a list ofitems
, which in pratice is children of the same type. If creating a parentSomeModel
object with two children stored to itsitems
list all together in a chunk (for example as part of a storage API request), we may want to use the same timestamp for all three objects (the parent and the children).It's not possible to chain
utcnow.synchronizer
context managers to freeze the current time to different values at different points in the call chain. If autcnow.synchronizer
context is already opened a second attempt to create or open a context will result in a raised exception.