September Morn Update
This commit is contained in:
parent
4e2d22a71d
commit
aac6731f2c
6856 changed files with 141342 additions and 21127 deletions
22
Task/Date-manipulation/Factor/date-manipulation.factor
Normal file
22
Task/Date-manipulation/Factor/date-manipulation.factor
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
USING: calendar calendar.english calendar.format calendar.parser
|
||||
combinators io kernel math math.parser sequences splitting
|
||||
unicode ;
|
||||
IN: rosetta-code.date-manipulation
|
||||
|
||||
! e.g. "7:30pm" -> 19 30
|
||||
: parse-hm ( str -- hours minutes )
|
||||
":" split first2 [ digit? ] partition
|
||||
[ [ string>number ] bi@ ] dip "pm" = [ [ 12 + ] dip ] when ;
|
||||
|
||||
! Parse a date in the format "March 7 2009 7:30pm EST"
|
||||
: parse-date ( str -- timestamp )
|
||||
" " split {
|
||||
[ first month-names index 1 + ]
|
||||
[ second string>number ]
|
||||
[ third string>number -rot ]
|
||||
[ fourth parse-hm 0 ]
|
||||
[ last parse-rfc822-gmt-offset ]
|
||||
} cleave <timestamp> ;
|
||||
|
||||
"March 7 2009 7:30pm EST" parse-date dup 12 hours time+
|
||||
[ timestamp>rfc822 print ] bi@
|
||||
|
|
@ -1,9 +1,14 @@
|
|||
import Data.Time.Clock.POSIX
|
||||
import Data.Time.Format
|
||||
import System.Locale
|
||||
import qualified Data.Time.Clock.POSIX as P
|
||||
import qualified Data.Time.Format as F
|
||||
|
||||
-- UTC from EST
|
||||
main :: IO ()
|
||||
main = print t2
|
||||
where t1 = readTime defaultTimeLocale
|
||||
"%B %e %Y %l:%M%P %Z"
|
||||
"March 7 2009 7:30pm EST"
|
||||
t2 = posixSecondsToUTCTime $ 12*60*60 + utcTimeToPOSIXSeconds t1
|
||||
where
|
||||
t1 =
|
||||
F.parseTimeOrError
|
||||
True
|
||||
F.defaultTimeLocale
|
||||
"%B %e %Y %l:%M%P %Z"
|
||||
"March 7 2009 7:30pm EST"
|
||||
t2 = P.posixSecondsToUTCTime $ 12 * 60 * 60 + P.utcTimeToPOSIXSeconds t1
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue