Saravanan666/pypi-org huggingface dataset:
Package: date-time-event
date-time-eventA very simple package to trigger events at a specific DateTime.InstallationUse the package manager pip to install with the following command:pipinstalldate-time-eventIf you would like to get the latest master or branch from github, you could also:pipinstallgit+https://github.com/Saadmairaj/date-time-eventOr even select a specific revision(branch/tag/commit):pipinstallgit+https://github.com/Saadmairaj/date-time-event@masterUsageIt is very simple and easy to use. First import the class which can be used either as a decorator or a thread function.fromdate_time_eventimportUntiltimeTheUntiltimeclass is threaded based timer which will wait till the given date or timer is met. As it runs on a separate thread, it doesn't effect the main thread or lock it.fromdatetimeimportdatetime,timedeltafromdate_time_eventimportUntiltime# Current datetime with 5 seconds in future.date=datetime.now()+timedelta(0,5)@Untiltime(dateOrtime=date)deffunction():print('Hello! Its time!',datetime.now())function()print('Function will be call at:%s\n'%date)Untiltimedecorator options. Syntax:@Untiltime( **options )OptionsDescriptionfunctionPass Target function.dateOrtimeGive date or time for the function to trigger if None give function will be a threaded function which can only run once. The date, time or datetime should be an instance ofdatetimemodule.nameA string used for identification purposes only. Just like in threadjoinWait until the thread terminates. This blocks the calling thread until the thread whosejoin()method is called terminates.groupReserved for future extension when a ThreadGroup class is implemented.daemonA boolean value indicating whether this thread is a daemon thread (True) or not (False).argsTheargsis the argument tuple for the target invocation. Defaults to ().kwargsThekwargsis a dictionary of keyword arguments for the target invocation. Defaults to {}.TheUntiltimeclass can also be used as thread class. Like sofromdatetimeimportdatetime,timedeltafromdate_time_eventimportUntiltimedeffunction():print('Hello! Its time!',datetime.now())# Current datetime with 5 seconds in future.date=datetime.now()+timedelta(0,5)th=Untiltime(function,dateOrtime=date)th.start()print('Function will be call at:%s\n'%date)Once the thread is called it can be stopped or cancel if called.cancel()method before the datetime event occurs.Set date can be changed with propertydate, if the thread has not started.fromdatetimeimportdatetime,timedeltafromdate_time_eventimportUntiltimedeffunction():print('Hello! Its time!',datetime.now())# Current datetime with 5 seconds in future.date=datetime.now()+timedelta(0,1)th=Untiltime(function,dateOrtime=date)# Initializing new dateth.date=datetime.now()+timedelta(0,5)th.start()print('Function will be call at:%s\n'%th.date)License
Package: datetime-extractor
datetime_extractorThe main intent of this project is to extract mostly all possible timestamps from a given string where date and time written together. It extracts timestaamps in a string format. Later one can convert extracted timestamp to python timestamp using pandas datetime package.How to install the packagepip install datetime-extractorExample1fromdatetime_extractorimportDateTimeExtractorimportpandasaspdimportresamplestring='scala> val xorder= new order(1,"2016-02-22 00:00:00.00",100,"COMPLETED")'DateTimeExtractor(samplestring)Out:['2016-02-22 00:00:00.00']Example2Suppose if one has a dataframe with text column where timestamps written, the above function can be used to create a new column with extracted timestamp strings. One can use below command in this casedata=pd.read_csv('sampledata.csv')data['textcolumn']=data['textcolumn'].fillna('')data['ExtractedTimestamp']=data['textcolumn'].apply(lambdax:DateTimeExtractor(str(x)))
Package: date-time-handler
date-time-handlerRobust date-time formatter with implicit time-zone conversion, wraps datetime and pytzOut of the box solution for quick and easy proto-type buildingUses Python3 standard library time and datetimeRequires pytz and dateutil to be installed:$ pip3 install pytz
    $ pip3 install python-dateutildate_time_handler package contains class DateTimeHandler with methods that convert timestamp format and time-zoneBy default, DateTimeHandler performs timezone-naive timestamp format conversion (handy for quick display formatting)For implicit timezone conversion:set destination tz with kwargtime_zone = 'region/local'at instantiationthen kwargstart_tz = 'region/local'when converting timestamp formatAll methods take 'timestamp' in any format: int/float, tuple/struct, formatted_string, and even datetime objexamplesfor time-zone agnostic format conversion>>> dt_format = DateTimeHandler(date_format = "%Y/%m/%d", clock_format = "%H:%M:%S")
