I work with a list containing DateObjects. I want to transform the dateobject to a "Month". The list contains 6 parts.
Fot simplicity, the list looks like:
test = {{"ASX", 15, DateObject[{2021, 03, 08}], "buy", "F", 21.95} , {"ASX", 15, DateObject[{2021, 03, 08}], "buy", "F", 21.95} , {"ASX", 15, DateObject[{2021, 03, 08}], "buy", "F", 21.95} , {"ASX", 15, DateObject[{2021, 03, 08}], "buy", "F", 21.95} , {"ASX", 15, DateObject[{2021, 03, 08}], "buy", "F", 21.95} , {"ASX", 15, DateObject[{2021, 03, 08}], "buy", "F", 21.95}};
The transformation rule is like:
test /. {a_, b_, c_, d_, e_, f_} -> {a, b, DateObject[c, "Month"], d, e, f};
The output is:
{ {"ASX", 15, DateObject[{2021, 3, 8}], "buy", "F", 21.95} , {"ASX", 15, DateObject[{2021, 3, 8}], "buy", "F", 21.95} , DateObject[{"ASX", 15, DateObject[{2021, 3, 8}], "buy", "F", 21.95}, "Month"] , {"ASX", 15, DateObject[{2021, 3, 8}], "buy", "F", 21.95} , {"ASX", 15, DateObject[{2021, 3, 8}], "buy", "F", 21.95} , {"ASX", 15, DateObject[{2021, 3, 8}], "buy", "F", 21.95}}
It goes wrong with the third element of the list.
DateObject[{"ASX", 15, DateObject[{2021, 3, 8}], "buy", "F", 21.95}, "Month"]
When the original list contains 5 elements or 7 elements, the output is correct. When the list contains the same number of elements as the parameters a, b, ... f_ then something goes wrong.
For example:
test5 = {{"ASX", 15, DateObject[{2021, 03, 08}], "buy", "F",
21.95}, {"ASX", 15, DateObject[{2021, 03, 08}], "buy", "F",
21.95}, {"ASX", 15, DateObject[{2021, 03, 08}], "buy", "F",
21.95}, {"ASX", 15, DateObject[{2021, 03, 08}], "buy", "F",
21.95}, {"ASX", 15, DateObject[{2021, 03, 08}], "buy", "F",
21.95}};
test5 /. {a_, b_, c_, d_, e_, f_} -> {a, b, DateObject[c, "Month"], d, e, f}
test7 = {{"ASX", 15, DateObject[{2021, 03, 08}], "buy", "F",
21.95}, {"ASX", 15, DateObject[{2021, 03, 08}], "buy", "F",
21.95}, {"ASX", 15, DateObject[{2021, 03, 08}], "buy", "F",
21.95}, {"ASX", 15, DateObject[{2021, 03, 08}], "buy", "F",
21.95}, {"ASX", 15, DateObject[{2021, 03, 08}], "buy", "F",
21.95}, {"ASX", 15, DateObject[{2021, 03, 08}], "buy", "F",
21.95}, {"ASX", 15, DateObject[{2021, 03, 08}], "buy", "F",
21.95}};
test7 /. {a_, b_, c_, d_, e_, f_} -> {a, b, DateObject[c, "Month"], d, e, f}
The transformations with 5 and 7 elements in de list are correct. When the list containts 6 elements, it's goes wrong.
When I use a different a transformation like
Map[ {#[[1]], #[[2]], DateObject[#[[3]], "Month"], #[[4]], #[[5]], #[[6]]} &, test]
Then I don't have any problem.
I would like to understand what's wrong with the first transformation, and why it goes wrong when there is a relation with the number of elements in the list. Anyone a suggestion?