Search code examples
timecalendartimezoneinternationalizationlocale

What defines whether a given day is "workday" or "weekend"?


Throughout the world there isn't a consensus what a workweek should be. Western-centric world seems to define it as 5x2 (5 workdays, 2 weekend days), but they define their own "start of week" be it sunday or monday, and weekends as either saturday sunday, or friday saturday. On the other hand some countries define it as 6x1, where the weekend is only either friday, saturday or sunday. Considering that there are multiple locales, timezones, calendars, and so on, what defines whether a given day is a workday or a weekend? So far I have found the following candidates, but they don't seem to fit the criteria

locale(5) specifies that locale files are only used for formatting texts, number, time. LC_TIME in particular seems to be a great candidate for this, but it does not seem to define weekends in particular, but instead defines what is start of week, and start of working week, but not length of working week.

tzfile(5) specifies how a given timezone switches its offsets, and how it moves relative to UTC0.

Is there such definition file at all?


Solution

  • You can find territory-specific weekend information in the Unicode CLDR project, as part of UTS-35 (LDML).

    From the docs:

    Week Elements
    ...
    weekendStart, weekendEnd Indicates the day and time that the weekend starts or ends ...

    The data itself can be found in the supplementalData.xml file. This is the entirety of the data, current as of the time of writing this answer:

    <weekData>
      <weekendStart day="thu" territories="AF"/>
      <weekendStart day="fri" territories="BH DZ EG IL IQ IR JO KW LY OM QA SA SD SY YE"/>
      <weekendStart day="sat" territories="001"/>
      <weekendStart day="sun" territories="IN UG"/>
      
      <weekendEnd day="fri" territories="AF IR"/>
      <weekendEnd day="sat" territories="BH DZ EG IL IQ JO KW LY OM QA SA SD SY YE"/>
      <weekendEnd day="sun" territories="001"/>
    <weekData>
    

    Note that 001 refers to the default, if the territory code is not specifically listed.

    Unicode also provides a chart that includes this information.


    Several libraries such as ICU and others expose CLDR data in various programming languages, so you may possibly be able to access this data through a built-in API or library.

    For example, in JavaScript, the Intl API provides this data via the getWeekInfo, though it uses numbers to represent the days of the week. Here's a working example to illustrate:

    const enUS = new Intl.Locale("en-US");
    console.log("US:", enUS.getWeekInfo().weekend);
    
    const heIL = new Intl.Locale("he-IL");
    console.log("Israel:", heIL.getWeekInfo().weekend);

    In Java, ICU4J exposes this data via weekendOnset and weekendCease in Calendar.WeekData, returned from Calendar.getWeekDataForRegion or Calendar.getWeekData.

    Other languages and platforms may expose the same data in other ways.