Calendar Date Ranges

Create arrays of dates

Description

Unlike bash, Murex also supports date ranges:

» a [25-dec-2020..05-jan-2021]
» a [..25-dec-2020]
» a [25-dec-2020..]

Please refer to a (mkarray) for more detailed usage of mkarray.

Usage

a: [start..end] -> <stdout>
a: [start..end,start..end] -> <stdout>
a: [start..end][start..end] -> <stdout>

All usages also work with ja and ta as well, eg:

ja: [start..end] -> <stdout>
ta: data-type [start..end] -> <stdout>

You can also inline arrays with the %[] syntax, eg:

%[start..end]

Examples

» a [25-Dec-2020..01-Jan-2021]
25-Dec-2020
26-Dec-2020
27-Dec-2020
28-Dec-2020
29-Dec-2020
30-Dec-2020
31-Dec-2020
01-Jan-2021
» a [31-Dec..25-Dec]
31-Dec
30-Dec
29-Dec
28-Dec
27-Dec
26-Dec
25-Dec

Detail

Current Date

If the start value is missing (eg [..01-Jan-2020]) then mkarray (a et al) will start the range from the current date and count up or down to the end.

If the end value is missing (eg [01-Jan-2020..]) then mkarray will start at the start value, as usual, and count up or down to the current date.

For example, if today was 25th December 2020:

» a [23-December-2020..]
23-December-2020
24-December-2020
25-December-2020
» a [..23-December-2020]
25-December-2020
24-December-2020
23-December-2020

This can lead so some fun like countdowns:

» out "${a: [..01-January-2021] -> len -> =-1} days until the new year!"
7 days until the new year!

Case Sensitivity

Date ranges are case aware. If the ranges are uppercase then the return will be uppercase. If the ranges are title case (capital first letter) then the return will be in title case.

lower case

» a [01-jan..03-jan]
01-jan
02-jan
03-jan

Title Case

» a [01-Jan..03-Jan]
01-Jan
02-Jan
03-Jan

UPPER CASE

» a [01-JAN..03-JAN]
01-JAN
02-JAN
03-JAN

Supported Date Formatting

Below is the source for the supported formatting options for date ranges:

package mkarray

var dateFormat = []string{
    // dd mm yy

    "02-Jan-06",
    "02-January-06",
    "02-Jan-2006",
    "02-January-2006",

    "02 Jan 06",
    "02 January 06",
    "02 Jan 2006",
    "02 January 2006",

    "02/Jan/06",
    "02/January/06",
    "02/Jan/2006",
    "02/January/2006",

    // mm dd yy

    "Jan-02-06",
    "January-02-06",
    "Jan-02-2006",
    "January-02-2006",

    "Jan 02 06",
    "January 02 06",
    "Jan 02 2006",
    "January 02 2006",

    "Jan/02/06",
    "January/02/06",
    "Jan/02/2006",
    "January/02/2006",

    // dd mm

    "02-Jan",
    "02-January",

    "02 Jan",
    "02 January",

    "02/Jan",
    "02/January",
}

If you do need any other formatting options not supported there, you can use datetime to convert the output of a. eg:

» a [01-Jan-2020..03-Jan-2020] -> foreach { -> datetime --in "{go}02-Jan-2006" --out "{py}%A, %d %B"; echo }
Wednesday, 01 January
Thursday, 02 January
Friday, 03 January

See Also


This document was generated from builtins/core/mkarray/ranges_doc.yaml.

This site's content is rebuilt automatically from murex's source code after each merge to the master branch. Downloadable murex binaries are also built with the website.

Last built on Wed Sep 18 21:18:57 UTC 2024 against commit c037883c03788357164e9846c84d9f777251495d9452a8e.

Current version is 6.3.4225 (develop) which has been verified against tests cases.