When.py Documentation

Similar documents
fiscalyear Documentation

Python Datetime TZ Documentation

It s about time! Aymeric Augustin DjangoCon Europe T16:10:00+02:00

Home Assistant Documentation

Django Timezone Utils Documentation

Date and Time Functions

Functions and Decomposition

LECTURE 8 The Standard Library Part 2

eoddata-client Documentation

prompt Documentation Release Stefan Fischer

PLEAC-Python

AIMMS Function Reference - Time Functions

python-gmaps Documentation

treacle Documentation

Systems Programming/ C and UNIX

python-rapidjson Documentation

Mawens Workflow Helper Tool. Version Mawens Business Solutions 7/25/17

EVE Market Data Structures Documentation

Kron Documentation. Release qtfkwk

ISO8601. Time.ISO8601. Time.ISO8601

MT940 Documentation. Release Rick van Hattem (wolph)

urtc Documentation Release 1.2 Radomir Dopieralski

Genesys Info Mart. date-time Section

python-ipfix Documentation

Python Release September 11, 2014

Package datetimeutils

Date/Time Library for Python. Version 3.1

edeposit.amqp.calibre Release 1.1.4

tolerance Documentation

Package humanize. R topics documented: April 4, Version Title Create Values for Human Consumption

dateutil Documentation

ECE 364 Software Engineering Tools Lab. Lecture 8 Python: Advanced I

MyGeotab Python SDK Documentation

python-samplerate Documentation

Natural Documentation

Math in Focus Vocabulary. Kindergarten

xmodels Documentation

WordEmbeddingLoader Documentation

Pairs and Lists. (cons 1 2) 1 2. (cons 2 nil) 2 nil. Not a well-formed list! 1 > (cdr x) 2 > (cons 1 (cons 2 (cons 3 (cons 4 nil)))) ( ) (Demo)

AIMMS Function Reference - Date Time Related Identifiers

morbo Documentation Release 0.9 Elisha Cook

pglib Documentation Release Michael Kleehammer

pybtsync Documentation

Configuring CDR Search

Working with Time Zones in Oracle Business Intelligence Publisher ORACLE WHITE PAPER JULY 2014

Examination C++ Programming

Swingtime Documentation

Adafruit MicroPython TSL2561 Documentation

ICC. BACnet MS/TP Server Driver Manual INDUSTRIAL CONTROL COMMUNICATIONS, INC Industrial Control Communications, Inc.

CSE : Python Programming. Homework 5 and Projects. Announcements. Course project: Overview. Course Project: Grading criteria

Python-Tempo Documentation

validictory Documentation

petfinder-api Documentation

What's new in Python 2.3

CSC 148 Lecture 3. Dynamic Typing, Scoping, and Namespaces. Recursion

python-periphery Documentation

Day One Export Documentation

Torndb Release 0.3 Aug 30, 2017

Getting Started with Python

Community detection for NetworkX Documentation

DSC 201: Data Analysis & Visualization

dota2api Documentation

tkstuff Documentation

asn1tools Documentation

Table of Contents 1 Basic Configuration Commands 1-1

python-docker-machine Documentation

Exceptions in Python. AMath 483/583 Lecture 27 May 27, Exceptions in Python. Exceptions in Python

PyDriller Documentation

SCoLang - Language Reference Manual

The Year argument can be one to four digits between 1 and Month is a number representing the month of the year between 1 and 12.

EMF Temporality. Jean-Claude Coté Éric Ladouceur

Basic Device Management

PART I SQLAlchemy Core

Information Science 1

picrawler Documentation

Data 100 Lecture 5: Data Cleaning & Exploratory Data Analysis

MIT AITI Python Software Development

tm1640-rpi Documentation

CacheControl Documentation

Data 100. Lecture 5: Data Cleaning & Exploratory Data Analysis

django-openid Documentation

Sir Muhammad Naveed. Arslan Ahmed Shaad ( ) Muhammad Bilal ( )

CMPT 120 Basics of Python. Summer 2012 Instructor: Hassan Khosravi

Fundamentals of Programming (Python) Getting Started with Programming

Announcements. Lab 11 is due tomorrow. Quiz 6 is on Monday. Ninja session tonight, 7-9pm. The final is in two weeks!

Welcome to the Time Zone

WEBplay. User Manual. Version 9.0 Date 2009/09/24. ASC telecom AG - Seibelstr D Hösbach - Germany

DateParser Documentation

SQL Reader User Guide

pyvcd Documentation Release Peter Grayson and Steven Sprouse

