Create arrays of dates
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.
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]
» 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
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!
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.
» a [01-jan..03-jan]
01-jan
02-jan
03-jan
» a [01-Jan..03-Jan]
01-Jan
02-Jan
03-Jan
» a [01-JAN..03-JAN]
01-JAN
02-JAN
03-JAN
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
count
): Count items in a map, list or arrayja
): A sophisticated yet simply way to build a JSON arrayta
): A sophisticated yet simple way to build an array of a user defined data-typedatetime
): A date and/or time conversion tool (like printf
but for date and time values)[ ..Range ]
: Outputs a ranged subset of data from stdin[[ Element ]]
): Outputs an element from a nested structuremtac
): Reverse the order of an arraya
): A sophisticated yet simple way to stream an array or list (mkarray)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.