>>> timestring = dt_format.timestring(timestamp)
>>> timetuple = dt_format.timetuple(timestamp)
>>> datestamp = dt_format.datestamp(timestamp)for time-zone conversion, set destination tz at instantiation>>> dt_format = DateTimeHandler(time_zone = 'US/Pacific')

    # specify starting timezone when converting timestamp #
>>> local_timestring = dt_format.timestring(utc_timestamp, start_tz = 'UTC')
>>> local_timetuple = dt_format.timetuple(utc_timestamp, start_tz = 'UTC')so-called 'date' methods return the given timestamp's date @ 00:00:00>>> local_datestring = dt_format.datestring(utc_timestamp, start_tz = 'UTC')
>>> local_datetuple = dt_format.datetuple(utc_timestamp, start_tz = 'UTC')
Package: datetime-helpers
Datetime HelpersA handy collection of datetime utils.InstallInstall and update usingpip.$pipinstall-Udatetime-helpersWhat's available?importdatetime_helpers# Given a datetime:>>>dt=datetime.date(2017,4,17)# Check the day of week>>>datetime_helpers.get_day_of_week(dt=dt)'Monday'# Check if it is a weekend>>>datetime_helpers.is_weekend(dt=dt)False# Check if it is a weekday>>>datetime_helpers.is_weekday(dt=dt)True# Get the previous business day>>>datetime_helpers.get_previous_business_day(dt=dt)datetime.date(2017,4,14)# Get the next business day>>>datetime_helpers.get_next_business_day(dt=dt)datetime.date(2017,4,18)# Get the first business day of the month>>>datetime_helpers.get_first_business_day_of_month(dt=dt)datetime.date(2017,4,3)# Get the nth business day of the month>>>n=3# e.g. third business day>>>datetime_helpers.get_nth_business_day_of_month(dt=dt,n=n)datetime.date(2017,4,5)# Convert to a datetime string with custom format (defaults to JSON date format)>>>datetime_helpers.datetime_to_string(dt=dt)'2017-04-17T00:00:00.000000Z'# Convert to a date string with custom format (defaults to YYYY-MM-DD)>>>datetime_helpers.date_to_string(dt=dt)'2017-04-17'# Convert a string with custom format to datetime (defaults to JSON date format)>>>text='2016-04-17T00:00:00.000000Z'>>>datetime_helpers.datetime_from_string(text=text)datetime.datetime(2016,4,17,0,0)# Convert a string with custom format to datetime (defaults to JSON date format)>>>text='2016-04-17T00:00:00.000000Z'>>>datetime_helpers.datetime_from_string(text=text)datetime.datetime(2016,4,17,0,0)# Convert a windows filetime to datetime>>>windows_filetime=116444736000000000>>>datetime_helpers.datetime_from_windows_filetime(windows_filetime=windows_filetime)datetime.datetime(1970,1,1,0,0)# Convert to seconds>>>datetime_helpers.datetime_to_seconds(dt=dt)1492387200.0# Convert seconds to datetime>>>seconds=1492387200>>>datetime_helpers.datetime_from_seconds(seconds=seconds)datetime.datetime(2017,4,17,0,0)# Convert to millis>>>datetime_helpers.datetime_to_millis(dt=dt)1492387200000# Convert millis to datetime>>>millis=1492387200000>>>datetime_helpers.datetime_from_millis(millis=millis)datetime.datetime(2017,4,17,0,0)# Convert date to datetime>>>datetime_helpers.datetime_from_date(dt=dt)datetime.datetime(2017,4,17,0,0)ContributingContributions are welcome via pull requests.First time setup$gitclonegit@github.com:DeveloperRSquared/datetime-helpers.git
$cddatetime-helpers
$poetryinstall
$poetryshellTools including black, mypy etc. will run automatically if you installpre-commitusing the instructions below$pre-commitinstall
$pre-commitrun--all-filesRunning tests$poetryrunpytestLinksSource Code:https://github.com/DeveloperRSquared/datetime-helpers/PyPI Releases:https://pypi.org/project/datetime-helpers/Issue Tracker:https://github.com/DeveloperRSquared/datetime-helpers/issues/
Package: datetime-interval
The builtindatetimemodule provides classes for points in time
(date, anddatetime) as well as durations (timedelta), but
it does not account for time durations at a specific point. This module
providesInterval, which contains a start and enddateordatetime, and a durationtimedelta. This is useful for
representing calendar events. This module also providesPeriodicIntervalwhich can be used for recurring events, by
containing a periodtimedeltaand a count of occurrences (either anintorforever).TODO:Intervalisoformatmethod (start/end).This wouldn’t work on PeriodicInterval, as recurring intervals
have a different semantics in ISO 8601.Property-based testing withpropsAdd operators for PeriodicInterval (*, [])How to account for e.g. every Tuesday and Thursday
Package: datetime-itertool
datetime-itertoolSimple datetime iteratorFeaturesFully typed with annotations and checked with mypy,PEP561 compatibleInstallationpipinstalldatetime-itertoolExampleShowcase how your project can be used:importdatetimefromdatetime_itertool.datetime_iteratorimportDateTimeIteratorstart=datetime.datetime(2022,2,7)end=datetime.datetime(2022,2,10)fordate_timeinDateTimeIterator(start,end):print(date_time)# 2022-02-07 00:00:00# 2022-02-08 00:00:00# 2022-02-09 00:00:00LicenseMITCreditsThis project was generated withwemake-python-package. Current template version is:5fe13ee2646d5cf38736bacfa8f9dbbfac092efb. See what isupdatedsince then.
Package: datetimejp
和暦変換ライブラリ DatetimeJp概要DatetimeJp は西暦と和暦の変換処理を提供します。
主な機能として、次のような拡張機能を実装しています。和暦表示の文字列を構文解析し、datetime.datetime のサブクラスオブジェクトを生成する。西暦の日付情報を入力して和暦変換オブジェクトを生成し、和暦表示の文字列を出力する。加えて、本ライブラリは標準ライブラリdatetimeの datetime クラスを継承した構成となっており、datetime と同様の日付操作を行うことが可能です。利用方法本ライブラリの主な機能は datetime クラスの strptime 関数および strptime 関数を拡張する形で提供されています。これらの関数で拡張された書式化指定子は次のとおりです。書式化指定子意味使用例%g元号を日本語表記で表示します。明治, 大正, 昭和, 平成, 令和%-g, %#g元号を1文字のローマ字表記で表示します。M, T, S, H, R%e0埋めした10進数で表記した年度を表します。01, 02, ..., 99%-e, %#e0埋めしない10進数で表記した年度を表します。1, 2, ..., 99本ライブラリで提供する拡張機能の他に、標準ライブラリ datetime で指定可能な書式化指定子を使用できます。
詳細は公式ドキュメント
「strftime() と strptime() の書式コード」
を参照してください。サンプルコード西暦から和暦への変換以下の例では西暦2020年2月2日の日付オブジェクトを生成し、'令和02年02月02日'という文字情報に変換します。from datetimejp import JDate
jd = JDate(2020,2,2)
result = jd.strftime('%g%e年%m月%d日')
print(result) # -> '令和02年02月02日'和暦から西暦への変換以下の例では'令和1年5月1日'という文字情報を解析して日付オブジェクトを生成します。
その後、'20190501' という文字列に変換します。from datetimejp import JDate
jd = JDate.strptime('令和1年5月1日', '%g%e年%m月%d日')
result = jd.strftime('%Y%m%d')
print(result) # -> '20190501'注意点本ライブラリには過去の和暦情報が保持されています。
改元が行われた際には和暦の情報が古くなり、新しい元号の情報を追加する必要があります。また、本ライブラリが保持している最も古い和暦情報は明治1年（西暦1868年）となっており、それ以前の和暦変換には対応していません。ライセンスMIT LicenseCopyright (c) 2023 宇宮間そら以下に定める条件に従い、本ソフトウェアおよび関連文書のファイル（以下「ソフトウェア」）の複製を取得するすべての人に対し、ソフトウェアを無制限に扱うことを無償で許可します。これには、ソフトウェアの複製を使用、複写、変更、結合、掲載、頒布、サブライセンス、および/または販売する権利、およびソフトウェアを提供する相手に同じことを許可する権利も無制限に含まれます。上記の著作権表示および本許諾表示を、ソフトウェアのすべての複製または重要な部分に記載するものとします。ソフトウェアは「現状のまま」で、明示であるか暗黙であるかを問わず、何らの保証もなく提供されます。ここでいう保証とは、商品性、特定の目的への適合性、および権利非侵害についての保証も含みますが、それに限定されるものではありません。 作者または著作権者は、契約行為、不法行為、またはそれ以外であろうと、ソフトウェアに起因または関連し、あるいはソフトウェアの使用またはその他の扱いによって生じる一切の請求、損害、その他の義務について何らの責任も負わないものとします。This software is released under the MIT License.http://opensource.org/licenses/mit-license.php
Package: datetimejson
Datetime JSONSerialize and deserialize datetime objects to and from JSON.This package provides:4 functions that wrap the corresponding functions of thejsonmodule:load/loads- Deserialize a JSON string containing datetime objectsdump/dumps- Serialize python object containting datetime objects to JSONtwo classes derived respectively fromjson.JSONEncoderandjson.JSONDecoder:DateTimeEncoder- Serialize a datetime object to JSONDateTimeDecoder- Deserialize a JSON string to a datetime objectInstallationpipinstalldatetimejsonUsageJust replacejsonimport bydatetimejsonin your code:>>>fromdatetimejsonimportdumps,loads>>>fromdatetimeimportdatetime>>>now=datetime.now()>>>print(now)2023-02-1311:27:56.687439>>>json_string=dumps(now)>>>print(json_string){"__type__":"datetime","year":2023,"month":2,"day":13,"hour":11,"minute":27,"second":56,"microsecond":687439}>>>print(loads(json_string))2023-02-1311:27:56.687439>>>Original code by@ApptuitAI:https://gist.github.com/abhinav-upadhyay/5300137
Package: datetime-month
monthA package that handles calendar months and arithmetic operation of months.The package comprises two modules:monthandx_month.monthmodule provides the base classes for manipulating month-level time.x_monthmodule extends the base classes from themonthmodule to include additional functionalities.Installationpip install datetime-monthFeatures & UsageTo construct a month object:frommonthimportMonthfrommonthimportXMonth# extended month;m=Month(2020,4)xm=XMonth(2020,4)Additional construction methods below can be used to translate atuple(year, month), aisoformatstring,
anordinalint andmonth-formatstring into aMonthobject.# constructed from a (year, month) tuple:m=Month.fromtuple((2019,11))# isoformat is defined as a str in "year-month" format:m=Month.fromisoformat('2019-12')# ordinal (as in date units):m=Month.fromordinal(737390)# using string format like datetime:m=Month.strptime('2019/1','%Y/%m')For the representation of the difference between two months, we can useMdelta(similar totimedeltain datetime modules). To construct:frommonthimportMDeltadelta=Mdelta(2)# Mdelta(months), months: int;Mdeltasupports comparisons using operators. It also supports some arithmetic operations (addition, subtraction, and multiplication)
among Mdelta objects or with Month objects or int objects.Mdelta(2)<Mdelta(3)# returns bool;Mdelta(2)-Mdelta(3)# returns Mdelta(-1);Mdelta(2)*2# returns Mdelta(4);Some arithmetic operations and comparisons are also supported forMonthobjects.Month(2019,11).add(MDelta(2))# returns Month(2020, 1);Month(2020,04)+Mdelta(2)# returns Month(2020, 6);Month(2020,1)-2# returns Month(2019, 11);Month(2020,04)<=Month(2020,06)# returns True;XMonthis an extended version ofMonthby including some convenient manipulation and sub-level operations.xm=XMonth(2019,11)xm.days()# returns total days in the month;xm.first_date()# returns date(2019,11,1)# iterate dates within the month in increment by step days:xm.dates(step=2)# iterate months in a given range:XMonth.range(starting_month,ending_month,step=1)LicenseFree software: MIT licenseCreditsThe repo was initiated usingaudreyr/cookiecutter-pypackageproject template.History0.1.0 (2020-03-21)First release on PyPI.1.0.3 (2022-10-11)FIX:Fix wrong package metadata in setup -#2.1.0.4 (2022-11-10)FIX:Fix arithmetic operation on XMonth returning base class Month object instead of XMonth  -#8. Contributed by@ramwin. Thank you!1.0.5 (2024-02-15)Add compatibility with Python 3.11 & 3.12.1.0.6 (2024-02-15)Fix ReadMe note.
Package: datetime-parser
datetime-parserdatetime can be many different formats and often we want to express a time relative
to the current time, such as10 minutes ago. This module is able to handle all datetime formats
as well as our custom relative time format.Relative datetime format:For the current time:
    now
