I don't have Factor installed on this machine, so I can't test my
suggestions. But I'll do my best.

`today` is defined as `now midnight` -
http://docs.factorcode.org/content/word-today,calendar.html

Notice that `now` uses `gmt`, then sets the offset -
http://docs.factorcode.org/content/word-now,calendar.html

Thus, instead of `today 0 hours >>gmt-offset` I think you can just say `gmt
midnight`.

`ymd>timestamp` seems to be exactly what you need for converting a YMD
string to a timestamp, so let's leave that part alone. :)

Now, we can pay attention to the general pattern of this code. If it
weren't for the GMT offset, most of your snippet would look like `now
"2014-08-31" ymd>timestamp time-`.  This pattern of subtracting a timestamp
or duration from the current time is exactly encapsulated by the `ago` word
- http://docs.factorcode.org/content/word-ago%2Ccalendar.html (due to the
fact that `time-` can apply to a timestamp as well -
http://docs.factorcode.org/content/word-time-%2Ccalendar.html)

That is, if it weren't for the GMT bit, you could just say `"2014-08-31"
ymd>timestamp ago duration>days`.  In fact, that would make a nice word: `:
days-ago ( timestamp -- days ) ago duration>days ;`

(Not sure I would name it `days-ago`, since that's similar to `days ago`,
which has a different meaning...but I can't think of a better name.)

However, there's the GMT hangup.  I'm not smart enough right now to reason
about whether you could just use `ago >gmt` and get the right results, but
I'd try it - http://docs.factorcode.org/content/word-__gt__gmt,calendar.html

Hope any of that helps or gives you some ideas. Let us know what you come
up with!



On Tue, Sep 2, 2014 at 9:02 AM, Georg Simon <georg.si...@auge.de> wrote:

> today "2014-08-31" ymd>timestamp time- duration>days .
>
> prints 1+11/12
> as we are 2 hours earlier than gmt I guess.
>
> today 0 hours >>gmt-offset "2014-08-31" ymd>timestamp time-
> duration>days .
>
> prints 2
> which is what I want.
>
> Is there a better way to calculate how many days ago a YYYY-MM-DD
> string means ?
>
> Georg
>
>
> ------------------------------------------------------------------------------
> Slashdot TV.
> Video for Nerds.  Stuff that matters.
> http://tv.slashdot.org/
> _______________________________________________
> Factor-talk mailing list
> Factor-talk@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/factor-talk
>
------------------------------------------------------------------------------
Slashdot TV.  
Video for Nerds.  Stuff that matters.
http://tv.slashdot.org/
_______________________________________________
Factor-talk mailing list
Factor-talk@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/factor-talk

Reply via email to