icambron / twix.js

:hourglass::left_right_arrow: A date range plugin for moment.js
https://isaaccambron.com/twix.js/
MIT License
379 stars 54 forks source link

Added ability to hide time and year during formatting. #81

Closed cwperry closed 8 years ago

cwperry commented 8 years ago

Added a showTime formatting option, that when set to false will not show the time components.

For example, using the following:

start = moment('2015-05-21 00:00:00')
end = moment('2015-05-23 11:59:00')

range = start.twix end

range.format
          dayFormat: 'Do'
          implicitMinutes: false
          groupMeridiems: false # May 21st, 12 AM - May 23rd, 11:59 AM, 2015

At the time of creation for my app, I do not know if the two date ranges are all day, so what this change does in the following:

range.format
          dayFormat: 'Do'
          showTime: false # May 21st - May 23rd, 2015

Furthermore, by adding a showYear option, I can hide the year as well:

range.format
          dayFormat: 'Do'
          showTime: false 
          showYear: false # May 21st - May 23rd
icambron commented 8 years ago

Looks good, thanks!

icambron commented 8 years ago

@cwperry I took another look at this, and I'm going to make a few changes. Basically, I'm going to make it behave like this:

        showTime: true         #always/never show the time (unless it's allDay, in which case don't)
        showDate: null         #always/never show the date. By default defer to implictDate setting
        showYear: null         #always/never show the year. By default defer to implictYear setting
        implicitMinutes: true  #hide minutes if they're 00
        implicitDate: false    #hide the date if the range takes place entirely today
        implicitYear: true     #hide the year if range takes place entirely this year

IOW, I found it confusing that while showYear:false does what it says on the tin, showYear:true currently means "use the implicitYear setting to decide whether to show the year" whereas I think it ought to me "no really, show the year". I don't think this will break anything, but I wanted to run it past you since you've just used these options.

icambron commented 8 years ago

Actually, here's what I implemented:

        hideTime: false
        hideYear: false
        implicitMinutes: true
        implicitDate: false
        implicitYear: true

I left in reverse compat:

      options.hideTime = !options.showTime if options.showTime?
      options.hideYear = !options.showYear if options.showYear?
      options.implicitDate = !options.showDate if options.showDate?