# `Calendrical.Reform.Sweden`

A composite calendar that tracks the historical calendar in use in Sweden.

Sweden's path from the Julian to the Gregorian calendar is the most unusual in
Europe, and makes a good demonstration of `Calendrical.Composite`: it splices
four calendars, drops a leap day, and includes the only known **30 February**.

## Transitions

* **(base)** — the Julian calendar.

* **1700-03-01** — Sweden begins a gradual transition by omitting the leap day
  of 1700 (there is no 29 February 1700) and switches to the transitional
  `Calendrical.Reform.Sweden.Transitional` calendar, which runs one day ahead of the
  Julian calendar.

* **1712-03-01** — Sweden abandons the transition and reverts to the Julian
  calendar. To realign, an extra day — **30 February 1712** — is inserted at
  the end of the transitional period.

* **1753-03-01** — Sweden adopts the proleptic Gregorian calendar. The eleven
  days 18 February 1753 through 28 February 1753 are skipped.

## Examples

    # 30 February 1712 is a valid date in Sweden
    iex> Calendrical.Reform.Sweden.valid_date?(1712, 2, 30)
    true

    # There is no 29 February 1700
    iex> Calendrical.Reform.Sweden.valid_date?(1700, 2, 29)
    false

    # The eleven days lost to the 1753 Gregorian adoption
    iex> Calendrical.Reform.Sweden.valid_date?(1753, 2, 20)
    false

## Reference

For a source-referenced survey of how other territories moved to the
Gregorian calendar, see `Calendrical.Reform` and Giuseppe Giudice's
[The adoption of the Gregorian calendar](https://web.archive.org/web/20130315080715/http://dpgi.unina.it/giudice/calendar/Adoption.html).

# `day`

```elixir
@type day() :: 1..31
```

# `month`

```elixir
@type month() :: 1..12
```

# `year`

```elixir
@type year() :: -9999..9999
```

# `calendar_base`

Identifies that the calendar is month based.

This may not always be true for all dates in a composite
calendar but only a single value per calendar is supported.

# `calendar_for_date`

# `calendar_for_date`

Identify the base calendar for a given date.

This function derives the calendar we delegate to for a given
date based upon the configuration.

# `calendar_for_iso_days`

Identify the base calendar for a given iso_days.

# `calendar_year`

```elixir
@spec calendar_year(Calendar.year(), Calendar.month(), Calendar.day()) ::
  Calendar.year()
```

Returns the calendar year as displayed on rendered calendars.

# `cldr_calendar_type`

Defines the CLDR calendar type for this calendar.

This type is used in support of `Calendrical.localize/3`.

# `cyclic_year`

```elixir
@spec cyclic_year(Calendar.year(), Calendar.month(), Calendar.day()) ::
  Calendar.year()
```

Returns the cyclic year.

# `date_from_iso_days`

Returns `{year, month, day}` calculated from the number of
`iso_days`.

# `date_to_iso_days`

# `date_to_iso_days`

Returns the number of days since the calendar epoch for the
given `year-month-day`.

# `day_of_era`

Calculates the day and era for the given date.

# `day_of_week`

Calculates the day of the week for the given date.

# `day_of_year`

Calculates the day of the year for the given date.

# `days_in_month`

Returns the number of days in the given month.

Composite calendars cannot answer this without a year so the
default implementation returns `{:error, :undefined}`.

# `days_in_month`

Returns the number of days in the given year/month.

# `days_in_week`

Returns the number of days in a week.

# `days_in_year`

Returns the number of days in the given year.

# `extended_year`

```elixir
@spec extended_year(Calendar.year(), Calendar.month(), Calendar.day()) ::
  Calendar.year()
```

Returns the extended year.

# `iso_week_of_year`

Calculates the ISO week of the year for the given date.

# `leap_year?`

Returns whether the given year is a leap year, in the context
of the calendar in effect on the first day of that year.

# `month`

Returns a `Date.Range` representing a given month of a year.

# `month_of_year`

Calculates the month of the year for the given date.

# `naive_datetime_from_iso_days`

Converts a `t:Calendar.iso_days/0` to the datetime form for
this calendar.

# `naive_datetime_to_iso_days`

```elixir
@spec naive_datetime_to_iso_days(
  Calendar.year(),
  Calendar.month(),
  Calendar.day(),
  Calendar.hour(),
  Calendar.minute(),
  Calendar.second(),
  Calendar.microsecond()
) :: Calendar.iso_days()
```

Returns the `t:Calendar.iso_days/0` form of the specified
datetime.

# `periods_in_year`

Returns the number of periods in the given year.

# `plus`

Adds an `increment` number of `:months` or `:quarters` to the
given `year-month-day`. Delegates to whichever base calendar is
in effect on the input date.

# `quarter`

Returns a `Date.Range` representing a given quarter of a year.

# `quarter_of_year`

Calculates the quarter of the year (1..4) for the given date.

# `related_gregorian_year`

```elixir
@spec related_gregorian_year(Calendar.year(), Calendar.month(), Calendar.day()) ::
  Calendar.year()
```

Returns the related Gregorian year.

# `shift_date`

```elixir
@spec shift_date(year(), month(), day(), Duration.t()) :: {year(), month(), day()}
```

Shifts a date by the given duration.

# `valid_date?`

Determines if the date given is valid according to this calendar.

# `week`

Returns a `Date.Range` representing a given week of a year.

Not all base calendars define weeks; the result depends on the
calendar in effect on 1 January of the given year.

# `week_of_month`

Composite calendars do not define week-of-month.

# `week_of_year`

Calculates the week of the year for the given date.

# `weeks_in_year`

Returns the number of weeks in the given year (in the context
of the calendar that starts the year).

# `year`

Returns a `Date.Range` representing a given year.

# `year_of_era`

```elixir
@spec year_of_era(year(), month(), day()) :: {year(), era :: non_neg_integer()}
```

Calculates the year and era from the given `year`, `month`,
and `day`. The result is in the context of the calendar in
effect on that date.

---

*Consult [api-reference.md](api-reference.md) for complete listing*
