Utils

Many Things

ls.joyous.utils.manythings.hrJoin(items)[source]

Joins items together in a human readable string e.g. ‘wind, ice and fire’

ls.joyous.utils.manythings.toOrdinal(n)[source]

Returns the ordinal name of a number e.g. ‘first’

ls.joyous.utils.manythings.toTheOrdinal(n, inTitleCase=True)[source]

Returns the definite article with the ordinal name of a number e.g. ‘the second’ Becomes important for languages with multiple definite articles (e.g. French)

Mix-ins

class ls.joyous.utils.mixins.ProxyPageMixin(*args, **kwargs)[source]

Adding this mixin allows inheritance without needing a new table. The proxy model has its own content type which allows it to be selected as a separate page type in the Wagtail admin interface. No change is made to the manager, but peers() will return a queryset of others of the same type. See also https://github.com/wagtail/wagtail/pull/1736

classmethod peers()[source]

Return others of the same type

Names

ls.joyous.utils.names.MONDAY_TO_SUNDAY = ('Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday', 'Sunday')

Names of days of the week, from Monday to Sunday

ls.joyous.utils.names.MONTH_ABBRS = ('', 'Jan.', 'Feb.', 'March', 'April', 'May', 'June', 'July', 'Aug.', 'Sept.', 'Oct.', 'Nov.', 'Dec.')

Abbreviations of the months, with Jan at index 1

ls.joyous.utils.names.MONTH_NAMES = ('', 'January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December')

Names of the months, with January at index 1

ls.joyous.utils.names.MON_TO_SUN = ('Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun')

Abbreviations of days of the week, from Mon to Sun

ls.joyous.utils.names.SUNDAY_TO_SATURDAY = ('Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday')

Names of days of the week, from Sunday to Saturday

ls.joyous.utils.names.SUN_TO_SAT = ('Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat')

Abbreviations of days of the week, from Sun to Sat

ls.joyous.utils.names.WEEKDAY_ABBRS = ('Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun')

Abbreviations of days of the week, from Mon to Sun

ls.joyous.utils.names.WEEKDAY_NAMES = ('Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday', 'Sunday')

Names of days of the week, from Monday to Sunday

ls.joyous.utils.names.WEEKDAY_NAMES_PLURAL = ('Mondays', 'Tuesdays', 'Wednesdays', 'Thursdays', 'Fridays', 'Saturdays', 'Sundays')

The names of days of the week in plural, Mondays to Sundays

ls.joyous.utils.names.WRAPPED_MONTH_NAMES = ('December', 'January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December', 'January')

Names of the months, December, January, …December, January

class ls.joyous.utils.names._Names[source]

Holds internationalized names and only translates them at the last possible moment, when they are accessed.

Recurrence

class ls.joyous.utils.recurrence.Recurrence(*args, **kwargs)[source]

Implementation of the recurrence rules somewhat based upon RFC 5545 RRules, implemented using dateutil.rrule.

Does not support timezones … and probably never will. Does not support a frequency of by-hour, by-minute or by-second.

byeaster

An offset from Easter Sunday.

bymonth

The months where the recurrence will be applied.

bymonthday

The month days where the recurrence will be applied.

bysetpos

The nth occurrence of the rule inside the frequency period.

byweekday

The weekdays where the recurrence will be applied. In RFC5545 this is called BYDAY, but is renamed by dateutil to avoid ambiguity.

byweekno

The week numbers to apply the recurrence to.

byyearday

The year days to apply the recurrence to.

count

Limit on the number of occurrences.

dtstart

The recurrence start date.

freq

How often the recurrence repeats. (0,1,2,3)

frequency

How often the recurrence repeats. (“YEARLY”, “MONTHLY”, “WEEKLY”, “DAILY”)

getCount()[source]

How many occurrences will be generated.

interval

The interval between each freq iteration.

until

The last occurence in the rule is the greatest date that is less than or equal to the value specified in the until parameter.

wkst

The week start day. The default week start is got from calendar.firstweekday() which Joyous sets based on the Django FIRST_DAY_OF_WEEK format.

class ls.joyous.utils.recurrence.Weekday(wkday, n=None)[source]

Represents a day of the week, for every occurence of the week or for a specific week in the period. e.g. The first Friday of the month.

Tell time

ls.joyous.utils.telltime._timeFormat(when, formatStr)[source]

Format a single time, e.g. 10am

ls.joyous.utils.telltime.dateFormat(when)[source]

Format the date when, e.g. Friday 14th of April 2011

Uses the format given by JOYOUS_DATE_FORMAT if that is set, or otherwise the standard Django date format.

ls.joyous.utils.telltime.dateShortFormat(when)[source]

Short version of the date when, e.g. 14 April 2017

Uses the format given by JOYOUS_DATE_SHORT_FORMAT if that is set, or otherwise the standard Django date format.

ls.joyous.utils.telltime.getAwareDatetime(date, time, tz, timeDefault=datetime.time(23, 59, 59, 999999))[source]

Get a datetime in the given timezone from date and optionally time. If time is not given it will default to timeDefault if that is given or if not then to the end of the day.

ls.joyous.utils.telltime.getLocalDate(*args, **kwargs)[source]

Get the date in the local timezone from date and optionally time

ls.joyous.utils.telltime.getLocalDateAndTime(date, time, *args, **kwargs)[source]

Get the date and time in the local timezone from date and optionally time

ls.joyous.utils.telltime.getLocalDatetime(date, time, tz=None, timeDefault=datetime.time(23, 59, 59, 999999))[source]

Get a datetime in the local timezone from date and optionally time

ls.joyous.utils.telltime.getLocalTime(date, time, *args, **kwargs)[source]

Get the time in the local timezone from date and time

ls.joyous.utils.telltime.getLocalTimeAtDate(atDate, time, *args, **kwargs)[source]

Get the time at a certain date in the local timezone

ls.joyous.utils.telltime.getTimeFrom(time_from)[source]

Return time_from if it is set, otherwise return the start of the day

ls.joyous.utils.telltime.getTimeTo(time_to)[source]

Return time_to if it is set, otherwise return the end of the day

ls.joyous.utils.telltime.timeFormat(time_from, time_to=None, prefix='', infix=None)[source]

Format the times time_from and optionally time_to, e.g. 10am

Uses the format given by JOYOUS_TIME_FORMAT if that is set, or otherwise the standard Django time format.

ls.joyous.utils.telltime.todayUtc()[source]

The current date in the UTC timezone

Weeks

Sets “Monday” or “Sunday” as the first day of the week depending upon the Django FIRST_DAY_OF_WEEK format.

ls.joyous.utils.weeks.gregorian_to_week_date(date_value)

year, week and day for the given Gregorian calendar date

ls.joyous.utils.weeks.num_weeks_in_year(ssweek_year)

Get the number of weeks in this year

ls.joyous.utils.weeks.week_info(ssweek_year, ssweek_week)

Give all the info we need from one calculation (first_day, last_day, prev_year_num_weeks, year_num_weeks)

ls.joyous.utils.weeks.week_of_month(date_value)

Returns a 0-starting index of which week in the month this date is

ls.joyous.utils.weeks.weekday_abbr = ('Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat')

Abbreviations of the days of the week

ls.joyous.utils.weeks.weekday_name = ('Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday')

Names of the days of the week