print dates in reversed order

2021-06-01 Thread euant
If you know the number of entries up front, you can also do something like this and pre-allocate the sequence: import times, algorithm const limit = 3 let today = now() var sq = newSeq[string](limit) for i in 1..3: var duration = initDuration(days = i)

print dates in reversed order

2021-06-01 Thread enthus1ast
you can use countdown: import times, algorithm var today = now() var sq: seq[string] for i in countdown(3, 1): var duration = initDuration(days = i) var next_day = today + duration sq.add($next_day.format(", dd-MMM-")) for e in sq:

print dates in reversed order

2021-06-01 Thread bunkford
If the dates in your seq are stored as "-MM-dd" you can sort them alphanumerically using `sort`. Then I converted them back to the format you used incase that is a requirement. import algorithm, sequtils, times var dates = @["2021-05-31", "1972-07-01", "2020-01-31", "19

print dates in reversed order

2021-05-29 Thread treeform
Using my chrono ( ) library and countdown you can go pretty short: import chrono, times for i in countdown(2, 0): var cal = Timestamp(epochTime()).calendar cal.add(Day, i) echo cal.format("{weekday}, {day/2}-{month/n/3}-{yea

print dates in reversed order

2021-05-29 Thread fengkehh
Not so much about idiomatic/shorter, but more for performance/efficiency. IIRC `reversed` returns a new seq and therefore requires allocation. Use `reverse` to do reversal in place. Or you can do a for loop on the index in decreasing order to avoid reverse altogether. Also, if you know the numb

print dates in reversed order

2021-05-29 Thread masiarek2
Any improvements, shorter, more idiomatic (golf?) Nim? import times, algorithm var today = now() var sq: seq[string] for i in 1..3: var duration = initDuration(days = i) var next_day = today + duration sq.add($next_day.format(", dd-MMM-"))