! Copyright (C) 2008 John Benediktsson
! See http://factorcode.org/license.txt for BSD license
USING: accessors arrays assocs calendar calendar.english
-combinators combinators.smart generalizations io
-io.streams.string kernel math math.functions
+calendar.private combinators combinators.smart generalizations
+io io.streams.string kernel math math.functions
math.functions.integer-logs math.parser multiline namespaces
peg.ebnf present prettyprint quotations sequences
sequences.generalizations splitting strings unicode ;
sign_ = [+ ] => [[ '[ dup first CHAR: - = [ _ prefix ] unless ] ]]
sign = (sign_)? => [[ [ ] or ]]
-width_ = "." ([0-9])* => [[ second >digits '[ _ short head ] ]]
+width_ = "." ([0-9])* => [[ second >digits '[ _ index-or-length head ] ]]
width = (width_)? => [[ [ ] or ]]
digits_ = "." ([0-9])* => [[ second >digits ]]
formats = "%" (types|fmt-%|lists|assocs|unknown) => [[ second ]]
-plain-text = (!("%").)+ => [[ >string ]]
+plain-text = [^%]+ => [[ >string ]]
text = (formats|plain-text)*
[ >time ]
[ year>> number>string ]
} cleave
- ] output>array unwords ; inline
+ ] output>array join-words ; inline
: week-of-year ( timestamp day -- n )
- [ dup clone 1 >>month 1 >>day day-of-week dup ] dip > [ 7 swap - ] when
- [ day-of-year ] dip 2dup < [ 0 2nip ] [ - 7 / 1 + >fixnum ] if ;
+ [ dup clone first-day-of-year dup clone ]
+ [ day-this-week ] bi* swap '[ _ time- duration>days ] bi@
+ dup 0 < [ 7 + - ] [ drop ] if 7 + 7 /i ;
: week-of-year-sunday ( timestamp -- n ) 0 week-of-year ; inline
formats = "%" (formats_) => [[ second ]]
-plain-text = (!("%").)+ => [[ >string ]]
+plain-text = [^%]+ => [[ >string ]]
text = (formats|plain-text)*