title: Representing just 'year' and 'year-month' in Clojure/Java
body: <p>I am trying to represent <em>time</em> information that has precision at the scale of <em>year</em> or <em>year-month</em>. Eg. 'patient has a history of fracture of the right wrist in <strong>1998</strong>'; 'history of headaches since <strong>October 2015</strong>'. </p>
  
  <p>I looked at <a href="http://www.joda.org/joda-time/" rel="nofollow">Joda-Time</a> which has <a href="http://www.joda.org/joda-time/apidocs/org/joda/time/YearMonth.html" rel="nofollow">YearMonth</a> <code>org.joda.time.YearMonth</code> but not just 'Year'. But even the YearMonth seems kinda a disconnected. E.g.</p>
  
  <pre><code>(clj-time.core/year-month 2015 02)
  (clj-time.core/date-time  2015 11 15)
  
  =&gt; #object[org.joda.time.YearMonth 0x7a19d121 "2015-02"]
  =&gt; #object[org.joda.time.DateTime 0x5625de93 "2015-11-15T00:00:00.000Z"]
  </code></pre>
  
  <p>and you can do some operations such as: </p>
  
  <pre><code>(clj-time.core/month (clj-time.core/year-month 2015 02))
  (clj-time.core/month (clj-time.core/date-time  2015 11 15))
  
  =&gt; 2
  =&gt; 11
  </code></pre>
  
  <p>but not this:</p>
  
  <pre><code>(clj-time.core/before? (clj-time.core/year-month 2015 02)
                         (clj-time.core/date-time  2015 11 15))
  
  =&gt; Exception thrown: java.lang.ClassCastException (org.joda.time.DateTime 
                       cannot be cast to org.joda.time.ReadablePartial)
  </code></pre>
  
  <p>and similar results with <code>java.time</code>:</p>
  
  <pre><code>(.compareTo (java.time.Year/of 2007) (java.time.LocalDate/now))
  
  =&gt; Exception thrown: java.lang.ClassCastException (java.time.LocalDate
                       cannot be cast to java.time.Year)
  </code></pre>
  
  <p>What I want to be able to do is represent <strong>temporal entities</strong> such as Year and YearMonth at the precision they are - not more, not less, and also do date math with them. E.g.:</p>
  
  <ul>
  <li>The year <strong>1998</strong> would be represented as an <em>interval '01 Jan 1998' to '31 Dec 1998'</em> and <strong>October 2015</strong> as <em>'01 October 2015' to ' 31 October 2015'</em>.</li>
  <li>And <em>be able to compare and do other operations on these <strong>temporal entities</em></strong>. </li>
  </ul>
  
  <p>Has anyone found a good solution for this? Or should I look at building my own solution/library? </p>