dates
- Description:
- Calendar related methods.
Because method names are going to be used in templates, we keep them short, but descriptive.
Method names are nouns describing what they return (rather than verbs), e.g..month()and.weekday(), unless they are made for modifying variables, like.addMonths().
All date/time related methods take their input as date/time strings (e.g. "2018-01-01") or Javascript date objects, unless something else is explicitly stated in the method name (an exception is for instance.monthFromNumber())
Methods ususally take one argument, and an additional options dictionary. See options for full documentation of available options.
Some methods can be chained, for readability:addMonths(d, 3).since()is equivalent tosince(addMonths(d, 3)).
- Calendar related methods.
Members
(static) today :string
- Description:
- Contains the current UTC date.
Contains the current UTC date.
Type:
- string
Examples
// returns '2019-01-13'
today
en
// returns '2019'
year(today)
ja
// returns '2019年'
year(today)
Methods
(static) addDays(date, num) → {string}
- Description:
- Add (or subtract) a number of days to a date.
This method deliberately ignore DLS
- Add (or subtract) a number of days to a date.
Examples
// returns '2019-04-01'
addDays("2019-03-31", 1)
tr
// returns '2019-03-31'
addDays("2019-04-01", -1)
Parameters:
| Name | Type | Description |
|---|---|---|
date |
Date | string | A date string or object |
num |
number | whole number of days to add (positive) or subtract (negative) |
Returns:
The new date
- Type
- string
(static) addMonths(date, num) → {string}
- Description:
- Add (or subtract) a number of months to a date, keeping as close as
possible to the original day of month (e.g. March 31 - 1 = February 28).
This method deliberately ignores DLS
- Add (or subtract) a number of months to a date, keeping as close as
possible to the original day of month (e.g. March 31 - 1 = February 28).
Examples
// returns '2018-02-28'
addMonths("2018-01-31", -1)
tr
// returns '2019-02-01'
addMonths("2018-12-01", 2)
Parameters:
| Name | Type | Description |
|---|---|---|
date |
Date | string | A date string or object |
num |
number | whole number of months to add (positive) or subtract (negative) |
Returns:
The new date
- Type
- string
(static) addYears(date, num) → {string}
- Description:
- Add (or subtract) a number of years to a date, keeping as close as
possible to the original day of month.
This method deliberately ignore DLS
- Add (or subtract) a number of years to a date, keeping as close as
possible to the original day of month.
Example
// returns '2018-01-01'
addYears("2019-01-01", -1)
// returns '2018-02-28'
addYears("2016-02-29", 2)
Parameters:
| Name | Type | Description |
|---|---|---|
date |
Date | string | A date string or object |
num |
number | whole number of years to add (positive) or subtract (negative) |
Returns:
The new date
- Type
- string
(static) age(birthdate, comparisonDateopt, optsopt) → {number}
- Description:
- Give a person's age in years, given a birthdate
Example
sv
// returns '46'
age("1978-05-06", "2025-02-21")
age("1978-05-06", today)
Parameters:
| Name | Type | Attributes | Default | Description | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
birthdate |
string | Date | The birthdate | ||||||||||
comparisonDate |
string | Date |
<optional> |
today
|
The current date | ||||||||
opts |
object |
<optional> |
Options
Properties
|
Returns:
The age in years
- Type
- number
(static) agePretty(birthdate, comparisonDateopt, optsopt) → {number}
- Description:
- Give a person's age in years, given a birthdate
Example
sv
// returns '46'
age("1978-05-06", "2025-02-21")
age("1978-05-06", today)
Parameters:
| Name | Type | Attributes | Default | Description | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
birthdate |
string | Date | The birthdate | ||||||||||
comparisonDate |
string | Date |
<optional> |
today
|
The current date | ||||||||
opts |
object |
<optional> |
Options
Properties
|
Returns:
The age in years
- Type
- number
(static) ageText(birthdate, comparisonDateopt, optsopt) → {number}
- Description:
- Give a person's age in years, given a birthdate
Example
sv
// returns 'fyrtiosex'
ageText("1978-05-06", "2025-02-21")
ageText("1978-05-06", today)
Parameters:
| Name | Type | Attributes | Default | Description | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
birthdate |
string | Date | The birthdate | ||||||||||
comparisonDate |
string | Date |
<optional> |
today
|
The current date | ||||||||
opts |
object |
<optional> |
Options
Properties
|
Returns:
The age in years
- Type
- number
(static) date(dateopt, optsopt) → {string}
- Description:
- Get a full date string.
Examples
en
// returns 'January 1, 2016'
date("2016-01-01")
sv
// returns '1 januari 2016'
date("2016-01-01")
Parameters:
| Name | Type | Attributes | Default | Description | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
date |
Date | string |
<optional> |
today
|
A date string or object | ||||||||
opts |
object |
<optional> |
Options
Properties
|
Returns:
A date string
- Type
- string
(static) dateList(dates, optsopt) → {string}
- Description:
- Use greatest difference logic to list a number of dates
Example
sv
// returns '3, 5 och 6 februari 2018'
dateList(["2018-02-03", "2018-02-05", "2018-02-06"])
// returns '3 januari och 5 februari 2018'
dateList(["2018-01-03", "2018-02-05"])
// returns '1, 2 och 3 januari; 5 februari och 18 mars 2018'
dateList(["2018-01-01", "2018-01-02", "2018-01-03", "2018-02-05", "2018-03-18"])
Parameters:
| Name | Type | Attributes | Description |
|---|---|---|---|
dates |
Array.<(string|Date)> | a list of dates | |
opts |
object |
<optional> |
options |
Returns:
a list of dates
- Type
- string
(static) dateListOr(dates, optsopt) → {string}
- Description:
- Use greatest difference logic to list a number of dates
Example
sv
// returns '3, 5 eller 6 februari 2018'
dateListOr(["2018-02-03", "2018-02-05", "2018-02-06"])
// returns '3 januari eller 5 februari 2018'
dateListOr(["2018-01-03", "2018-02-05"])
// returns '1, 2 eller 3 januari; 5 februari eller 18 mars 2018'
dateListOr(["2018-01-01", "2018-01-02", "2018-01-03", "2018-02-05", "2018-03-18"])
Parameters:
| Name | Type | Attributes | Description |
|---|---|---|---|
dates |
Array.<(string|Date)> | a list of dates | |
opts |
object |
<optional> |
options |
Returns:
a list of dates
- Type
- string
(static) dateShort(dateopt, optsopt) → {string}
- Description:
- Get a abbreviated date string
Examples
en
// returns 'Jan 1, 2016'
date("2016-01-01")
sv
// returns '1 jan 2016'
date("2016-01-01")
Parameters:
| Name | Type | Attributes | Default | Description | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
date |
Date | string |
<optional> |
today
|
A date string or object | ||||||||
opts |
object |
<optional> |
Options
Properties
|
Returns:
A date string
- Type
- string
(static) day(dateopt, optsopt) → {string}
- Description:
- Get a d string.
Examples
en
// returns '1'
day("2016-01-01")
ja
// returns '1日'
day("2016-01-01")
// returns '一日'
day("2016-01-01", {numberSystem: "jpan"})
Parameters:
| Name | Type | Attributes | Default | Description |
|---|---|---|---|---|
date |
object | string |
<optional> |
today
|
A date string or object |
opts |
object |
<optional> |
Options |
Returns:
A day of month string
- Type
- string
(static) dayMonth(dateopt, optsopt) → {string}
- Description:
- Get a day/month (MMMMd) string.
Examples
en
// returns 'January 1'
dayMonth("2016-01-01")
sv
// returns '1 januari'
dayMonth("2016-01-01")
ja
// returns '1月1日'
dayMonth("2016-01-01")
Parameters:
| Name | Type | Attributes | Default | Description | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
date |
Date | string |
<optional> |
today
|
A date string or object | ||||||||
opts |
object |
<optional> |
Options
Properties
|
Returns:
A month/year string
- Type
- string
(static) dayMonthList(dates, optsopt) → {string}
- Description:
- Use greatest difference logic to list number of dates
Example
sv
// returns '3, 5 och 6 februari'
dayMonthList(["2018-02-03", "2018-02-05", "2018-02-06"])
// returns '3 januari och 5 februari'
dayMonthList(["2018-01-03", "2018-02-05"])
Parameters:
| Name | Type | Attributes | Description |
|---|---|---|---|
dates |
Array.<(string|Date)> | a list of dates | |
opts |
object |
<optional> |
options |
Returns:
a list of dates
- Type
- string
(static) dayMonthListOr(dates, optsopt) → {string}
- Description:
- Use greatest difference logic to list a number of dates
Example
sv
// returns '3, 5 eller 6 februari'
dayMonthListOr(["2018-02-03", "2018-02-05", "2018-02-06"])
// returns '3 januari eller 5 februari'
dayMonthListOr(["2018-01-03", "2018-02-05"])
Parameters:
| Name | Type | Attributes | Description |
|---|---|---|---|
dates |
Array.<(string|Date)> | a list of dates | |
opts |
object |
<optional> |
options |
Returns:
a list of dates
- Type
- string
(static) dayMonthPretty(dateopt, optsopt) → {string}
- Description:
- Get a day/month string like ”tredje november”.
Examples
en
// returns 'January 1st'
dayMonthText("2016-01-01")
sv
// returns 'första januari'
dayMonthText("2016-01-01")
ja
// returns '一月一日'
dayMonthText("2016-01-01")
Parameters:
| Name | Type | Attributes | Default | Description |
|---|---|---|---|---|
date |
Date | string |
<optional> |
today
|
A date string or object |
opts |
object |
<optional> |
Options |
Returns:
A month/year string
- Type
- string
(static) dayMonthShort(dateopt, optsopt) → {string}
- Description:
- Get a day/month (MMMd) string.
Examples
en
// returns 'Jan. 1'
dayMonthShort("2016-01-01")
sv
// returns '1 jan.'
dayMonthShort("2016-01-01")
ja
// returns '1月1日'
dayMonthShort("2016-01-01")
Parameters:
| Name | Type | Attributes | Default | Description | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
date |
Date | string |
<optional> |
today
|
A date string or object | ||||||||
opts |
object |
<optional> |
Options
Properties
|
Returns:
A month/year string
- Type
- string
(static) dayMonthText(dateopt, optsopt) → {string}
- Description:
- Get a day/month string like ”tredje november”.
Examples
en
// returns 'January 1st'
dayMonthText("2016-01-01")
sv
// returns 'första januari'
dayMonthText("2016-01-01")
ja
// returns '一月一日'
dayMonthText("2016-01-01")
Parameters:
| Name | Type | Attributes | Default | Description |
|---|---|---|---|---|
date |
Date | string |
<optional> |
today
|
A date string or object |
opts |
object |
<optional> |
Options |
Returns:
A month/year string
- Type
- string
(static) dayPretty(dateopt, optsopt) → {string}
- Description:
- Get a d string.
Example
sv
// returns 'första'
dayPretty("2016-01-01")
// returns '21:a'
dayPretty("2016-01-21")
Parameters:
| Name | Type | Attributes | Default | Description |
|---|---|---|---|---|
date |
object | string |
<optional> |
today
|
A date string or object |
opts |
object |
<optional> |
Options |
Returns:
A day of month string
- Type
- string
(static) dayText(dateopt, optsopt) → {string}
- Description:
- Get a d string.
Examples
sv
// returns 'första'
dayText("2016-01-01")
ja
// returns '一日'
dayText("2016-01-01")
Parameters:
| Name | Type | Attributes | Default | Description |
|---|---|---|---|---|
date |
object | string |
<optional> |
today
|
A date string or object |
opts |
object |
<optional> |
Options |
Returns:
A day of month string
- Type
- string
(static) days(date_1, date_2opt, optsopt) → {string}
- Description:
- Get the number of days that passed between two dates
Example
sv
// returns '10 dagar'
days("2018-08-01", "2019-06-01")
// returns '1 dag'
days("2018-01-30", "2019-02-28")
Parameters:
| Name | Type | Attributes | Default | Description | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
date_1 |
Date | string | A date string or object | ||||||||||
date_2 |
Date | string |
<optional> |
today
|
A date string or object | ||||||||
opts |
object |
<optional> |
Options
Properties
|
Returns:
describing the number of days
- Type
- string
(static) daysInMonth(date) → {number}
- Description:
- Return the number of days in a month
Example
sv
// returns 28
daysInMonth("2018-02-03")
Parameters:
| Name | Type | Description |
|---|---|---|
date |
Date | a date |
Returns:
an integer length
- Type
- number
(static) daysPretty(date_1, date_2opt, optsopt) → {string}
- Description:
- Get the number of full days that passed between two dates spelling them out for lower numbers, if desired
Example
sv
// returns 'tio dagar'
daysPretty("2018-08-01", "2019-06-01")
// returns '22 dagar'
daysPretty("2018-01-30", "2020-04-28")
Parameters:
| Name | Type | Attributes | Default | Description | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
date_1 |
Date | string | A date string or object | ||||||||||||||
date_2 |
Date | string |
<optional> |
today
|
A date string or object | ||||||||||||
opts |
object |
<optional> |
Options
Properties
|
Returns:
describing the number of days
- Type
- string
(static) daysText(date_1, date_2opt, optsopt) → {string}
- Description:
- Get the number of full days that passed between two dates with number of days printed out using numberText
Example
sv
// returns 'tio dagar'
daysText("2018-08-01", "2018-08-11")
// returns 'en dag'
daysText("2018-01-31", "2019-02-01")
Parameters:
| Name | Type | Attributes | Default | Description | ||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
date_1 |
Date | string | A date string or object | ||||||||||||
date_2 |
Date | string |
<optional> |
today
|
A date string or object | ||||||||||
opts |
object |
<optional> |
Options
Properties
|
Returns:
describing the number of days
- Type
- string
(static) decameronMonth(date, optsopt) → {string}
- Description:
- Divides the month in thirds, like the East Asian 旬. In English we translate these to things like ”end of May”. This is local, non-CLDR data, and language support is limited. Note that we follow the East Asian practice of assigning the first 10 days to the beginning of the month, then next 10 days to the middle, and the remainder to the end.
Example
sv
// returns 'början av april'
decameronMonth("2017-04-03")
Parameters:
| Name | Type | Attributes | Description |
|---|---|---|---|
date |
string | Date | date to check | |
opts |
object |
<optional> |
Options |
Returns:
a decameron phrase
- Type
- string
(static) decameronMonthYear(date, optsopt) → {string}
- Description:
- Divides the month in thirds, like the East Asian 旬. In English we translate these to things like ”end of May”. This is local, non-CLDR data, and language support is limited. Note that we follow the East Asian practice of assigning the first 10 days to the beginning of the month, then next 10 days to the middle, and the remainder to the end.
Example
sv
// returns 'början av april 2017'
decameronMonthYear("2017-04-03")
Parameters:
| Name | Type | Attributes | Description |
|---|---|---|---|
date |
string | Date | date to check | |
opts |
object |
<optional> |
Options |
Returns:
a decameron phrase
- Type
- string
(static) fuzzyDate(dateopt, optsopt) → {string}
- Description:
- Return the most complete date possible, givet a full or partial date string. Unlike other date methods, fuzzyDate does only accept strings.
Example
en
// returns 'January 1, 2016'
fuzzyDate("2016-01-01")
// returns 'January 2016'
fuzzyDate("2016-01")
// returns '2016'
fuzzyDate("2016")
Parameters:
| Name | Type | Attributes | Default | Description | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
date |
string |
<optional> |
today
|
A date string | ||||||||||||
opts |
object |
<optional> |
Options
Properties
|
Returns:
A date string
- Type
- string
(static) interval(date_1, date_2opt, optsopt) → {string}
- Description:
- Construct a date interval from two dates.
Examples
sv
// returns '3–12 april 2018'
interval("2018-04-03", "2018-04-12")
// returns '3 april–12 augusti 2018'
interval("2018-04-03", "2018-08-12")
// returns '3 april 2018–12 augusti 2019'
interval("2018-04-03", "2019-08-12")
ja
// returns '2019年1月1日~17日'
interval("2019-01-01", "2019-01-17")
Parameters:
| Name | Type | Attributes | Default | Description |
|---|---|---|---|---|
date_1 |
string | Date | First date | ||
date_2 |
string | Date |
<optional> |
today
|
Second date |
opts |
object |
<optional> |
Options |
Returns:
A formatted date interval
- Type
- string
(static) intervalDayMonth(date_1, date_2opt, optsopt) → {string}
- Description:
- Construct a month interval from two dates, only including the year if necessary
Example
sv
// returns '3 december 2017–12 april 2018'
intervalDayMonth("2017-12-03", "2018-04-12")
// returns '3 april–12 augusti'
intervalDayMonth("2018-04-03", "2018-08-12")
Parameters:
| Name | Type | Attributes | Default | Description |
|---|---|---|---|---|
date_1 |
string | Date | First date | ||
date_2 |
string | Date |
<optional> |
today
|
Second date |
opts |
object |
<optional> |
Options |
Returns:
A formatted month interval
- Type
- string
(static) intervalMonth(date_1, date_2opt, optsopt) → {string}
- Description:
- Construct a month interval from two dates.
Examples
sv
// returns 'december 2017–april 2018'
intervalMonth("2017-12-03", "2018-04-12")
// returns 'april–augusti 2018'
intervalMonth("2018-04-03", "2018-08-12")
ja
// returns '2018年1月~4月'
intervalMonth("2018-01-01", "2019-04-17")
Parameters:
| Name | Type | Attributes | Default | Description |
|---|---|---|---|---|
date_1 |
string | Date | First date | ||
date_2 |
string | Date |
<optional> |
today
|
Second date |
opts |
object |
<optional> |
Options |
Returns:
A formatted month interval
- Type
- string
(static) listDates()
- Description:
- Alias for dateList
- Deprecated:
- Yes
(static) listDayMonths()
- Description:
- Alias for dayMonthList
- Deprecated:
- Yes
(static) listMonthYears()
- Description:
- Alias for monthYearList
- Deprecated:
- Yes
(static) listMonthYears()
- Description:
- Alias for monthYearList
- Deprecated:
- Yes
(static) month(dateopt, optsopt) → {string}
- Description:
- Get plain text month name from a date string (or date object)
Example
sv
//returns 'januari'
month("2018-08-01")
Parameters:
| Name | Type | Attributes | Default | Description | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
date |
Date | string |
<optional> |
today
|
A date string or object | ||||||||
opts |
object |
<optional> |
Options
Properties
|
Returns:
A monthname
- Type
- string
(static) monthDays(date_1, date_2opt, optsopt) → {string}
- Description:
- Get the time between two dates expressed in months and days
Example
sv
// returns '1 år och 2 månader'
monthDays("2018-08-01", "2019-08-02")
// returns '1 dag'
monthDays("2018-08-01", "2019-09-11")
// returns '1 månad och 10 dagar'
Parameters:
| Name | Type | Attributes | Default | Description | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
date_1 |
Date | string | A date string or object | ||||||||||
date_2 |
Date | string |
<optional> |
today
|
A date string or object | ||||||||
opts |
object |
<optional> |
Options
Properties
|
Returns:
describing the number of years and months
- Type
- string
(static) monthDays(date_1, date_2opt, optsopt) → {string}
- Description:
- Get the time between two dates expressed in months and days
Example
sv
// returns '1 år och 2 månader'
monthDays("2018-08-01", "2019-08-02")
// returns '1 dag'
monthDays("2018-08-01", "2019-09-11")
// returns '1 månad och 10 dagar'
Parameters:
| Name | Type | Attributes | Default | Description | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
date_1 |
Date | string | A date string or object | ||||||||||
date_2 |
Date | string |
<optional> |
today
|
A date string or object | ||||||||
opts |
object |
<optional> |
Options
Properties
|
Returns:
describing the number of years and months
- Type
- string
(static) monthDaysPretty(date_1, date_2opt, optsopt) → {string}
- Description:
- Get the time between two dates expressed in months and days
Example
sv
// returns 'ett år och två månader'
monthDaysPretty("2018-08-01", "2019-08-02")
// returns 'en dag'
monthDaysPretty("2018-08-01", "2019-09-11")
// returns 'en månad och tio dagar'
Parameters:
| Name | Type | Attributes | Default | Description | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
date_1 |
Date | string | A date string or object | ||||||||||||||
date_2 |
Date | string |
<optional> |
today
|
A date string or object | ||||||||||||
opts |
object |
<optional> |
Options
Properties
|
Returns:
describing the number of years and months
- Type
- string
(static) monthDaysPretty(date_1, date_2opt, optsopt) → {string}
- Description:
- Get the time between two dates expressed in months and days
Example
sv
// returns 'ett år och två månader'
monthDaysPretty("2018-08-01", "2019-08-02")
// returns 'en dag'
monthDaysPretty("2018-08-01", "2019-09-11")
// returns 'en månad och tio dagar'
Parameters:
| Name | Type | Attributes | Default | Description | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
date_1 |
Date | string | A date string or object | ||||||||||||||
date_2 |
Date | string |
<optional> |
today
|
A date string or object | ||||||||||||
opts |
object |
<optional> |
Options
Properties
|
Returns:
describing the number of years and months
- Type
- string
(static) monthDaysText(date_1, date_2opt, optsopt) → {string}
- Description:
- Get the time between two dates expressed in months and days
Example
sv
// returns 'ett år och två månader'
monthDaysText("2018-08-01", "2019-08-02")
// returns 'en dag'
monthDaysText("2018-08-01", "2019-09-11")
// returns 'en månad och tio dagar'
Parameters:
| Name | Type | Attributes | Default | Description |
|---|---|---|---|---|
date_1 |
Date | string | A date string or object | ||
date_2 |
Date | string |
<optional> |
today
|
A date string or object |
opts |
object |
<optional> |
Options |
Returns:
describing the number of years and months
- Type
- string
(static) monthDaysText(date_1, date_2opt, optsopt) → {string}
- Description:
- Get the time between two dates expressed in months and days
Example
sv
// returns 'ett år och två månader'
monthDaysText("2018-08-01", "2019-08-02")
// returns 'en dag'
monthDaysText("2018-08-01", "2019-09-11")
// returns 'en månad och tio dagar'
Parameters:
| Name | Type | Attributes | Default | Description |
|---|---|---|---|---|
date_1 |
Date | string | A date string or object | ||
date_2 |
Date | string |
<optional> |
today
|
A date string or object |
opts |
object |
<optional> |
Options |
Returns:
describing the number of years and months
- Type
- string
(static) monthFromNumber(index, optsopt) → {string}
- Description:
- Takes a month index (0,1,2...) and returns a month name
Examples
sv
// returns 'januari'
monthFromNumber(0)
fi
// returns 'heinäkuu'
monthFromNumber(6, {style: "standAlone"})
// returns 'heinäkuuta'
monthFromNumber(6, {style: "format"})
Parameters:
| Name | Type | Attributes | Description | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|
index |
string | number | A zero indexed month number | |||||||||
opts |
object |
<optional> |
Options
Properties
|
Returns:
A monthname
- Type
- string
(static) monthShort(dateopt) → {string}
- Description:
- Get plain text abbreviated month name from a date string (or date object)
Example
sv
// returns 'jan'
monthShort("2018-08-01")
Parameters:
| Name | Type | Attributes | Default | Description |
|---|---|---|---|---|
date |
Date | string |
<optional> |
today
|
A date string or object |
Returns:
A monthname
- Type
- string
(static) monthShortFromNumber(index) → {string}
- Description:
- Takes a month index (0,1,2...) and returns an abbreviated month name
Example
sv
// returns 'jan'
monthShortFromNumber(0)
Parameters:
| Name | Type | Description |
|---|---|---|
index |
string | number | A zero indexed month number |
Returns:
An abbreviated monthname
- Type
- string
(static) monthYear(dateopt, optsopt) → {string}
- Description:
- Get a yMMMM string.
Examples
en
// returns 'January 2016'
monthYear("2016-01-01")
ja
// returns '2016年1月'
monthYear("2016-01-01")
Parameters:
| Name | Type | Attributes | Default | Description |
|---|---|---|---|---|
date |
object | string |
<optional> |
today
|
A date string or object |
opts |
object |
<optional> |
Options |
Returns:
A month/year string
- Type
- string
(static) monthYearList(dates, optsopt) → {string}
- Description:
- Use greatest difference logic to list number of dates
Example
sv
// returns 'februari 2018'
monthYearList(["2018-02-03", "2018-02-05", "2018-02-06"])
// returns 'januari och februari 2018'
monthYearList(["2018-01-03", "2018-02-05"])
// returns '1 januari, februari och mars 2018; februari 2019 och mars 2020'
monthYearList(["2018-01-01", "2018-01-02", "2018-01-03", "2018-02-05", "2018-03-18", "2019-02-05", "2020-03-18"])
Parameters:
| Name | Type | Attributes | Description |
|---|---|---|---|
dates |
Array.<(string|Date)> | a list of dates | |
opts |
object |
<optional> |
options |
Returns:
a list of dates
- Type
- string
(static) monthYearListOr(dates, optsopt) → {string}
- Description:
- Use greatest difference logic to list a number of dates
Example
sv
// returns 'februari 2018'
monthYearListOr(["2018-02-03", "2018-02-05", "2018-02-06"])
// returns 'januari eller februari 2018'
monthYearListOr(["2018-01-03", "2018-02-05"])
// returns '1 januari, februari eller mars 2018; februari 2019 eller mars 2020'
monthYearListOr(["2018-01-01", "2018-01-02", "2018-01-03", "2018-02-05", "2018-03-18", "2019-02-05", "2020-03-18"])
Parameters:
| Name | Type | Attributes | Description |
|---|---|---|---|
dates |
Array.<(string|Date)> | a list of dates | |
opts |
object |
<optional> |
options |
Returns:
a list of dates
- Type
- string
(static) monthYearShort(dateopt, optsopt) → {string}
- Description:
- Get a yMMM string.
Examples
en
// returns 'Jan 2016'
monthYearShort("2016-01-01")
ja
// returns '2016年1月'
monthYearShort("2016-01-01")
Parameters:
| Name | Type | Attributes | Default | Description |
|---|---|---|---|---|
date |
object | string |
<optional> |
today
|
A date string or object |
opts |
object |
<optional> |
Options |
Returns:
A short month/year string
- Type
- string
(static) months(date_1, date_2opt, optsopt) → {string}
- Description:
- Get the number of full months that passed between two dates
Examples
sv
// returns '10 månader'
months("2018-08-01", "2019-06-01")
// returns '1 månad'
months("2018-01-30", "2019-02-28")
ja
// returns '1ヶ月'
months("2019-05-01", "2019-06-01")
Parameters:
| Name | Type | Attributes | Default | Description | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
date_1 |
Date | string | A date string or object | ||||||||||
date_2 |
Date | string |
<optional> |
today
|
A date string or object | ||||||||
opts |
object |
<optional> |
Options
Properties
|
Returns:
describing the number of months
- Type
- string
(static) monthsPretty(date_1, date_2opt, optsopt) → {string}
- Description:
- Get the number of full months that passed between two dates spelling them out for lower numbers, if desired
Example
sv
// returns 'tio månader'
monthsPretty("2018-08-01", "2019-06-01")
// returns '22 månader'
monthsPretty("2018-01-30", "2020-04-28")
Parameters:
| Name | Type | Attributes | Default | Description | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
date_1 |
Date | string | A date string or object | ||||||||||||||
date_2 |
Date | string |
<optional> |
today
|
A date string or object | ||||||||||||
opts |
object |
<optional> |
Options
Properties
|
Returns:
describing the number of months
- Type
- string
(static) monthsText(date_1, date_2opt, optsopt) → {string}
- Description:
- Get the number of full months that passed between two dates with number of months printed out using numberText
Examples
sv
// returns 'tio månader'
monthsText("2018-08-01", "2019-06-01")
// returns 'en månad'
monthsText("2018-01-30", "2019-02-28")
ja
// returns '一ヶ月'
monthsText("2019-05-01", "2019-06-01")
Parameters:
| Name | Type | Attributes | Default | Description | ||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
date_1 |
Date | string | A date string or object | ||||||||||||
date_2 |
Date | string |
<optional> |
today
|
A date string or object | ||||||||||
opts |
object |
<optional> |
Options
Properties
|
Returns:
describing the number of months
- Type
- string
(static) quadrimester(date, optsopt) → {string}
- Description:
- Descibe year thirds (”quadrimesters”)
Example
sv
// returns 'slutet av 2017'
quadrimester("2017-12-03")
Parameters:
| Name | Type | Attributes | Description |
|---|---|---|---|
date |
string | Date | to check | |
opts |
object |
<optional> |
Options |
Returns:
A quadrimester phrase
- Type
- string
(static) quarter(dateopt, optsopt) → {string}
- Description:
- Get a numerical quarter description from a date string (or date object)
Example
sv
// returns '1:a kvartalet'
quarter("2018-01-15")
Parameters:
| Name | Type | Attributes | Default | Description | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
date |
Date | string |
<optional> |
today
|
A date string or object | ||||||||
opts |
object |
<optional> |
Options
Properties
|
Returns:
A monthname
- Type
- string
(static) quarterNumber(dateopt, optsopt) → {string}
- Description:
- Get a the quarter as a plain number. Useful for chaining, e.g. `Date.quarterNumber().ordinalText()`
Example
sv
// returns '1'
quarterNumber("2018-01-15")
Parameters:
| Name | Type | Attributes | Default | Description | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
date |
Date | string |
<optional> |
today
|
A date string or object | ||||||||
opts |
object |
<optional> |
Options
Properties
|
Returns:
A quarter number
- Type
- string
(static) quarterText(dateopt) → {string}
- Description:
- Get a textual quarter description from a date string (or date object) NB: Limited language support!
Example
sv
// returns 'första kvartalet'
quarterText("2018-01-15")
Parameters:
| Name | Type | Attributes | Default | Description |
|---|---|---|---|---|
date |
Date | string |
<optional> |
today
|
A date string or object |
Returns:
A quarter name
- Type
- string
(static) quarterYear(dateopt, optsopt) → {string}
- Description:
- Get a quarter/ year description from a date string (or date object)
For many languages this will be equivalent to`${quarter(d)} ${year(d)}`or`${year(d)} ${quarter(d)}`
- Get a quarter/ year description from a date string (or date object)
Example
sv
// returns '1:a kvartalet 2018'
quarterYear("2018-01-15")
Parameters:
| Name | Type | Attributes | Default | Description | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
date |
Date | string |
<optional> |
today
|
A date string or object | ||||||||
opts |
object |
<optional> |
Options
Properties
|
Returns:
A monthname
- Type
- string
(static) quarterYearText(dateopt, optsopt) → {string}
- Description:
- Get a quarter / year description from a date string (or date object),
with a textual quarter part, if relevant.
For many languages this will be equivalent to`${quarterText(d)} ${year(d)}`or`${year(d)} ${quarterText(d)}`
- Get a quarter / year description from a date string (or date object),
with a textual quarter part, if relevant.
Example
sv
// returns '1:a kvartalet 2018'
quarterYear("2018-01-15")
Parameters:
| Name | Type | Attributes | Default | Description | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
date |
Date | string |
<optional> |
today
|
A date string or object | ||||||||
opts |
object |
<optional> |
Options
Properties
|
Returns:
A monthname
- Type
- string
(static) relativeDay(date_1, date_2opt, optsopt) → {string}
- Description:
- Describe a day, relative to another (by default the current), e.g yesterday.
Example
sv
// returns 'om 3 dagar'
relativeDay("2019-12-06")
// returns 'i går'
relativeDay("2019-12-01")
Parameters:
| Name | Type | Attributes | Default | Description | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
date_1 |
string | Date | The date we're talking about | ||||||||||
date_2 |
string | Date |
<optional> |
today
|
Date used for context. Usually when the text is read. | ||||||||
opts |
object |
<optional> |
Options
Properties
|
Returns:
A relative year phrase
- Type
- string
(static) relativeDayPretty(date_1, date_2opt, optsopt) → {string}
- Description:
- Describe a day, relative to another (by default the current), e.g yesterday.
Example
sv
// returns 'om tre dagar'
relativeDayPretty("2019-12-06")
// returns 'om 13 dagar'
relativeDayPretty("2019-12-16")
// relativeDayPretty 'i går'
relativeDay("2019-12-01")
Parameters:
| Name | Type | Attributes | Default | Description | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
date_1 |
string | Date | The date we're talking about | ||||||||||||||
date_2 |
string | Date |
<optional> |
today
|
Date used for context. Usually when the text is read. | ||||||||||||
opts |
object |
<optional> |
Options
Properties
|
Returns:
A relative day phrase
- Type
- string
(static) relativeDayText(date_1, date_2opt) → {string}
- Description:
- Describe a day, relative to another (by default the current), e.g yesterday.
Example
sv
// returns 'om tre dagar'
relativeDayText("2019-12-06")
// relativeDayText 'i går'
relativeDay("2019-12-01")
Parameters:
| Name | Type | Attributes | Default | Description |
|---|---|---|---|---|
date_1 |
string | Date | The date we're talking about | ||
date_2 |
string | Date |
<optional> |
today
|
Date used for context. Usually when the text is read. |
Returns:
A relative day phrase
- Type
- string
(static) relativeMonth(date_1, date_2opt, optsopt) → {string}
- Description:
- Describe a month, relative to another (by default the current), e.g “last month”.
Example
sv
// returns 'om 2 månader'
relativeMonth("2020-05-06", "2020-03")
Parameters:
| Name | Type | Attributes | Default | Description | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
date_1 |
string | Date | The date we're talking about | ||||||||||
date_2 |
string | Date |
<optional> |
today
|
Date used for context. Usually when the text is read. | ||||||||
opts |
object |
<optional> |
Options
Properties
|
Returns:
A relative year phrase
- Type
- string
(static) relativeMonthPretty(date_1, date_2opt, optsopt) → {string}
- Description:
- Describe a month, relative to another (by default the current), e.g “last month”.
Example
sv
// returns 'om två månader'
relativeMonthPretty("2020-05-06")
// returns 'om 24 månader'
relativeMonthPretty("2022-03-06")
Parameters:
| Name | Type | Attributes | Default | Description | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
date_1 |
string | Date | The date we're talking about | ||||||||||||||
date_2 |
string | Date |
<optional> |
today
|
Date used for context. Usually when the text is read. | ||||||||||||
opts |
object |
<optional> |
Options
Properties
|
Returns:
A relative year phrase
- Type
- string
(static) relativeMonthText(date_1, date_2opt) → {string}
- Description:
- Describe a month, relative to another (by default the current), e.g “last month”.
Example
sv
// returns 'förra månaden'
relativeMonthText("2019-12-01")
// returns 'om två månader'
relativeMonthText("2022")
Parameters:
| Name | Type | Attributes | Default | Description |
|---|---|---|---|---|
date_1 |
string | Date | The date we're talking about | ||
date_2 |
string | Date |
<optional> |
today
|
Date used for context. Usually when the text is read. |
Returns:
A relative year phrase
- Type
- string
(static) relativeMonthYear(date_1opt, date_2opt, optsopt) → {string}
- Description:
- Get a yMMMM string with the y part as a relative year.
Example
en
// returns 'January last year'
monthYear("2016-01-01", "2017-01-01")
Parameters:
| Name | Type | Attributes | Default | Description |
|---|---|---|---|---|
date_1 |
object | string |
<optional> |
A date string or object | |
date_2 |
object | string |
<optional> |
today
|
A date string or object |
opts |
object |
<optional> |
Options |
Returns:
A month/year string
- Type
- string
(static) relativeMonthYearPretty(date_1opt, date_2opt, optsopt) → {string}
- Description:
- Get a yMMMM string with the y part as a relative year.
Example
en
// returns 'January two years ago'
monthYear("2016-01-01", "2018-01-01")
Parameters:
| Name | Type | Attributes | Default | Description |
|---|---|---|---|---|
date_1 |
object | string |
<optional> |
A date string or object | |
date_2 |
object | string |
<optional> |
today
|
A date string or object |
opts |
object |
<optional> |
Options |
Returns:
A month/year string
- Type
- string
(static) relativeMonthYearText(date_1opt, date_2opt, optsopt) → {string}
- Description:
- Get a yMMMM string with the y part as a relative year.
Example
en
// returns 'January two years ago'
monthYear("2016-01-01", "2018-01-01")
Parameters:
| Name | Type | Attributes | Default | Description |
|---|---|---|---|---|
date_1 |
object | string |
<optional> |
A date string or object | |
date_2 |
object | string |
<optional> |
today
|
A date string or object |
opts |
object |
<optional> |
Options |
Returns:
A month/year string
- Type
- string
(static) relativeQuarter(date_1, date_2opt, optsopt) → {string}
- Description:
- Give a querter, relative to another (by default the current), e.g ”last quarter.
Example
sv
// returns 'förra kvartalet'
relativeQuarter("2019-12-01")
// returns 'om 8 kvartal'
relativeQuarter("2022")
Parameters:
| Name | Type | Attributes | Default | Description | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
date_1 |
string | Date | The date we're talking about | ||||||||||
date_2 |
string | Date |
<optional> |
today
|
Date used for context. Usually when the text is read. | ||||||||
opts |
object |
<optional> |
Options
Properties
|
Returns:
A relative quarter phrase
- Type
- string
(static) relativeQuarterPretty(date_1, date_2opt, optsopt) → {string}
- Description:
- Give a querter, relative to another (by default the current), e.g “last quarter”.
Example
sv
// returns 'förra kvartalet'
relativeQuarterPretty("2019-12-01")
// returns 'om åtta kvartal'
relativeQuarterPretty("2022")
Parameters:
| Name | Type | Attributes | Default | Description | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
date_1 |
string | Date | The date we're talking about | ||||||||||||||
date_2 |
string | Date |
<optional> |
today
|
Date used for context. Usually when the text is read. | ||||||||||||
opts |
object |
<optional> |
Options
Properties
|
Returns:
A relative quarter phrase
- Type
- string
(static) relativeQuarterText(date_1, date_2opt) → {string}
- Description:
- Give a quarter, relative to another (by default the current), e.g “last quarter”.
Example
sv
// returns 'förra kvartalet'
relativeQuarterText("2019-12-01")
// returns 'om åtta kvartal'
relativeQuarterText("2022")
Parameters:
| Name | Type | Attributes | Default | Description |
|---|---|---|---|---|
date_1 |
string | Date | The date we're talking about | ||
date_2 |
string | Date |
<optional> |
today
|
Date used for context. Usually when the text is read. |
Returns:
A relative quarter phrase
- Type
- string
(static) relativeWeek(date_1, date_2opt, optsopt) → {string}
- Description:
- Given a week, relative to another (by default the current), e.g “last week”. Note that weeks start at different days depending on the locale's territory. If your locale does not include a territory, the default territory for your language will be used. In case of ambiguity, an error will be thrown. In other words: `sv` will work, becuase in all of the Swedish' default territories AX, FI, and SE the week starts on Monday, but `en` will fail, because in some `en` territories the week starts on Sunday and in others on Monday. It's recommended to be specific in your locale settings to avoid ambiguity, but if that's not an option you can also pass the `weekStartsAt` option.
Example
sv
// returns 'förra veckan'
relativeWeek("2019-12-01", "2019-12-13")
// returns 'om 3 veckor'
relativeWeek("2020-01-03")
Parameters:
| Name | Type | Attributes | Default | Description | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
date_1 |
string | Date | The date we're talking about | ||||||||||||||
date_2 |
string | Date |
<optional> |
today
|
Date used for context. Usually when the text is read. | ||||||||||||
opts |
object |
<optional> |
Options
Properties
|
Returns:
A relative year phrase
- Type
- string
(static) relativeWeekPretty(date_1, date_2opt, optsopt) → {string}
- Description:
- Given a week, relative to another (by default the current), e.g “last week”. Note that weeks start at different days depending on the locale's territory. If your locale does not include a territory, the default territory for your language will be used. In case of ambiguity, an error will be thrown. In other words: `sv` will work, becuase in all of the Swedish' default territories AX, FI, and SE the week starts on Monday, but `en` will fail, because in some `en` territories the week starts on Sunday and in others on Monday. It's recommended to be specific in your locale settings to avoid ambiguity, but if that's not an option you can also pass the `weekStartsAt` option.
Example
sv
// returns 'om två veckor'
relativeWeekPretty("2042-05-06")
// returns 'om 14 veckor'
relativeWeekPretty("2042-05-06")
Parameters:
| Name | Type | Attributes | Default | Description | ||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
date_1 |
string | Date | The date we're talking about | ||||||||||||||||||
date_2 |
string | Date |
<optional> |
today
|
Date used for context. Usually when the text is read. | ||||||||||||||||
opts |
object |
<optional> |
Options
Properties
|
Returns:
A relative year phrase
- Type
- string
(static) relativeWeekText(date_1, date_2opt, optsopt) → {string}
- Description:
- Given a week, relative to another (by default the current), e.g “last week”. Note that weeks start at different days depending on the locale's territory. If your locale does not include a territory, the default territory for your language will be used. In case of ambiguity, an error will be thrown. In other words: `sv` will work, becuase in all of the Swedish' default territories AX, FI, and SE the week starts on Monday, but `en` will fail, because in some `en` territories the week starts on Sunday and in others on Monday. It's recommended to be specific in your locale settings to avoid ambiguity, but if that's not an option you can also pass the `weekStartsAt` option.
Example
sv
// returns 'förra veckan fjol'
relativeWeekText("2019-12-01")
// returns 'om trettiotvå veckor'
relativeWeekText("2022")
Parameters:
| Name | Type | Attributes | Default | Description | ||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
date_1 |
string | Date | The date we're talking about | ||||||||||||||||||
date_2 |
string | Date |
<optional> |
today
|
Date used for context. Usually when the text is read. | ||||||||||||||||
opts |
object |
<optional> |
Options
Properties
|
Returns:
A relative week phrase
- Type
- string
(static) relativeWeekday(date_1, date_2opt, optsopt) → {string}
- Description:
- Describe a weekday, relative to another (by default the current), e.g last Tuesday. Note 1: Support for grammatical case is still very much WIP in CLDR, making this method somewhat limited in e.g. Finnish. Note 2: The relative weekday phrases in CLDR are primarily tailored for use in timestamps, often making them less suited for use in inside texts. We might want to replace this one with a custom ruleset, if ever using it. Note 3: The weeks start at different days depending on the locale's territory. If your locale does not include a territory, the default territory for your language will be used. In case of ambiguity, an error will be thrown. In other words: `sv` will work, becuase in all of the Swedish' default territories AX, FI, and SE the week starts on Monday, but `en` will fail, because in some `en` territories the week starts on Sunday and in others on Monday. It's recommended to be specific in your locale settings to avoid ambiguity, but if that's not an option you can also pass the `weekStartsAt` option.
Example
sv
// returns 'torsdag denna vecka'
relativeWeekday(date)
// relativeWeekday 'måndag förra veckan'
relativeWeekday("2019-12-01")
Parameters:
| Name | Type | Attributes | Default | Description | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
date_1 |
string | Date | The date we're talking about | ||||||||||||||
date_2 |
string | Date |
<optional> |
today
|
Date used for context. Usually when the text is read. | ||||||||||||
opts |
object |
<optional> |
Options
Properties
|
Returns:
A relative year phrase
- Type
- string
(static) relativeWeekdayPretty(date_1, date_2opt, optsopt) → {string}
- Description:
- Describe a weekday, relative to another (by default the current), e.g “last Tuesday”. Note 1: Support for grammatical case is still very much WIP in CLDR, making this method somewhat limited in e.g. Finnish. Note 2: The relative weekday phrases in CLDR are primarily tailored for use in timestamps, often making them less suited for use in inside texts. We might want to replace this one with a custom ruleset, if ever using it. Note 3: The weeks start at different days depending on the locale's territory. If your locale does not include a territory, the default territory for your language will be used. In case of ambiguity, an error will be thrown. In other words: `sv` will work, becuase in all of the Swedish' default territories AX, FI, and SE the week starts on Monday, but `en` will fail, because in some `en` territories the week starts on Sunday and in others on Monday. It's recommended to be specific in your locale settings to avoid ambiguity, but if that's not an option you can also pass the `weekStartsAt` option.
Example
sv
// returns 'torsdag denna vecka'
relativeWeekdayText()
// relativeWeekdayText 'för tolv måndagar sedan'
relativeWeekdayText("2019-12-01")
Parameters:
| Name | Type | Attributes | Default | Description | ||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
date_1 |
string | Date | The date we're talking about | ||||||||||||||||||
date_2 |
string | Date |
<optional> |
today
|
Date used for context. Usually when the text is read. | ||||||||||||||||
opts |
object |
<optional> |
Options
Properties
|
Returns:
A relative year phrase
- Type
- string
(static) relativeWeekdayText(date_1, date_2opt, optsopt) → {string}
- Description:
- Describe a weekday, relative to another (by default the current), e.g last Tuesday. Note 1: Support for grammatical case is still very much WIP in CLDR, making this method somewhat limited in e.g. Finnish. Note 2: The relative weekday phrases in CLDR are primarily tailored for use in timestamps, often making them less suited for use in inside texts. We might want to replace this one with a custom ruleset, if ever using it. Note 3: The weeks start at different days depending on the locale's territory. If your locale does not include a territory, the default territory for your language will be used. In case of ambiguity, an error will be thrown. In other words: `sv` will work, becuase in all of the Swedish' default territories AX, FI, and SE the week starts on Monday, but `en` will fail, because in some `en` territories the week starts on Sunday and in others on Monday. It's recommended to be specific in your locale settings to avoid ambiguity, but if that's not an option you can also pass the `weekStartsAt` option.
Example
sv
// returns 'torsdag denna vecka'
relativeWeekdayText()
// relativeWeekdayText 'för tolv måndagar sedan'
relativeWeekdayText("2019-12-01")
Parameters:
| Name | Type | Attributes | Default | Description | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
date_1 |
string | Date | The date we're talking about | ||||||||||
date_2 |
string | Date |
<optional> |
today
|
Date used for context. Usually when the text is read. | ||||||||
opts |
object |
<optional> |
Options
Properties
|
Returns:
A relative year phrase
- Type
- string
(static) relativeYear(date_1, date_2opt, optsopt) → {string}
- Description:
- Give a year, relative to another (by default the current), e.g “last year”.
Examples
sv
// returns 'i fjol'
relativeYear("2019-12-01")
// returns 'om 2 år'
relativeYear("2022")
en (Pug)
// returns 'It was the coldest month since April 1966.'
| #{month(RainDate)} is always a rainy month,
| but #{relativeYear(RainDate)} it was even rainier than normal.
Parameters:
| Name | Type | Attributes | Default | Description | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
date_1 |
string | Date | The date we're talking about | ||||||||||
date_2 |
string | Date |
<optional> |
today
|
Date used for context. Usually when the text is read. | ||||||||
opts |
object |
<optional> |
Options
Properties
|
Returns:
A relative year phrase
- Type
- string
(static) relativeYearPretty(date_1, date_2opt, optsopt) → {string}
- Description:
- Give a year, relative to another (by default the current), e.g “last year”.
Example
sv
// returns 'om två år'
relativeYearPretty("2042-05-06")
// returns 'om 22 år'
relativeYearPretty("2042-05-06")
Parameters:
| Name | Type | Attributes | Default | Description | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
date_1 |
string | Date | The date we're talking about | ||||||||||||||
date_2 |
string | Date |
<optional> |
today
|
Date used for context. | ||||||||||||
opts |
object |
<optional> |
Options
Properties
|
Returns:
A relative year phrase
- Type
- string
(static) relativeYearText(date_1, date_2opt) → {string}
- Description:
- Give a year, relative to another (by default the current), e.g “last year”.
Example
sv
// returns 'i fjol'
relativeYearText("2019-12-01")
// returns 'om två år'
relativeYearText("2022")
Parameters:
| Name | Type | Attributes | Default | Description |
|---|---|---|---|---|
date_1 |
string | Date | The date we're talking about | ||
date_2 |
string | Date |
<optional> |
today
|
Date used for context. |
Returns:
A relative year phrase
- Type
- string
(static) season(dateopt, optsopt) → {string}
- Description:
- Primary season divisions in a certain locale, typically either [spring, summer, autum, winter] or [dry, wet, cold]. We only have data for a limited set of locales.
Example
sv
// returns 'vinter'
season("2017-12-03")
// returns 'vintras'
season("2017-12-03", {variant: "våras"})
Parameters:
| Name | Type | Attributes | Default | Description | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
date |
string | Date |
<optional> |
today
|
date to check | ||||||||
opts |
object |
<optional> |
Options
Properties
|
Returns:
A formatted season name, un-inflected
- Type
- string
(static) seasonYear(dateopt, optsopt) → {string}
- Description:
- Primary season divisions and year in a certain locale, typically either [spring, summer, autum, winter] or [dry, wet, cold]. Note that both year formatting and season variant may vary from `season()`'s defaults. We only have data for a limited set of locales.
Example
sv
// returns 'vintern 2017'
seasonYear("2017-12-03")
Parameters:
| Name | Type | Attributes | Default | Description | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
date |
string | Date |
<optional> |
today
|
date to check | ||||||||||||
opts |
object |
<optional> |
Options
Properties
|
Returns:
A formatted season/år string
- Type
- string
(static) semester(date, optsopt) → {string}
- Description:
- Descibe year halfs (semesters)
Example
sv
// returns 'andra halvåret'
semester("2017-12-03")
Parameters:
| Name | Type | Attributes | Description |
|---|---|---|---|
date |
string | Date | to check | |
opts |
object |
<optional> |
Options |
Returns:
A semester phrase
- Type
- string
(static) semesterYear(date, optsopt) → {string}
- Description:
- Descibe year halfs (semesters)
Example
sv
// returns 'andra halvåret 2017'
semester("2017-12-03")
Parameters:
| Name | Type | Attributes | Description |
|---|---|---|---|
date |
string | Date | to check | |
opts |
object |
<optional> |
Options |
Returns:
A semester phrase
- Type
- string
(static) since(date_1, date_2opt, optsopt) → {string}
- Description:
- Return one date in the context of another, avioding repitions of common
parts. The returned date could be eg. 'May 2' or 'May 2, 2018',
depending on the comparison date (defaults to
today)
- Return one date in the context of another, avioding repitions of common
parts. The returned date could be eg. 'May 2' or 'May 2, 2018',
depending on the comparison date (defaults to
Examples
sv
// returns '3 april'
since("2018-04-03", "2018-08-12")
// returns '3 april 2018'
since("2018-04-03", "2019-08-12")
en (Pug)
// returns 'It was the coldest day since April 4, 1966.'
`It was the coldest day since #{since("1966-04-03", "2010-11-12")}.`
Parameters:
| Name | Type | Attributes | Default | Description |
|---|---|---|---|---|
date_1 |
string | Date | The date to format | ||
date_2 |
string | Date |
<optional> |
today
|
Date used for context |
opts |
object |
<optional> |
Options |
Returns:
A formatted date
- Type
- string
(static) sinceMonth(date_1, date_2opt, optsopt) → {string}
- Description:
- Return one date in the context of another, avioding repitions of common
parts. The returned date could be eg. 'May' or 'May 2018',
depending on the comparison date (defaults to
today)
- Return one date in the context of another, avioding repitions of common
parts. The returned date could be eg. 'May' or 'May 2018',
depending on the comparison date (defaults to
Examples
sv
// returns 'april'
sinceMonth("2018-04-03", "2018-08-12")
// returns 'april 2018'
sinceMonth("2018-04-03", "2019-08-12")
en (Pug)
// returns 'It was the coldest month since April 1966.'
`It was the coldest month since #{sinceMonth("1966-04-03")}.`
Parameters:
| Name | Type | Attributes | Default | Description |
|---|---|---|---|---|
date_1 |
string | Date | The date to format | ||
date_2 |
string | Date |
<optional> |
today
|
Date used for context |
opts |
object |
<optional> |
Options |
Returns:
A formatted date
- Type
- string
(static) sinceMonthShort(date_1, date_2opt, optsopt) → {string}
- Description:
- Return one date in the context of another, avioding repitions of common
parts. The returned date could be eg. 'May' or 'May 2018',
depending on the comparison date (defaults to
today)
- Return one date in the context of another, avioding repitions of common
parts. The returned date could be eg. 'May' or 'May 2018',
depending on the comparison date (defaults to
Examples
sv
// returns 'apr'
sinceMonthShort("2018-04-03", "2018-08-12")
// returns 'apr 2018'
sinceMonthShort("2018-04-03", "2019-08-12")
en (Pug)
// returns 'It was the coldest month since Apr 1966.'
`It was the coldest month since #{sinceMonthShort("1966-04-03")}.`
Parameters:
| Name | Type | Attributes | Default | Description |
|---|---|---|---|---|
date_1 |
string | Date | The date to format | ||
date_2 |
string | Date |
<optional> |
today
|
Date used for context |
opts |
object |
<optional> |
Options |
Returns:
A formatted date
- Type
- string
(static) sinceShort(date_1, date_2opt, optsopt) → {string}
- Description:
- Return one date in the context of another, avioding repitions of common
parts. The returned date could be eg. 'May 2' or 'May 2, 2018',
depending on the comparison date (defaults to
today)
- Return one date in the context of another, avioding repitions of common
parts. The returned date could be eg. 'May 2' or 'May 2, 2018',
depending on the comparison date (defaults to
Examples
sv
// returns '3 apr'
sinceShort("2018-04-03", "2018-08-12")
// returns '3 apr 2018'
sinceShort("2018-04-03", "2019-08-12")
en (Pug)
// returns 'It was the coldest day since Apr 4, 1966.'
`It was the coldest day since #{sinceShort("1966-04-03", "2010-11-12")}.`
Parameters:
| Name | Type | Attributes | Default | Description |
|---|---|---|---|---|
date_1 |
string | Date | The date to format | ||
date_2 |
string | Date |
<optional> |
today
|
Date used for context |
opts |
object |
<optional> |
Options |
Returns:
A formatted date
- Type
- string
(static) turnOfYear(date, optsopt) → {string}
- Description:
- Descibe year ends
Example
sv
// returns '2017/18'
turnOfYear("2017-12-03")
Parameters:
| Name | Type | Attributes | Description |
|---|---|---|---|
date |
string | Date | to check | |
opts |
object |
<optional> |
Options |
Returns:
A turn-of-year phrase
- Type
- string
(static) weekNumber(date, optsopt) → {number}
- Description:
- Return a (locally correct) week number from a date. NB: This can differ from the ISO week numbers often used in computational settings, even in places where week numbering is done differently! This is more sophisticated than JS Date().getWeek(), but be aware that depending on your data, Date().getWeek() might be what you are really looking for!
Example
sv
// returns 53
weekNumber("2021-01-01")
Parameters:
| Name | Type | Attributes | Description | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|
date |
string | Date | Date to convert to week | |||||||||
opts |
object |
<optional> |
Options
Properties
|
Returns:
A week number
- Type
- number
(static) weekday(dateopt) → {string}
- Description:
- Return the weekday of a given date
Example
sv
// returns 'torsdag'
weekday("2019-01-17")
Parameters:
| Name | Type | Attributes | Default | Description |
|---|---|---|---|---|
date |
Date | string |
<optional> |
today
|
A date string or object |
Returns:
the name of a day
- Type
- string
(static) weekdayFromNumber(index) → {string}
- Description:
- Takes a day index (0,1,2...) and returns a weekday name. 0 is Sunday
Example
sv
// returns 'måndag'
weekdayFromNumber(1)
Parameters:
| Name | Type | Description |
|---|---|---|
index |
string | number | A zero indexed day number |
Returns:
the name of a day
- Type
- string
(static) weekdayShort(dateopt) → {string}
- Description:
- Return an abbreviated weekday string for a given date
Example
sv
// returns 'to'
weekdayShort("2019-01-17")
Parameters:
| Name | Type | Attributes | Default | Description |
|---|---|---|---|---|
date |
Date | string |
<optional> |
today
|
A date string or object |
Returns:
the name of a day
- Type
- string
(static) weekdayShortFromNumber(index) → {string}
- Description:
- Takes a day index (0,1,2...) and returns a weekday name. 0 is Sunday
Example
sv
// returns 'må'
weekdayFromNumber(1)
Parameters:
| Name | Type | Description |
|---|---|---|
index |
string | number | A zero indexed day number |
Returns:
the name of a day
- Type
- string
(static) year(dateopt, optsopt) → {string}
- Description:
- Get year from a date string (or date object)
Examples
en
// returns '2018'
year("2018-01-12")
// returns '2019'
year()
// returns 'MMXVII'
year("2017-12-31", {numberSystem: "roman"})
ja
// returns '2018年'
year("2018-01-12")
Parameters:
| Name | Type | Attributes | Default | Description | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
date |
Year |
<optional> |
today
|
A date like "2018-04-12", or a date object | ||||||||
opts |
object |
<optional> |
Options
Properties
|
Returns:
Year
- Type
- string
(static) yearList(dates, optsopt) → {string}
- Description:
- Use greatest difference logic to list number of dates
Example
sv
// returns '2018'
yearList(["2018-02-03", "2018-02-05", "2018-02-06"])
Parameters:
| Name | Type | Attributes | Description | ||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
dates |
Array.<Year> | a list of dates | |||||||||||||||||||||
opts |
object |
<optional> |
options
Properties
|
Returns:
a list of dates
- Type
- string
(static) yearListOr(dates, optsopt) → {string}
- Description:
- Use greatest difference logic to list number of dates
Example
sv
// returns '2018 eller 2019'
yearListOr(["2018-02-03", "2018-02-05", "2018-02-06", "2019-02-06"])
Parameters:
| Name | Type | Attributes | Description | ||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
dates |
Array.<Year> | a list of dates | |||||||||||||||||||||
opts |
object |
<optional> |
options
Properties
|
Returns:
a list of dates
- Type
- string
(static) yearMonthDays(date_1, date_2opt, optsopt) → {string}
- Description:
- Get the time between two dates expressed in days, months and years We count only full months passed, hence the difference between leap year and common year in the last example.
Example
sv
// returns '1 år, 2 månader och 13 dagar'
yearMonthDays("2018-08-01", "2019-10-14")
Parameters:
| Name | Type | Attributes | Default | Description | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
date_1 |
Date | string | A date string or object | ||||||||||
date_2 |
Date | string |
<optional> |
today
|
A date string or object | ||||||||
opts |
object |
<optional> |
Options
Properties
|
Returns:
describing the number of years and months
- Type
- string
(static) yearMonthDaysPretty(date_1, date_2opt, optsopt) → {string}
- Description:
- Get the time between two dates expressed in days, months and years We count only full months passed, hence the difference between leap year and common year in the last example.
Example
sv
// returns 'ett år, två månader och 13 dagar'
yearMonthDaysPretty("2018-08-01", "2019-10-14")
Parameters:
| Name | Type | Attributes | Default | Description | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
date_1 |
Date | string | A date string or object | ||||||||||||||
date_2 |
Date | string |
<optional> |
today
|
A date string or object | ||||||||||||
opts |
object |
<optional> |
Options
Properties
|
Returns:
describing the number of years and months
- Type
- string
(static) yearMonthDaysText(date_1, date_2opt, optsopt) → {string}
- Description:
- Get the time between two dates expressed in days, months and years We count only full months passed, hence the difference between leap year and common year in the last example.
Example
sv
// returns 'ett år, två månader och tretton dagar'
yearMonthDaysText("2018-08-01", "2019-10-14")
Parameters:
| Name | Type | Attributes | Default | Description | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
date_1 |
Date | string | A date string or object | ||||||||||
date_2 |
Date | string |
<optional> |
today
|
A date string or object | ||||||||
opts |
object |
<optional> |
Options
Properties
|
Returns:
describing the number of years and months
- Type
- string
(static) yearMonths(date_1, date_2opt, optsopt) → {string}
- Description:
- Get the time between two dates expressed in months and years We count only full months passed, hence the difference between leap year and common year in the last example.
Examples
sv
// returns '1 år och 2 månader'
yearMonths("2018-08-01", "2019-10-01")
// returns '1 år'
yearMonths("2018-08-01", "2019-08-01")
// returns '2 månader'
yearMonths("2018-08-01", "2018-10-01")
ja
// returns '1年2ヶ月'
yearMonths("2018-08-01", "2019-10-01")
// returns '一1年二ヶ月'
yearMonths("2018-08-01", "2019-10-01", {numberSystem: "jpan"})
en
// returns '0 months'
yearMonths("2004-01-31", "2004-02-28")
// returns '1 month'
yearMonths("2003-01-31", "2003-02-28")
Parameters:
| Name | Type | Attributes | Default | Description | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
date_1 |
Date | string | A date string or object | ||||||||||
date_2 |
Date | string |
<optional> |
today
|
A date string or object | ||||||||
opts |
object |
<optional> |
Options
Properties
|
Returns:
describing the number of years and months
- Type
- string
(static) yearMonthsPretty(date_1, date_2opt, optsopt) → {string}
- Description:
- Get the time between two dates expressed in months and years, numbers spelled out
Example
sv
// returns 'ett år och två månader'
yearMonthsPretty("2018-08-01", "2019-10-01")
// returns '99 år och två månader'
yearMonthsPretty("1920-08-01", "2019-10-01")
Parameters:
| Name | Type | Attributes | Default | Description | ||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
date_1 |
Date | string | A date string or object | ||||||||||||
date_2 |
Date | string |
<optional> |
today
|
A date string or object | ||||||||||
opts |
object |
<optional> |
Options
Properties
|
Returns:
describing the number of years and months
- Type
- string
(static) yearMonthsText(date_1, date_2opt, optsopt) → {string}
- Description:
- Get the time between two dates expressed in months and years, numbers spelled out
Examples
sv
// returns 'ett år och två månader'
yearMonthsText("2018-08-01", "2019-10-01")
ja
// returns '一1年二ヶ月'
yearMonthsText("2018-08-01", "2019-10-01")
Parameters:
| Name | Type | Attributes | Default | Description | ||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
date_1 |
Date | string | A date string or object | ||||||||||||
date_2 |
Date | string |
<optional> |
today
|
A date string or object | ||||||||||
opts |
object |
<optional> |
Options
Properties
|
Returns:
describing the number of years and months
- Type
- string
(static) yearShort(dateopt, optsopt) → {string}
- Description:
- Minimal year representation
Examples
en
// returns '18'
year("2018-01-12")
ja
// returns '18年'
year("2018-01-12")
Parameters:
| Name | Type | Attributes | Description | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|
date |
string | Date |
<optional> |
Input date | ||||||||
opts |
object |
<optional> |
Options
Properties
|
Returns:
Year
- Type
- string
(static) years(date_1, date_2opt, optsopt) → {string}
- Description:
- Get the number of full years that passed between two dates
Examples
sv
// returns '1 år'
years("2018-08-01", "2019-08-01")
// returns '10 år'
years("2018-01-30", "2028-10-28")
ja
// returns '1年'
years("2018-08-01", "2019-08-01")
// returns '一年'
years("2018-08-01", "2019-08-01", {numberSystem: "jpan"})
Parameters:
| Name | Type | Attributes | Default | Description | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
date_1 |
Date | string | A date string or object | ||||||||||
date_2 |
Date | string |
<optional> |
today
|
A date string or object | ||||||||
opts |
object |
<optional> |
Options
Properties
|
Returns:
describing the number of months
- Type
- string
(static) yearsPretty(date_1, date_2opt, optsopt) → {string}
- Description:
- Get the number of full years that passed between two dates spelling them out for lower numbers, if desired
Example
sv
// returns '199 år'
yearsPretty("1819-08-01", "2019-06-01")
// returns 'ett år'
yearsPretty("2018-01-30", "2019-12-28")
Parameters:
| Name | Type | Attributes | Default | Description | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
date_1 |
Date | string | A date string or object | ||||||||||||||
date_2 |
Date | string |
<optional> |
today
|
A date string or object | ||||||||||||
opts |
object |
<optional> |
Options
Properties
|
Returns:
describing the number of years
- Type
- string
(static) yearsText(date_1, date_2opt, optsopt) → {string}
- Description:
- Get the number of full years that passed between two dates, spelled out
Examples
sv
// returns 'ett år'
yearsText("2018-08-01", "2019-08-01")
// returns 'tio år'
yearsText("2018-01-30", "2028-10-28")
ja
// returns '一年'
yearsText("2018-08-01", "2019-08-01")
Parameters:
| Name | Type | Attributes | Default | Description | ||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
date_1 |
Date | string | A date string or object | ||||||||||||
date_2 |
Date | string |
<optional> |
today
|
A date string or object | ||||||||||
opts |
object |
<optional> |
Options
Properties
|
Returns:
describing the number of months
- Type
- string