Package s3 :: Module s3datetime
[frames] | no frames]

Module s3datetime

source code

S3 Date/Time Toolkit


Copyright: 2015-2019 (c) Sahana Software Foundation

License: MIT

Requires: gluon

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Classes
  S3DateTime
Toolkit for date+time parsing/representation
  S3Calendar
Calendar Base Class (implementing the Gregorian Calendar)
  S3DateTimeParser
Date/Time Parser for non-Gregorian calendars
  S3DateTimeFormatter
Date/Time Formatter for non-Gregorian calendars
Functions
 
s3_parse_datetime(string, dtfmt=None)
Parse a date/time string according to the given format.
source code
 
s3_format_datetime(dt=None, dtfmt=None)
Format a datetime object according to the given format.
source code
 
s3_decode_iso_datetime(dtstr)
Convert date/time string in ISO-8601 format into a datetime object
source code
 
s3_encode_iso_datetime(dt)
Convert a datetime object into a ISO-8601 formatted string, omitting microseconds
source code
 
s3_utc(dt)
Get a datetime object for the same date/time as the datetime object, but in UTC
source code
 
s3_get_utc_offset()
Get the current UTC offset for the client
source code
 
s3_relative_datetime(dtexpr)
Return an absolute datetime for a relative date/time expression;
source code
Variables
  ISOFORMAT = "%Y-%m-%dT%H:%M:%S"
ISO 8601 Combined Date+Time format
Function Details

s3_parse_datetime(string, dtfmt=None)

source code 

Parse a date/time string according to the given format.

Parameters:
  • string - the string
  • dtfmt - the string format (defaults to ISOFORMAT)
Returns:
a datetime object, or None if the string is invalid

s3_format_datetime(dt=None, dtfmt=None)

source code 

Format a datetime object according to the given format.

Parameters:
  • dt - the datetime object, defaults to datetime.datetime.utcnow()
  • dtfmt - the string format (defaults to ISOFORMAT)
Returns:
a string

s3_decode_iso_datetime(dtstr)

source code 

Convert date/time string in ISO-8601 format into a datetime object

Parameters:
  • dtstr - the date/time string
Returns:
a timezone-aware datetime.datetime object

Note: this has "iso" in its name for consistency reasons, but can actually read a variety of formats

s3_encode_iso_datetime(dt)

source code 

Convert a datetime object into a ISO-8601 formatted string, omitting microseconds

Parameters:
  • dt - the datetime object

s3_utc(dt)

source code 

Get a datetime object for the same date/time as the datetime object, but in UTC

Parameters:
  • dt - the datetime object

s3_get_utc_offset()

source code 

Get the current UTC offset for the client

s3_relative_datetime(dtexpr)

source code 

Return an absolute datetime for a relative date/time expression;

Parameters:
  • dtexpr - the relative date/time expression, syntax: "[+|-][numeric][Y|M|D|h|m|s]", e.g. "+12M" = twelve months from now, additionally recognizes the string "NOW"
Returns:
datetime.datetime (UTC), or None if dtexpr is invalid

Variables Details

ISOFORMAT

ISO 8601 Combined Date+Time format

Value:
"%Y-%m-%dT%H:%M:%S"