Skip to main content
I had failed to notice that the first date in month was specified.
Source Link
anon
anon
strings = {"Thu 30 Mar 2023 08:52:48", 
  "Tue 14 Feb 2023 18:02:16", "Sun 5 Feb 2023 14:44:49", 
  "Sat 7 Jan 2023 14:29:20", "Mon 9 Jan 2023 21:16:06", 
  "Fri 13 Jan 2023 01:11:07", "Sun 4 Sep 2022 10:33:07", 
  "Thu 8 Sep 2022 20:03:03", "Sat 23 Jul 2022 22:24:56", 
  "Fri 29 Jul 2022 01:04:59", "Fri 5 Aug 2022 17:29:07", 
  "Sat 24 Sep 2022 08:18:38"};  

dates = DateObject /@ strings  

(*  
  #1[[2,-1]] & is the function that selects the the last date in month.
  #1[[2,1]] would delect the desired first date in mpnth
*)


AssociationMap[#1[[1]] -> Association[Table[m[[1,2]] -> m[[2]], 
      {m, #1[[2]]}]] & , 
  GroupBy[Normal[AssociationMap[#1[[1]] -> #1[[2,-1]] & , 
     GroupBy[Sort[dates], #1[[1,1 ;; 2]] & ]]], #1[[1,1]] & ]]

Association[2022 -> Association[
    7 -> DateObject[{2022, 7, 29, 1, 4, 59.}, "Instant", 
      "Gregorian", -5.], 8 -> DateObject[{2022, 8, 5, 17, 29, 
       7.}, "Instant", "Gregorian", -5.], 
    9 -> DateObject[{2022, 9, 24, 8, 18, 38.}, "Instant", 
      "Gregorian", -5.]], 
  2023 -> Association[1 -> DateObject[{2023, 1, 13, 1, 11, 7.}, 
      "Instant", "Gregorian", -5.], 
    2 -> DateObject[{2023, 2, 14, 18, 2, 16.}, "Instant", 
      "Gregorian", -5.], 3 -> DateObject[{2023, 3, 30, 8, 52, 
       48.}, "Instant", "Gregorian", -5.]]]

Of course, I may have missed something. An Association is much like a hash map.

strings = {"Thu 30 Mar 2023 08:52:48", 
  "Tue 14 Feb 2023 18:02:16", "Sun 5 Feb 2023 14:44:49", 
  "Sat 7 Jan 2023 14:29:20", "Mon 9 Jan 2023 21:16:06", 
  "Fri 13 Jan 2023 01:11:07", "Sun 4 Sep 2022 10:33:07", 
  "Thu 8 Sep 2022 20:03:03", "Sat 23 Jul 2022 22:24:56", 
  "Fri 29 Jul 2022 01:04:59", "Fri 5 Aug 2022 17:29:07", 
  "Sat 24 Sep 2022 08:18:38"};  

dates = DateObject /@ strings  

AssociationMap[#1[[1]] -> Association[Table[m[[1,2]] -> m[[2]], 
      {m, #1[[2]]}]] & , 
  GroupBy[Normal[AssociationMap[#1[[1]] -> #1[[2,-1]] & , 
     GroupBy[Sort[dates], #1[[1,1 ;; 2]] & ]]], #1[[1,1]] & ]]

Association[2022 -> Association[
    7 -> DateObject[{2022, 7, 29, 1, 4, 59.}, "Instant", 
      "Gregorian", -5.], 8 -> DateObject[{2022, 8, 5, 17, 29, 
       7.}, "Instant", "Gregorian", -5.], 
    9 -> DateObject[{2022, 9, 24, 8, 18, 38.}, "Instant", 
      "Gregorian", -5.]], 
  2023 -> Association[1 -> DateObject[{2023, 1, 13, 1, 11, 7.}, 
      "Instant", "Gregorian", -5.], 
    2 -> DateObject[{2023, 2, 14, 18, 2, 16.}, "Instant", 
      "Gregorian", -5.], 3 -> DateObject[{2023, 3, 30, 8, 52, 
       48.}, "Instant", "Gregorian", -5.]]]

Of course, I may have missed something. An Association is much like a hash map.

strings = {"Thu 30 Mar 2023 08:52:48", 
  "Tue 14 Feb 2023 18:02:16", "Sun 5 Feb 2023 14:44:49", 
  "Sat 7 Jan 2023 14:29:20", "Mon 9 Jan 2023 21:16:06", 
  "Fri 13 Jan 2023 01:11:07", "Sun 4 Sep 2022 10:33:07", 
  "Thu 8 Sep 2022 20:03:03", "Sat 23 Jul 2022 22:24:56", 
  "Fri 29 Jul 2022 01:04:59", "Fri 5 Aug 2022 17:29:07", 
  "Sat 24 Sep 2022 08:18:38"};  

dates = DateObject /@ strings  

(*  
  #1[[2,-1]] & is the function that selects the the last date in month.
  #1[[2,1]] would delect the desired first date in mpnth
*)


AssociationMap[#1[[1]] -> Association[Table[m[[1,2]] -> m[[2]], 
      {m, #1[[2]]}]] & , 
  GroupBy[Normal[AssociationMap[#1[[1]] -> #1[[2,-1]] & , 
     GroupBy[Sort[dates], #1[[1,1 ;; 2]] & ]]], #1[[1,1]] & ]]

Association[2022 -> Association[
    7 -> DateObject[{2022, 7, 29, 1, 4, 59.}, "Instant", 
      "Gregorian", -5.], 8 -> DateObject[{2022, 8, 5, 17, 29, 
       7.}, "Instant", "Gregorian", -5.], 
    9 -> DateObject[{2022, 9, 24, 8, 18, 38.}, "Instant", 
      "Gregorian", -5.]], 
  2023 -> Association[1 -> DateObject[{2023, 1, 13, 1, 11, 7.}, 
      "Instant", "Gregorian", -5.], 
    2 -> DateObject[{2023, 2, 14, 18, 2, 16.}, "Instant", 
      "Gregorian", -5.], 3 -> DateObject[{2023, 3, 30, 8, 52, 
       48.}, "Instant", "Gregorian", -5.]]]

Of course, I may have missed something. An Association is much like a hash map.

Source Link
anon
anon

strings = {"Thu 30 Mar 2023 08:52:48", 
  "Tue 14 Feb 2023 18:02:16", "Sun 5 Feb 2023 14:44:49", 
  "Sat 7 Jan 2023 14:29:20", "Mon 9 Jan 2023 21:16:06", 
  "Fri 13 Jan 2023 01:11:07", "Sun 4 Sep 2022 10:33:07", 
  "Thu 8 Sep 2022 20:03:03", "Sat 23 Jul 2022 22:24:56", 
  "Fri 29 Jul 2022 01:04:59", "Fri 5 Aug 2022 17:29:07", 
  "Sat 24 Sep 2022 08:18:38"};  

dates = DateObject /@ strings  

AssociationMap[#1[[1]] -> Association[Table[m[[1,2]] -> m[[2]], 
      {m, #1[[2]]}]] & , 
  GroupBy[Normal[AssociationMap[#1[[1]] -> #1[[2,-1]] & , 
     GroupBy[Sort[dates], #1[[1,1 ;; 2]] & ]]], #1[[1,1]] & ]]

Association[2022 -> Association[
    7 -> DateObject[{2022, 7, 29, 1, 4, 59.}, "Instant", 
      "Gregorian", -5.], 8 -> DateObject[{2022, 8, 5, 17, 29, 
       7.}, "Instant", "Gregorian", -5.], 
    9 -> DateObject[{2022, 9, 24, 8, 18, 38.}, "Instant", 
      "Gregorian", -5.]], 
  2023 -> Association[1 -> DateObject[{2023, 1, 13, 1, 11, 7.}, 
      "Instant", "Gregorian", -5.], 
    2 -> DateObject[{2023, 2, 14, 18, 2, 16.}, "Instant", 
      "Gregorian", -5.], 3 -> DateObject[{2023, 3, 30, 8, 52, 
       48.}, "Instant", "Gregorian", -5.]]]

Of course, I may have missed something. An Association is much like a hash map.