TCG 01-G & TCG 02-G Firmware Release Notes

Mathematical Data Operators

edeposit.amqp.antivirus Release 1.0.1

CIS192 Python Programming

Platypus Analytics Documentation

Statsd Metrics Documentation

Constants. Variables, Expressions, and Statements. Variables. x = 12.2 y = 14 x = 100. Chapter

pyshk Documentation Release Jeremy Low

Fundamentals: Expressions and Assignment

IVI-3.18: IVI.NET Utility Classes and Interfaces Specification

Transcription:

When.py Documentation Release 0.4.0 Andy Dirnberger February 27, 2016

Contents 1 Usage 3 2 A note about future and past 9 3 Indices and tables 11 Python Module Index 13 i

ii

When.py provides user-friendly functions to help perform common date and time actions. Contents 1

2 Contents

CHAPTER 1 Usage Friendly Dates and Times when.all_timezones() Get a list of all time zones. This is a wrapper for pytz.all_timezones. Returns list all time zones. when.all_timezones_set() Get a set of all time zones. This is a wrapper for pytz.all_timezones_set. Returns set all time zones. when.common_timezones() Get a list of common time zones. This is a wrapper for pytz.common_timezones. Returns list common time zones. when.common_timezones_set() Get a set of common time zones. This is a wrapper for pytz.common_timezones_set. Returns set common time zones. when.ever() Get a random datetime. Instead of using datetime.minyear and datetime.maxyear as the bounds, the current year +/- 100 is used. The thought behind this is that years that are too extreme will not be as useful. Returns datetime.datetime a random datetime. New in version 0.3.0. when.format(value, format_string) Get a formatted version of a datetime. This is a wrapper for strftime(). The full list of directives that can be used can be found at http://docs.python.org/library/datetime.html#strftime-strptime-behavior. Predefined formats are exposed through when.formats: when.formats.date Date in locale-based format. 3

when.formats.datetime Date and time in locale-based format. when.formats.time Time in locale-based format. when.formats.time_ampm 12-hour time in locale-based format. Parameters value (datetime.datetime, datetime.date, datetime.time.) datetime object. format_string (str.) A string specifying formatting the directives or to use. Returns str the formatted datetime. Raises TypeError A Changed in version 0.4.0: TypeError is now raised New in version 0.3.0. when.future(years=0, months=0, weeks=0, days=0, hours=0, minutes=0, seconds=0, milliseconds=0, microseconds=0, utc=false) Get a datetime in the future. future() accepts the all of the parameters of datetime.timedelta, plus includes the parameters years and months. years and months will add their respective units of time to the datetime. By default future() will return the datetime in the system s local time. If the utc parameter is set to True or set_utc() has been called, the datetime will be based on UTC instead. Parameters years (int.) The number of years to add. months (int.) The number of months to add. weeks (int.) The number of weeks to add. days (int.) The number of days to add. hours (int.) The number of hours to add. minutes (int.) The number of minutes to add. seconds (int.) The number of seconds to add. milliseconds (int.) The number of milliseconds to add. microseconds (int.) The number of microseconds to add. utc (bool.) Whether or not to use UTC instead of local time. Returns datetime.datetime the calculated datetime. when.how_many_leap_days(from_date, to_date) Get the number of leap days between two dates Parameters from_date (datetime.datetime, datetime.date) A datetime object. If only a year is specified, will use January 1. 4 Chapter 1. Usage

to_date (datetime.datetime, datetime.date) A datetime object.. If only a year is specified, will use January 1. Returns int the number of leap days. Raises TypeError, ValueError Changed in version 0.4.0: TypeError is now raised ValueError is now raised New in version 0.3.0. when.is_timezone_aware(value) Check if a datetime is time zone aware. is_timezone_aware() is the inverse of is_timezone_naive(). Parameters value (datetime.datetime, datetime.time) A valid datetime object. Returns bool if the object is time zone aware. Raises TypeError Changed in version 0.4.0: TypeError is raised New in version 0.3.0. when.is_timezone_naive(value) Check if a datetime is time zone naive. is_timezone_naive() is the inverse of is_timezone_aware(). Parameters value (datetime.datetime, datetime.time) A valid datetime object. Returns bool if the object is time zone naive. Raises TypeError Changed in version 0.4.0: TypeError is now raised New in version 0.3.0. when.now(utc=false) Get a datetime representing the current date and time. By default now() will return the datetime in the system s local time. If the utc parameter is set to True or set_utc() has been called, the datetime will be based on UTC instead. Parameters utc (bool.) Whether or not to use UTC instead of local time. Returns datetime.datetime the current datetime. when.past(years=0, months=0, weeks=0, days=0, hours=0, minutes=0, seconds=0, milliseconds=0, microseconds=0, utc=false) Get a datetime in the past. past() accepts the all of the parameters of datetime.timedelta, plus includes the parameters years and months. years and months will add their respective units of time to the datetime. By default past() will return the datetime in the system s local time. If the utc parameter is set to True or set_utc() has been called, the datetime will be based on UTC instead. Parameters years (int.) The number of years to subtract. months (int.) The number of months to subtract. weeks (int.) The number of weeks to subtract. 5

