weeksOf
This method is useful when you want to get weeks from the given input, for example, when rendering calendar.
Default implementation can be seen in the Calendar UI.
Usage
What information you can get? See the interface IWeeks
- input date
- current date (real
now
) - start date (where is the first week of the month, or applied margin)
- end date (where is the last week of the month, or applied margin)
Luxon
Interval (opens in a new tab) ofstart
toend
isCurrent
tells you if the current interval matchesnow
(so you see current month)- localised list of days (no need for translations)
- list of weeks: they matches number of weeks on
input
month plus margins if specified - every week has its days (see
IWeek
andIDay
interface)
Code
Just simply call weeksOf()
and you'll get calendar data (weeks) of the given input in the month of the input.
import {DateTime, weeksOf} from "@leight/i18n";
const weeks = weeksOf({input: DateTime.now()});
Example output
This output is JSON.stringify()
of the IWeeks
interface, so there will be little differences, but this is just an example what
you can get.
{
"input": "2023-04-02T01:54:13.458+02:00",
"now": "2023-04-02T01:54:13.459+02:00",
"start": "2023-03-25T00:00:00.000+01:00",
"end": "2023-05-07T23:59:59.999+02:00",
"interval": {
"s": "2023-03-25T00:00:00.000+01:00",
"e": "2023-05-07T23:59:59.999+02:00",
"invalid": null,
"isLuxonInterval": true
},
"isCurrent": true,
"days": [
"po",
"út",
"st",
"čt",
"pá",
"so",
"ne"
],
"weeks": [
{
"id": "202312",
"week": "2023-03-20T00:00:00.000+01:00",
"number": 12,
"current": false,
"days": [
{
"id": "2023120",
"day": "2023-03-20T00:00:00.000+01:00",
"current": false,
"outOfRange": true
},
{
"id": "2023121",
"day": "2023-03-21T00:00:00.000+01:00",
"current": false,
"outOfRange": true
},
{
"id": "2023122",
"day": "2023-03-22T00:00:00.000+01:00",
"current": false,
"outOfRange": true
},
{
"id": "2023123",
"day": "2023-03-23T00:00:00.000+01:00",
"current": false,
"outOfRange": true
},
{
"id": "2023124",
"day": "2023-03-24T00:00:00.000+01:00",
"current": false,
"outOfRange": true
},
{
"id": "2023125",
"day": "2023-03-25T00:00:00.000+01:00",
"current": false,
"outOfRange": true
},
{
"id": "2023126",
"day": "2023-03-26T00:00:00.000+01:00",
"current": false,
"outOfRange": true
}
]
},
{
"id": "202313",
"week": "2023-03-27T00:00:00.000+02:00",
"number": 13,
"current": true,
"days": [
{
"id": "2023130",
"day": "2023-03-27T00:00:00.000+02:00",
"current": false,
"outOfRange": true
},
{
"id": "2023131",
"day": "2023-03-28T00:00:00.000+02:00",
"current": false,
"outOfRange": true
},
{
"id": "2023132",
"day": "2023-03-29T00:00:00.000+02:00",
"current": false,
"outOfRange": true
},
{
"id": "2023133",
"day": "2023-03-30T00:00:00.000+02:00",
"current": false,
"outOfRange": true
},
{
"id": "2023134",
"day": "2023-03-31T00:00:00.000+02:00",
"current": false,
"outOfRange": true
},
{
"id": "2023135",
"day": "2023-04-01T00:00:00.000+02:00",
"current": false,
"outOfRange": false
},
{
"id": "2023136",
"day": "2023-04-02T00:00:00.000+02:00",
"current": true,
"outOfRange": false
}
]
},
{
"id": "202314",
"week": "2023-04-03T00:00:00.000+02:00",
"number": 14,
"current": false,
"days": [
{
"id": "2023140",
"day": "2023-04-03T00:00:00.000+02:00",
"current": false,
"outOfRange": false
},
{
"id": "2023141",
"day": "2023-04-04T00:00:00.000+02:00",
"current": false,
"outOfRange": false
},
{
"id": "2023142",
"day": "2023-04-05T00:00:00.000+02:00",
"current": false,
"outOfRange": false
},
{
"id": "2023143",
"day": "2023-04-06T00:00:00.000+02:00",
"current": false,
"outOfRange": false
},
{
"id": "2023144",
"day": "2023-04-07T00:00:00.000+02:00",
"current": false,
"outOfRange": false
},
{
"id": "2023145",
"day": "2023-04-08T00:00:00.000+02:00",
"current": false,
"outOfRange": false
},
{
"id": "2023146",
"day": "2023-04-09T00:00:00.000+02:00",
"current": false,
"outOfRange": false
}
]
},
{
"id": "202315",
"week": "2023-04-10T00:00:00.000+02:00",
"number": 15,
"current": false,
"days": [
{
"id": "2023150",
"day": "2023-04-10T00:00:00.000+02:00",
"current": false,
"outOfRange": false
},
{
"id": "2023151",
"day": "2023-04-11T00:00:00.000+02:00",
"current": false,
"outOfRange": false
},
{
"id": "2023152",
"day": "2023-04-12T00:00:00.000+02:00",
"current": false,
"outOfRange": false
},
{
"id": "2023153",
"day": "2023-04-13T00:00:00.000+02:00",
"current": false,
"outOfRange": false
},
{
"id": "2023154",
"day": "2023-04-14T00:00:00.000+02:00",
"current": false,
"outOfRange": false
},
{
"id": "2023155",
"day": "2023-04-15T00:00:00.000+02:00",
"current": false,
"outOfRange": false
},
{
"id": "2023156",
"day": "2023-04-16T00:00:00.000+02:00",
"current": false,
"outOfRange": false
}
]
},
{
"id": "202316",
"week": "2023-04-17T00:00:00.000+02:00",
"number": 16,
"current": false,
"days": [
{
"id": "2023160",
"day": "2023-04-17T00:00:00.000+02:00",
"current": false,
"outOfRange": false
},
{
"id": "2023161",
"day": "2023-04-18T00:00:00.000+02:00",
"current": false,
"outOfRange": false
},
{
"id": "2023162",
"day": "2023-04-19T00:00:00.000+02:00",
"current": false,
"outOfRange": false
},
{
"id": "2023163",
"day": "2023-04-20T00:00:00.000+02:00",
"current": false,
"outOfRange": false
},
{
"id": "2023164",
"day": "2023-04-21T00:00:00.000+02:00",
"current": false,
"outOfRange": false
},
{
"id": "2023165",
"day": "2023-04-22T00:00:00.000+02:00",
"current": false,
"outOfRange": false
},
{
"id": "2023166",
"day": "2023-04-23T00:00:00.000+02:00",
"current": false,
"outOfRange": false
}
]
},
{
"id": "202317",
"week": "2023-04-24T00:00:00.000+02:00",
"number": 17,
"current": false,
"days": [
{
"id": "2023170",
"day": "2023-04-24T00:00:00.000+02:00",
"current": false,
"outOfRange": false
},
{
"id": "2023171",
"day": "2023-04-25T00:00:00.000+02:00",
"current": false,
"outOfRange": false
},
{
"id": "2023172",
"day": "2023-04-26T00:00:00.000+02:00",
"current": false,
"outOfRange": false
},
{
"id": "2023173",
"day": "2023-04-27T00:00:00.000+02:00",
"current": false,
"outOfRange": false
},
{
"id": "2023174",
"day": "2023-04-28T00:00:00.000+02:00",
"current": false,
"outOfRange": false
},
{
"id": "2023175",
"day": "2023-04-29T00:00:00.000+02:00",
"current": false,
"outOfRange": false
},
{
"id": "2023176",
"day": "2023-04-30T00:00:00.000+02:00",
"current": false,
"outOfRange": false
}
]
},
{
"id": "202318",
"week": "2023-05-01T00:00:00.000+02:00",
"number": 18,
"current": false,
"days": [
{
"id": "2023180",
"day": "2023-05-01T00:00:00.000+02:00",
"current": false,
"outOfRange": true
},
{
"id": "2023181",
"day": "2023-05-02T00:00:00.000+02:00",
"current": false,
"outOfRange": true
},
{
"id": "2023182",
"day": "2023-05-03T00:00:00.000+02:00",
"current": false,
"outOfRange": true
},
{
"id": "2023183",
"day": "2023-05-04T00:00:00.000+02:00",
"current": false,
"outOfRange": true
},
{
"id": "2023184",
"day": "2023-05-05T00:00:00.000+02:00",
"current": false,
"outOfRange": true
},
{
"id": "2023185",
"day": "2023-05-06T00:00:00.000+02:00",
"current": false,
"outOfRange": true
},
{
"id": "2023186",
"day": "2023-05-07T00:00:00.000+02:00",
"current": false,
"outOfRange": true
}
]
}
]
}