AltME: REBOL3

Messages

GiuseppeC
How could I find the corresponding date for:
"The monday of 2 weeks ago"
"The next sunday"
"The last day of the current/next/prev month ?"
Ashley
The monday of 2 weeks ago ... either now/weekday = 1 [now - 14][now - (6 + now/weekday)]
The next sunday ... either now/weekday = 7 [now + 7][now + (7 - now/weekday)]
The last day of the current/next/prev month ... http://www.rebol.org/view-script.r?script=date-time.r

Gregg
Giuseppe, individual date calcs are relatively easy. Designing a dialect to interpret human expressions of them is more work, though still doable. I have a number of things that do part of it, but no complete, open system I can post.
Watch for boundary issues. Here are a couple helpers that show what I mean.
set 'last-day-of-month func [date /local d] [
    d: date
    d/day: 1
    d/month: d/month + 1
    d: d - 1
    d
]
set 'same-day-next-month func [date /local d] [
    d: date
    d/month: d/month + 1
    if d/day < date/day [d: d - d/day]
    d
]
GiuseppeC
Ashley, how if I need to calculate a generic monday of N weeks AGO
or
sunday of N weeks in the future ?
Gregg
What have you tried so far Giuseppe?
GiuseppeC
I am currently working on it on the consolle
GiuseppeC
dayofweek: 1
date:  either now/weekday = dayofweek [now - (7 * (weeks - 1))] [now - (((7 * (weeks - 1)) - either now/weekday = 1 [now - (7 * (weeks - 1))] [now - (((7 * (weeks - 1)) -  dayofweek) + now/weekday)]
GiuseppeC
Ooops... to many copies
The following code returns the dayofweek of /weeks/ ago
        dayofweek: 1
        weeks: 2
        date: either now/weekday = dayofweek
            [now - (7 * (weeks - 1))]
            [now - (((7 * (weeks - 1)) -  dayofweek) + now/weekday)]
GiuseppeC
Note that this formula is dangerous when you want to filter something from a start to and date because it includes TIME!
now should be changed to now/date
DideC
I have a generic calculation for dates:   date-of-monday: a-date + 1 - a-date/weekday
If you need a sunday, it become:   date-of-sunday: a-date + 7 - a-date/weekday
Then just add or remove (weeks  * 7)

GiuseppeC
Interesting
Arnold
What should same-day-next-month be today?

Gregg
That would be open to interpretation on a day like today. My call, when I wrote that func, was to use the last day of the month, if the next month has less days than the target month.
Alternately, you could throw an error or return none.
Arnold
Yes depends on what you want it to be.

Ashley
>> col: 1
>> do z: compose/deep [foreach row [[A]] [(to-path join "row/" col)]]
** Script error: cannot access end! in path row/1
** Where: foreach do
** Near: foreach row [[A]] [row/1]
>> z
== [foreach row [[A]] [row/1]]
>> type? first p: [row/1]                                
== path!
>> do z: compose/deep [foreach row [[A]] [(pick p col)]]
== A
>> z
== [foreach row [[A]] [row/1]]
How to get first example working? ... and then for set-path! (i.e. row/1:)
DocKimbel
TO-PATH on a string! value is not doing what you expect:
>> length? to-path "a/b"
== 1
Just replace it with LOAD and it will work fine.
And alternative way to achieve it without using strings: (append to-path 'row col)

Last message posted 164 weeks ago.