days (int.) The number of days to subtract. hours (int.) The number of hours to subtract. minutes (int.) The number of minutes to subtract. seconds (int.) The number of seconds to subtract. milliseconds (int.) The number of milliseconds to subtract. microseconds (int.) The number of microseconds to subtract. utc (bool.) Whether or not to use UTC instead of local time. Returns datetime.datetime the calculated datetime. when.set_utc() Set all datetimes to UTC. The utc parameter of other methods will be ignored, with the global setting taking precedence. This can be reset by calling unset_utc(). when.shift(value, from_tz=none, to_tz=none, utc=false) Convert a datetime from one time zone to another. value will be converted from its time zone (when it is time zone aware) or the time zone specified by from_tz (when it is time zone naive) to the time zone specified by to_tz. These values can either be strings containing the name of the time zone (see pytz.all_timezones for a list of all supported values) or a datetime.tzinfo object. If no value is provided for either from_tz (when value is time zone naive) or to_tz, the current system time zone will be used. If the utc parameter is set to True or set_utc() has been called, however, UTC will be used instead. Parameters value (datetime.datetime, datetime.time.) A datetime object. from_tz (datetime.tzinfo, str.) The time zone to shift from. to_tz (datetime.tzinfo, str.) The time zone to shift to. utc (bool.) Whether or not to use UTC instead of local time. Returns datetime.datetime the calculated datetime. Raises TypeError Changed in version 0.4.0: TypeError is now raised when.timezone() Get the name of the current system time zone. Returns str the name of the system time zone. when.timezone_object(tz_name=none) Get the current system time zone. Parameters tz_name (str.) The name of the time zone. Returns datetime.tzinfo the time zone, defaults to system time zone. when.today() Get a date representing the current date. Returns datetime.date the current date. 6 Chapter 1. Usage

when.tomorrow() Get a date representing tomorrow s date. Returns datetime.date the current date plus one day. when.unset_utc() Set all datetimes to system time. The utc parameter of other methods will be used. This can be changed by calling set_utc(). when.yesterday() Get a date representing yesterday s date. Returns datetime.date the current date minus one day. 7

8 Chapter 1. Usage

CHAPTER 2 A note about future and past When changing a datetime from one month (or year) to another, it is often the case that the new month will have fewer days than the original, resulting in an invalid date. When this happens, the days will be adjusted into the future. This is consistent with implementations found elsewhere. >>> when.today() datetime.date(2012, 2, 29) >>> >>> when.future(years=1) datetime.datetime(2013, 3, 1, 19, 0, 23, 76878) >>> when.today() datetime.date(2012, 3, 31) >>> >>> when.past(months=1) datetime.datetime(2012, 3, 2, 19, 7, 36, 317653) 9

10 Chapter 2. A note about future and past

CHAPTER 3 Indices and tables genindex modindex search 11

12 Chapter 3. Indices and tables

Python Module Index w when, 3 13

14 Python Module Index

Index A all_timezones() (in module when), 3 all_timezones_set() (in module when), 3 C common_timezones() (in module when), 3 common_timezones_set() (in module when), 3 E ever() (in module when), 3 F format() (in module when), 3 future() (in module when), 4 H how_many_leap_days() (in module when), 4 I is_timezone_aware() (in module when), 5 is_timezone_naive() (in module when), 5 N now() (in module when), 5 P past() (in module when), 5 S set_utc() (in module when), 6 shift() (in module when), 6 T timezone() (in module when), 6 timezone_object() (in module when), 6 today() (in module when), 6 tomorrow() (in module when), 6 U unset_utc() (in module when), 7 W when (module), 3 when.formats.date (in module when), 3 when.formats.datetime (in module when), 3 when.formats.time (in module when), 4 when.formats.time_ampm (in module when), 4 Y yesterday() (in module when), 7 15