Any other time:
    (+/-)(integer) (milliseconds|seconds|minutes|days|weeks|months|years)
    
examples:
    now
    -1 months
    +3 days
    -123 secondsParse DatetimeTo parse a datetime (not including relative time), you can use thetry_parse_dtfunction. This
will return a pendulum objectfromdatetime_parserimporttry_parse_dtexample="2020-02-02 10:10:10"example_obj=try_parse_datetime(example)Parse Relavite TimeTo parse a datetime or relative datetime, useis_datetime.fromdatetime_parserimportis_datetimeexample="-5 minutes"example_obj=is_datetime(example)
Package: datetime_periods
This module aims to help you create time periods from timestamps.Pass in adatetime.datetime()object and a period name and it’ll
return the beginning and end of that period.Documentation available onRead the Docs.Installation:You can install from PyPi!pip install datetime_periodsperiodusagePass in adatetime.datetime()object and a period name and it’ll
return the beginning and end of that period.>>> from datetime_periods import period
>>> period(datetime(2012, 4, 2, second=12), 'minute')
[datetime(2012, 4, 2), datetime(2012, 4, 2, 0, 0, 59)]
>>> period(datetime(2012, 4, 2), 'hour')
[datetime(2012, 4, 2, 0), datetime(2012, 4, 2, 0, 59, 59)]
>>> period(datetime(2012, 4, 2), 'day')
[datetime(2012, 4, 2), datetime(2012, 4, 2, 23, 59, 59)]
>>> period(datetime(2012, 4, 2), 'week')
[datetime(2012, 4, 2), datetime(2012, 4, 8, 23, 59, 59)]
>>> period(datetime(2012, 4, 15), 'month')
[datetime(2012, 4, 1), datetime(2012, 4, 30, 23, 59, 59)]
>>> period(datetime(2012, 4, 2), 'quarter')
[datetime(2012, 4, 1), datetime(2012, 6, 30, 23, 59, 59)]
>>> period(datetime(2012, 9, 1), 'half_year')
[datetime(2012, 7, 1), datetime(2012, 12, 31, 23, 59, 59)]
>>> period(datetime(2012, 7, 1), 'year')
[datetime(2012, 1, 1), datetime(2012, 12, 31, 23, 59, 59)]TimeRangeusageTheTimeRangeclass takes two times,startandstop, and createsdatetimeobjects from them that is smart about when a date should
roll over to the following day.This class can also act like a 2 length list where index 0=start,
1=stop time. This to allow the class to be used for argument
expansion and as an iterator.>>> from datetime_periods import TimeRange
>>> tr = TimeRange('17:00', '23:00', '2013-12-25')
>>> tr.start
datetime(2013, 12, 25, 17)
>>> tr.stop
datetime(2013, 12, 25, 23)
>>> tr = TimeRange('17:00', '04:00', '2013-12-25')
>>> tr.start
datetime(2013, 12, 25, 17)
>>> tr.stop
datetime(2013, 12, 26, 4)
>>> tr[0] == tr.start
True
>>> tr[1] == tr.stop
TrueSugarThesugarmodule has sugar functions for all variants available.Sugar functions for entire period:period_secondperiod_minuteperiod_hourperiod_dayperiod_weekperiod_monthperiod_quarterperiod_half_yearperiod_yearSugar functions for beginning of period:period_beginning_secondperiod_beginning_minuteperiod_beginning_hourperiod_beginning_dayperiod_beginning_weekperiod_beginning_monthperiod_beginning_quarterperiod_beginning_half_yearperiod_beginning_yearSugar functions for end of period:period_end_secondperiod_end_minuteperiod_end_hourperiod_end_dayperiod_end_weekperiod_end_monthperiod_end_quarterperiod_end_half_yearperiod_end_year
Package: datetime-quarter
datetime-quarterSimple quarter support for pythondatetime.dateSetupInstall via pip (pip install datetime-quarter)or via git (git clone "https://github.com/BetaS/datetime-quarter")Check availability in your project like belowfromdatequarterimportDateQuartersample=DateQuarter(2019,4)print(sample)# 2019 4QOperations1. Creationitem = DateQuarter(2019, 4)  # 2019 4Qitem = DateQuarter(2018, 8)  # 2019 4Qfor convinienceitem = DateQuarter.from_date(datetime.date(2019, 12, 31))  # 2019 4Q2. Adding or sub quarterDateQuarter(2019, 4)+1  # 2020 1QDateQuarter(2019, 4)-4  # 2018 4Q3. Getting distanceDateQuarter(2019, 4) - DateQuarter(2019, 1)  # 3QDateQuarter(2019, 1) - DateQuarter(2019, 4)  # -3Q4. Comparison ofDateQuarterDateQuarter(2019, 1) > DateQuarter(2019, 4)  # FalseDateQuarter(2019, 1) < DateQuarter(2019, 4)  # TrueDateQuarter(2019, 1) == DateQuarter(2019, 4)  # FalseDateQuarter(2019, 1) != DateQuarter(2019, 4)  # Truealso support>=and<=5. Comparison ofdatetime.datedatetime.date(2019, 12, 31) in DateQuarter(2019, 1)  # Falsedatetime.date(2019, 12, 31) in DateQuarter(2019, 4)  # Truealso support>,>=and vice versa6. Getting start and end dateDateQuarter(2019, 1).start_date()  # datetime.date(2019, 1, 1)DateQuarter(2019, 1).end_date()  # datetime.date(2019, 3, 31)7. Iterate over containing datequarter=DateQuarter(2019,1)fordayinquarter.days():print(day)# [datetime.date(2019, 1, 1), ..., datetime.date(2019, 3, 31)]8. Iterate betweenDateQuarterstart=DateQuarter(2019,1)end=DateQuarter(2019,4)forquarterinDateQuarter.between(start,end):print(quarter)# [DateQuarter(2019, 1), DateQuarter(2019, 2) , DateQuarter(2019,3)]also it support reversed case
Package: datetime-selenium
Datetime-Selenium allows you to send/retrievedatetime.datetimeobjects to/from web forms usingSelenium.Installation$ pip install datetime-seleniumQuickstartFirst, clone an example file from the Datetime-Selenium repo.$curlhttps://raw.githubusercontent.com/dsbowen/datetime-selenium/master/form.html--outputform.htmlLet's send the current date and time to all input in the form.fromdatetime_seleniumimportsend_datetimefromselenium.webdriverimportChromefromdatetimeimportdatetimedriver=Chrome()driver.get('data:text/html,'+open('form.html').read())datetime_=datetime.utcnow()css_selectors=('input[type=date]','input[type=datetime-local]','input[type=month]','input[type=time]','input[type=week]')forselectorincss_selectors:input_=driver.find_element_by_css_selector(selector)send_datetime(input_,datetime_)You'll see the form filled in in your selenium browser.Citation@software{bowen2020datetime-selenium,
  author = {Dillon Bowen},
  title = {Datetime-Selenium},
  url = {https://dsbowen.github.io/datetime-selenium/},
  date = {2020-06-29},
}LicenseUsers must cite this package in any publications which use it.It is licensed with the MITLicense.
Package: datetime-truncate
This module truncates a datetime object to the level of precision that
you specify, making everything higher than that zero (or one for day
and month).It is based on PostgreSQL’sDATE_TRUNC.Documentation available onRead the Docs.Installation:You can install from pypi!pip install datetime_truncateUsage:>>> from datetime_truncate import truncate
>>> truncate(datetime(2012, 2, 4, 12, 24, 50, 234), 'second')
datetime(2012, 2, 4, 12, 24, 50)
>>> truncate(datetime(2012, 2, 4, 12, 24, 50), 'minute')
datetime(2012, 2, 4, 12, 24)
>>> truncate(datetime(2012, 2, 4, 12, 24), 'hour')
datetime(2012, 2, 4, 12)
>>> truncate(datetime(2012, 2, 4, 12, 24), 'day')
datetime(2012, 2, 4)
>>> truncate(datetime(2012, 2, 4, 12, 24), 'week')
datetime(2012, 1, 30)
>>> truncate(datetime(2012, 2, 4, 12, 24), 'month')
datetime(2012, 2, 1)
>>> truncate(datetime(2012, 2, 4, 12, 24), 'quarter')
datetime(2012, 1, 1)
>>> truncate(datetime(2012, 8, 18, 12, 25), 'half_year')
datetime(2012, 7, 1)
>>> truncate(datetime(2012, 8, 18, 12, 25), 'year')
datetime(2012, 1, 1)There are also sugar functions available on the form:truncate_secondtruncate_minutetruncate_hourtruncate_daytruncate_weektruncate_monthtruncate_quartertruncate_half_yeartruncate_year