# daterange

The `daterange` type stores a lower and upper value of a date range. Either one can be omitted to store an open range.

## API

The API uses an object with fields `from` (lower value) and `to` (upper range) for the daterange type:

```json
{
  "daterange": {
    "from": "2001",
    "to": "2010",
    "text": {
      "de-DE": "Die erste Dekade im neuen Millennium",
      "en-US": "The first decade in the new millenium"
    }
  }
}
```

The fields `from` and `to` are parsed as `date` or `datetime` values. At least one of `from` and `to` is required.

Parsing of the dates works the same as for the [`date, datetime`](https://docs.fylr.io/for-developers/date-datetime#api) type. Thus, a `daterange` can store the full set of widths available for the dates in fylr. The shortest date is the year and the longest the full time including a timezone with seconds.

Alongside with the date values, a textual value for the `daterange` can be set. The format of the `text` property matches the format of the [`text_l10n`](https://docs.fylr.io/for-developers/text_l10n-text_l10n_oneline#api) type. The field `text` is optional and not parsed. It is only used for a additional textual representation which is only saved to be displayed next to the parsed values.

## Index

The index works the same as for the [`date, datetime`](https://docs.fylr.io/for-developers/date-datetime#index) type. Internally **fylr** always works with date ranges to store values.

Alongside with the `from` and `to` values, a `from_to` value is stored which allows for aggregations using the middle value of a date. To aggregate over the range, **fylr** additionally stores a `range` value which consists of all values between the lower and upper limit. **fylr** stores all years, months and days found in between the lower and upper value of the range, resp. If the date has the width `year`, all years in between are stored for aggregations. E.g. for the above example, the dates `2001-01-01 00:00:00, 2002-01-01 00:00:00, ..., 2010-01-01 00:00:00`.

## Sorting

Sorting works the same as described in for the [`date, datetime`](https://docs.fylr.io/for-developers/date-datetime#sorting) type.

## Export

The XML Export for the above example looks like this:

```xml
<daterange type="daterange" column-api-id="4">
  <from>2001</from>
  <to>2010</to>
  <text>
    <de-DE>Die erste Dekade im neuen Millennium</de-DE>
    <en-US>The first decade in the new millenium</en-US>
  </text>
</daterange>
```

The **JSON** exports the data like this:

```json
{
  "daterange": {
    "from": "2001",
    "to": "2010",
    "text": {
      "de-DE": "Die erste Dekade im neuen Millenium",
      "en-US": "The first decade in the new millenium"
    }
  }
}
```

**CSV** exports like this:

<table><thead><tr><th>daterange.from</th><th width="136">daterange.to</th><th width="212">daterange.text.de-DE</th><th>daterange.text.en-US</th></tr></thead><tbody><tr><td>2001</td><td>2010</td><td>Die erste Dekade im neuen Millennium</td><td>The first decade in the new millenium</td></tr></tbody></table>
