Proposal-temporal: CivilDate without day or day and month?

Created on 21 Mar 2018  路  4Comments  路  Source: tc39/proposal-temporal

I was working on the resume page of my new personal website last weekend. What I wanted to do was, keep the information in an object and generate a view from that object.

So the data I had was like:

  • Appleseed University, 2010 - 2014
  • Contoso Ltd, Feb 2015 - May 2017

And my object looked like this:

const obj = {
  education: [
    {
      name: "Appleseed University",
      start: "2010",
      end: "2014"
    }
  ],
  work: [
    {
      name: "Contoso Ltd",
      start: "Feb 2015",
      end: "May 2017"
    }
  ]
}

If I convert start and ends to Date, they will become full dates and I will not be able to know if I should print the day or month in my view.

So how do I store just "2010" or "Feb 2015"? Could null be allowed for CivilDate's month and day arguments?

behavior question

Most helpful comment

JodaTime has a year month format IIRC. It would certainly be introduce-able later, but I guess I feel like there are enough things at play right now?

All 4 comments

JodaTime has a year month format IIRC. It would certainly be introduce-able later, but I guess I feel like there are enough things at play right now?

I think this would be a good thing, but it shouldn't be part of CivilDate. Let's think more on this and add it later, though we need to keep it in mind so as to not do things now that would eliminate the option to add it.

This functionality made it in as YearMonth and MonthDay.

That looks a bit like unintended behavior for a date: Having a string with not enough information to be a date but being treated like a date just for the sake of formatted output. There's a good reason why most libraries and implementations store both date string/object and mask/format.

Was this page helpful?
0 / 5 - 0 ratings