Re: Factor

Factor: the language, the theory, and the practice.

Fourth of July

Monday, July 4, 2011

#calendar

Today is Independence Day in the United States. Several lists of fantastic facts are being shared, including that today is the “biggest beer-selling holiday of the year”. However, while not as fantastic, here are a few fun facts about today that can be derived using Factor.

Using the calendar vocabulary, we can create a timestamp object for today’s date:

IN: scratchpad 2011 7 4 <date> .
T{ timestamp
    { year 2011 }
    { month 7 }
    { day 4 }
    { gmt-offset T{ duration { hour -7 } } }
}

We can see that today is the 185th day of the year:

IN: scratchpad 2011 7 4 <date> day-of-year .
185

Today is also the 27th week of the year (using weeks starting on Sunday - there might be a different answer using week-of-year-monday:

IN: scratchpad 2011 7 4 <date> week-of-year-sunday .
27

This year, July 4th falls on a Monday, but its a different day of the week each year. We can see which days of the week Independence Day falls on over the last few years:

IN: scratchpad 2011 2000 [a..b] [
                   dup 7 4 <date> day-name "%s: %s\n" printf
               ] each
2011: Monday
2010: Sunday
2009: Saturday
2008: Friday
2007: Wednesday
2006: Tuesday
2005: Monday
2004: Sunday
2003: Friday
2002: Thursday
2001: Wednesday
2000: Tuesday

And, finally, the most recent version of Factor (0.94) was released on September 18, 2010, which was 289 days ago.

IN: scratchpad 2011 7 4 <date> 2010 9 18 <date>
               time- duration>days .
289