murtaza52
murtaza52

Reputation: 47441

testing a datetime object or how to use a reader form in code

I have the following midje code -

(fact "Parsing the date received from github" (parse-date "2013-02-20T17:24:33Z") => #<DateTime 2013-02-20T17:24:33.000Z>)

I am trying to test a function which when given a string returns a date time object (joda time using the clj-time lib).

How do I represent the date time object #<DateTime 2013-02-20T17:24:33.000Z> in code, so that it doesnt throw error java.lang.RuntimeException: Unreadable form, compiling:(mashup/github.clj:11)

Upvotes: 1

Views: 171

Answers (2)

Andrew
Andrew

Reputation: 7516

You could use the #inst reader macro:

user=> #inst "2013-02-20T17:24:33.000Z"
#inst "2013-02-20T17:24:33.000-00:00"

Upvotes: 2

sw1nn
sw1nn

Reputation: 7328

clj-time has constructor functions for this:

user> (use 'clj-time.core)
nil
user> (date-time 2013 02 20 17 24 33)
#<DateTime 2013-02-20T17:24:33.000Z>

so your midje fact would look like:

(fact "Parsing the date received from github" (parse-date "2013-02-20T17:24:33Z") 
   => (date-time 2013 02 20 17 24 33))

Upvotes: 2

Related Questions