Package: justdays
JustdaysPackage to make working with days and ranges of days in Python super easy.The package contains two classes:Dayhandles everything you want to do with days.Periodhandles a range of Day objects.Current version: 1.8.4Installationpython-mpipinstalljustdaysDay class usageInitializing a Dayday=Day()# No arguments, initalize with the current dayday=Day('2022-08-16')# One argument, string in YYYY-MM-DD formatday=Day(2022,32)# Two arguments: year, week. Day with be the Monday of that weekday=Day(2022,8,16)# Three arguments: year, month, day.day=Day(datetime(2022,8,16))# Initialize with Python datetime objectday=Day(date(2022,8,16))# Initialize with Python date objectAccessing Day fieldsd=day.d# intm=day.m# inty=day.y# intas_string=day.str# in YYYY-MM-DD formatRepresenationstr(day)# Returns the day in YYYY-MM-DD formatday.as_datetime()# Returns the day as a Python datetime objectday.as_date()# Returns the day as a Python date objectday.strftime(format_string)# Returns the day as a string formatted according to the format stringday.as_unix_timestamp()# Returns the day as a unix timestamp (int)Days further away or in the pastday.next()# Next dayday+1# Next day1+day# Next dayday.previous()# Previous dayday-1# Previous dayday.next_weekday()# Next day that is on a weekdayday.previous_weekday()# Previous day that is on a weekdayday.plus_days(3)# Add 3 days to the dayday+3day.plus_days(-3)# Subtract 3 days from the dayday.plus_weeks(1)# Add 1 week to the dayday.plus_months(1)# Add 1 month to the dayComparing daysday1=Day('2022-08-16')day2=Day('2022-08-20')day2>day1# Returns True if day2 is after day1day2==day1# Returns True if day2 is the same day as day1days_difference=day2-day1# Returns the difference in days between two days (4)Miscellaneousday.is_weekend()# Returns True if the day is a weekendday.is_weekday()# Returns True if the day is a weekdayday.day_of_week()# Returns the day of the week as an integer (0 = Monday, 6 = Sunday)day.day_of_year()# Returns the day of the year as an integer (1 = 1st of January, 365 = 31st of December in a non leap year)day.fraction_of_the_year_past()# Returns the fraction of the year that has passed (0.0 = 1st of January, 1.0 = 31st of December)day.week_number()# Returns the week number of the year (1 = first week of the year, 52 = last week of the year)day.last_monday()# Returns the last day that was a Monday or the day itself if it is a Mondayday.last_day_of_month()# Returns the last day of the month of the dayday+' is a nice day'# Add string to a day'The date is '+day# Add string to a dayPeriod class usagePeriod is just a day range. Either fromday or untilday can be left to NoneInitializing a Periodperiod=Period(day1,day2)# Period ranging from day1 (included) until day2 (not included)period=Period(day1)# One argument: fromday. Untilday is left openperiod=Period('2022-08-16','2022-08-20')# Period can be initialized with strings in YYYY-MM-DD formatperiod=Period.from_week(2022,32)# Period ranging from the Monday of week 32 until the Sunday of week 32period=Period.from_month(2022,8)# Period ranging from the 1st of August until the 31st of AugustAccessing Period fieldsfromday=period.fromdayuntilday=period.untildaylength=len(period)Iterating over a Periodfordayinperiod:print(day)Checking if a Day falls within a Periodifdayinperiod:print('yes!')