title: "moment" format date with only a year or month and a year
body: <p>I have a string that represents a date in format of "YYYYMMDD", I need to format it to a different format.</p>
  
  <p>I am using moment.</p>
  
  <pre><code>import moment from 'moment';
  
  getDateStr(date: string, format){
      return moment(date, 'YYYYMMDD').format(format);
  }
  </code></pre>
  
  <p>The problem is that if a get a partial date the string is rapped with "01" instead of the missing parameters.</p>
  
  <p>For example if format is "YYYY-MM-DD" and the date is "201003" I get "2010-03-01", I want to get "2010-03".</p>
  
  <p>How can I make it work in a generic way?</p>