You can customize and control everything.

Calentim is a Date/Time Range Picker plugin, built using jQuery and moment.js libraries. You can use it as a date time range picker, as a date picker, or as a time picker. You can show it inline, or use as a dropdown for any element.

Get it from CodeCanyon

Features

Date Time Range Picker

It's a range picker, with time!

Predefined Ranges

You can use default ranges, or define your own!

Single Date Time Selection Support

It can also be used as a single date time picker!

Customizable

You can modify all the picker's behaviour like hiding some part, disabling some feature etc.

Quick Switching

Supports fast month and year navigation!

Inline Support

If you don't like dropdowns, you can convert your input to an inline calendar!

Mobile Ready

It renders beautifully on mobile devices

Portrait/Landscape Support

Also has a different landscape layout

Touch Slide Support

You can slide between months!

109 Languages

We support them all!
(What moment.js supports :P)

Sass Support

You can re-design completely using SASS.

Grunt Tasks

Yes, it's the automation era.

Icons (except Sass and Grunt logo) made by Freepik from www.flaticon.com is licensed by CC 3.0 BY

How to use it

The main files of this plugin are calentim.min.js and calentim.min.css, which are generated by compiling and minifying calentim.js and calentim.css. The plugin relies on jQuery and moment.js libraries, also needs to be included before including calentim.min.js.

The font used on this plugin is Roboto, and the icons are provided by Font Awesome which are included remotely from their CDN's. You can change it anyway you want.

The example configuration which can be found in the base index file is:

<link href="https://fonts.googleapis.com/css?family=Roboto:300,400,400i,500,700" rel="stylesheet"/>
<link href="http://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet"/>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/2.1.4/jquery.min.js"></script>
<script>window.jQuery || document.write('<script src="js/jquery-2.1.4.min.js" type="text/javascript"><\/script>');
</script>
<!-- .calentim includes -->
<link href="build/css/calentim.min.css" rel="stylesheet"/>
<script src="build/js/moment.min.js"></script>
<script src="build/js/calentim.min.js"></script>
<!-- .end calentim includes -->

Then, to attach a Calentim object to an element you desire, use this:

$(".calentim").calentim();

You can customize your plugin with options you provide to the initializing function,

$(".calentim").calentim({inline: true, startOnMonday: true});

or the element's data-plugin-options property.

<input class="calentim" data-plugin-options='{"calendarCount":1,"showHeader":true,"showFooter":true}'
name="calendar-input" type="text" value="08.08.2017 12:43 - 08.09.2017 13:11"/>

Once initalized, you can access the calentim object like this:

var calentim = $(".calentim:eq(3)").data("calentim");
calentim.config.startDate = new Date();
calentim.reDrawCalendars();

Properties

Once you've got the calentim instance object, you can access these properties:

  • elem [DOM node object]: The HTML dom node which the instance is created on.
  • $elem [jQuery Object]: jQuery object of the dom node. Equals to $(calentim.elem)



Please Note that if you've chosen a different target element, you will be accessing the initiator element by calling calentim.$elem. Your actual target element would be calentim.config.target.

For example,

    var calentim = $("#elem1").calentim();
    // calentim.elem will be equal to document.getElementById("elem1") or $("#elem1").get(0);
    // calentim.$elem will be equal to $("#elem1");



  • config [JS Object]: The instance's configuration object. Consists of merging default values and user defined settings. The details of it is explained in the Options section.



These properties are also defined, but not recommended to tinker on.

  • container [jQuery Object]: This refers to the outermost container element of the instance dropdown or inline instance and the input itself.
  • header [jQuery Object]: This refers to the header part of the plugin.
  • footer [jQuery Object]: This refers to the footer part, - not the mobile buttons part - the ranges part of the plugin.
  • input [jQuery Object]: This refers to the first child of the container, which contains everything except the input which is calentim instantiated on.

Configuration

These are the options you can set with the javascript plugin initialization object, or with the data-plugin-options html attribute on the input element, or within the events by directly modifying the calentim.config object.

  • startDate [moment object|javascript Date Object|string]: the selected start date, initially today is selected if not defined inside the input's value, or any of the initialization configuration methods.

  • endDate [moment object|javascript Date Object|string]: the selected end date, initially today is selected if not defined inside the input's value, or any of the initialization configuration methods.

  • format [string]: the default format for showing in input, defaults to short date format of locale, for all possible inputs, look here: https://momentjs.com/docs/#/displaying/format/ default: 'L LT'

  • hourFormat [number]: the format for the time pickers. Can be 12 or 24, if set anything else, will revert to default 24. default '24'

    Note: Be careful when setting this option, you might need to pick a suitable format for the format variable too. For example, you might set 12 hour calendar with L HH:mm format, and then receive 24 hour data on your backend.

  • minuteSteps [number]: the minute steps you want to show on your minute picker, for example, if you set 15 as the step, you'll get 0, 15, 30 and 45 in your minute picker. Default: 1

  • dateSeparator [string]: if not used as a single date picker, this will be the seperator, default " - ".

  • calendarCount [integer]: how many calendars will be shown in the plugin screen, default 2

  • inline [boolean]: display as an inline input replacement instead of input dropdown. default: false

  • minDate [moment object|javascript Date Object|string|null]: minimum selectable date, default null (no minimum)

  • maxDate [moment object|javascript Date Object|string|null]: maximum selectable date, default null (no maximum)

  • showHeader [boolean]: visibility of the part which displays the selected start and end dates, default true

  • showFooter [boolean]: visibility of the part which contains user defined ranges, default true

  • showButtons [boolean]: whether the input should display the apply and cancel buttons in dropdown, default false

  • startEmpty [boolean]: whether the input should remain empty until user makes a selection, default false

  • enableKeyboard [boolean]: enable this if you want to add keyboard support to the calendar. The keys are:
    • UP : Go to same weekday on the previous week
    • DOWN : Go to same weekday on the next week
    • LEFT : Go to the previous day
    • RIGHT : Go to the next day
    • PG UP : Go to the previous month
    • PG DOWN : Go to the next month
    • SHIFT + PG UP : Go to the previous year
    • SHIFT + PG DOWN : Go to the next year

  • startOnMonday [boolean]: false, // if you want to start the calendars on Monday, set this to true. Note that if the locale already starts on Monday, this setting will be ignored.

  • container [string]: the selector of the dropdowns container, default "body"

  • oneCalendarWidth [integer]: the width of one calendar, if two calendars are shown, the input width will be 2 * this setting. default 230

  • showOn ["bottom"|"top"|"left"|"right"|"center"]: dropdown placement position relative to input element, will be adjusted to the viewport, default "bottom"

  • arrowOn ["bottom"|"top"|"left"|"right"|"center"]: arrow position relative to dropdown element, will be adjusted to the viewport, default "left"

  • autoAlign [boolean]: enables dropdown auto placement change when the dropdown is not fully visible on the viewport. Default "true"

  • locale [string]: moment locale setting, for more information: https://momentjs.com/docs/#/i18n/changing-locale/, and for a list of available locales: https://momentjs.com/ (bottom of the page)

  • singleDate [boolean]: if you want a single date picker, set this to true, default false

  • target: [jquery object] the element to update after selection, if it's null, the element that is instantiated on will be updated. default null

  • ranges: [array] predefined ranges range objects array, which each will create a button in the footer, and when the user clicks, it'll automatically will be applied. One range is defined like below:

    • title [string]: the label which will appear on the button,
    • startDate [moment object|javascript Date Object|string]: the first date of the range,
    • endDate [moment object|javascript Date Object|string]: the last date of the range,

  • rangeLabel [string] : The title displayed in the defined ranges list section, default "Ranges: "

  • cancelLabel [string]: The cancel button label, default "Cancel"

  • applyLabel [string]: The apply button label, default "Apply"

  • enableMonthSwitcher [boolean]: Enables the month switcher when clicking on month names. Default: true

  • monthSwitcherFormat [boolean]: Changes the month name display format on the month switcher. Default: "MMMM"

  • enableYearSwitcher [boolean]: Enables the year switcher when clicking on years. Default: true

  • numericMonthSwitcher [boolean]: If set to true, shows month numbers instead of month names in month selector. Default: false

  • monthSwitcherFormat [string]: Changes the format of the month name displayed on the month selector. Default: "MMMM" (long month name format)

  • showWeekNumbers [string]: Shows week numbers on the left of the calendars. Default: false

  • autoCloseOnSelect [boolean]: On instances that are not displayed inline, this setting is used to automatically close the dropdown when a selection is made.

  • disableDays [function]: Enables day based disabling filters, input value is the current day to be processed. Example:
    {
      disableDays: function(day){
         return day.isSame(moment("17/05/2017")); // will return true on that day and the day will be disabled.
      }
    }
    


  • disabledRanges [object array]: Enables user to disable specific ranges from selection. Can be used with continuous option to preserve continuity. Object structure:
     [{ start: [moment object], end: [moment object]}, ..]
    


  • continuous [boolean]: Adds a check if the selected range continues any disabled days. Reverts the selection to it's original state when the user tries to select a range which contains a disabled date.

  • rangeOrientation [string]: Sets the range view to "vertical" or "horizontal" which renders the range part on the right or on the bottom of the calendar. Default: "horizontal"

  • verticalRangeWidth [string]: Sets the vertical range view panel width in pixels. Default: 150

Available Events

  • onbeforeselect [function]: event which is triggered before selecting the end date ( a range selection is completed). The return value decides whether the selection will happen. Returning false will prevent the input to update.

    Prototype:

          onbeforeselect: function(calentim, startDate, endDate){
              // calentim: calentim object instance
              // startDate: moment.js instance
              // endDate: moment.js instance
              return true; // false prevents update
          }
    



  • onafterselect [function]: event which is triggered after selecting the end date ( the input value changed )

    Prototype:

          onafterselect: function(calentim, startDate, endDate){
              // calentim: calentim object instance
              // startDate: moment.js instance
              // endDate: moment.js instance
          }
    



  • onbeforeshow [function]: event which is triggered before showing the dropdown

    Prototype:

          onbeforeshow: function(calentim){
              // calentim: calentim object instance
          }
    



  • onbeforehide [function]: event which is triggered before hiding the dropdown

    Prototype:

          onbeforehide: function(calentim){
              // calentim: calentim object instance
          }
    



  • onaftershow [function]: event which is triggered after showing the dropdown

    Prototype:

          onaftershow: function(calentim){
              // calentim: calentim object instance
          }
    



  • onafterhide [function]: event which is triggered after hiding the dropdown

    Prototype:

          onafterhide: function(calentim){
              // calentim: calentim object instance
          }
    



  • onfirstselect [function]: event which is triggered after selecting the first date of ranges

    Prototype:

          onfirstselect: function(calentim, startDate){
              // calentim: calentim object instance
              // startDate: moment.js instance
          }
    



  • onrangeselect [function]: event which is triggered after selecting a range from the defined range links

    Prototype:

          onrangeselect: function(calentim, range){
              // calentim: calentim object instance
              // range: selected range definition
          }
    



  • onbeforemonthchange [function]: event which fires before changing the first calendar month of multiple calendars, or the month of a single calendar. The return value decides whether the month switch will take place.

    Prototype:

          onbeforemonthchange: function(calentim, month, direction){
              // calentim: calentim object instance
              // month : moment.js object of first day of the month selected on the **first** calendar
              // direction: "next" or "prev", shows the month change direction. if `month.month()` is 4,
              // and direction is "prev", next month will be 3.
              return true; // false disables switching
          }
    



  • onaftermonthchange [function]: event which fires after changing the first calendar month of multiple calendars, or the month of a single calendar

    Prototype:

          onaftermonthchange: function(calentim, month){
              // calentim: calentim object instance
              // month : moment.js object of first day of the month selected on the first calendar
          }
    



  • ondraw [function]: event which fires after redraws in calendar

    Prototype:

      onredraw: function(calentim){
        // calentim: calentim object instance
      }
    



  • oninit [function]: event which fires after instance initialization

    Prototype:

      oninit: function(calentim){
        // calentim: calentim object instance
      }
    



  • ontimechange [function]: event which fires after timepicker value changes

    Prototype:

      ontimechange: function(calentim, startDate, endDate){
        // calentim: calentim object instance
        // startDate: the start date moment object
        // endDate: the end date moment object
      }
    



Methods

  • validateDates [function]: Validates the startDate, endDate, minDate, maxDate parameters of the instance configuration, by the means of parsability and order, and defaults to today's date for startDate and endDate, and to null for maxDate and minDate.

  • fetchInputs [function]: Retrieves the date(s) from the instance holder input and validates them before putting it to it's configuration.

  • updateInput [function]: Updates the instance holder input with the instance values and configuration.

  • drawNextMonth [function]: Triggers the instance show the next month after the first calendar month as the first calendar.

  • drawPrevMonth [function]: Triggers the instance show the previous month before the first calendar month as the first calendar.

  • reDrawCalendars [function]: Triggers a complete restructuring of the instance. Drawing the container first, then the header, then the calendars, then the footer.

  • reDrawCells [function]: Only modifies the calendar's related parts with the configuration variables. Doesn't entirely build the instance again like reDrawCalendars method does.

  • setViewport [function]: On dropdown instances, if the dropdown falls outside of the viewport (when shown, not scrolled) this function decides and calculates it's new position opposed to its configuration. For example, if the dropdown position is set to bottom and it falls below the page bottom edge, this method makes it appear as it was set to top for once.

  • showDropdown [function]: On dropdown and mobile instances, if the dropdown is not visible, this method triggers the show method.

  • hideDropdown [function]: On dropdown and mobile instances, if the dropdown is visible, this method hides it.

  • setStart [function]: Sets the start date and time of the input.

  • setEnd [function]: Sets the end date and time of the input.

  • setMinDate [function]: Sets the minimum selectable date of the input. Time portion is ignored.

  • setMaxDate [function]: Sets the maximum selectable date of the input. Time portion is ignored.

  • setDisplayDate [function] : Sets the displayed month and year, day and time are ignored.

     var instance = $(".calentim").data("calentim");

     // using moment object
     instance.setStart(moment());

     // using javascript Date object
     instance.setStart(new Date());

     // using ISO and RFC standardized date strings
     instance.setStart("2017-11-27T13:07:04+00:00"); // ISO 8601 and RFC 3339
     instance.setStart("Mon, 27 Nov 2017 13:07:04 +0000"); // RFC 822, 1035, 1123, 2822
     instance.setStart("Monday, 27-Nov-17 13:07:04 UTC"); // RFC 2822

     // using unix timestamp
     instance.setStart(1511788024);

     // using custom formatted date time string
     instance.setStart(moment("16:06 27.11.2017","HH:mm dd.MM.YYYY"));

Examples

Default Range Picker


Preview:

HTML:

      <input type="text" id="calentim-ex-1" />

JavaScript:

      <script type="text/javascript">
          $("#calentim-ex-1").calentim();
      </script>

Preview:

HTML:

      <input type="text" id="calentim-ex-1-1" />
    <input type="text" id="calentim-ex-1-2" />
    <input type="text" id="calentim-ex-1-3" />
    <input type="text" id="calentim-ex-1-4" />

JavaScript:

      <script type="text/javascript">
          $("#calentim-ex-1-1").calentim({showOn:"top",autoAlign:true});
          $("#calentim-ex-1-2").calentim({showOn:"left",autoAlign:true});
          $("#calentim-ex-1-3").calentim({showOn:"right",autoAlign:true});
          $("#calentim-ex-1-4").calentim({showOn:"bottom",autoAlign:true});
      </script>

Preview:

HTML:

      <input type="text" id="calentim-ex-1-5" />
    <input type="text" id="calentim-ex-1-6" />
    <input type="text" id="calentim-ex-1-7" />
    <input type="text" id="calentim-ex-1-8" />

JavaScript:

      <script type="text/javascript">
          $("#calentim-ex-1-5").calentim({showOn:"top",autoAlign:false});
          $("#calentim-ex-1-6").calentim({showOn:"left",autoAlign:false});
          $("#calentim-ex-1-7").calentim({showOn:"right",autoAlign:false});
          $("#calentim-ex-1-8").calentim({showOn:"bottom",autoAlign:false});
      </script>

Arrow Positioning


Preview:











HTML:

    <style> .vhide{ visibility:hidden; } </style>
    <input type="text" class="vhide"><input type="text" id="calentim-ex-t-r" value="06/21/2017" /><input type="text" id="calentim-ex-t-c" value="06/21/2017" /><input type="text" id="calentim-ex-t-l" value="06/21/2017" /><input type="text" class="vhide"><br><br>
    <input type="text" id="calentim-ex-l-t" value="06/21/2017" /><input type="text" class="vhide"><input type="text" class="vhide"><input type="text" class="vhide"><input type="text" id="calentim-ex-r-t" value="06/21/2017" /><br><br>
    <input type="text" id="calentim-ex-l-c" value="06/21/2017" /><input type="text" class="vhide"><input type="text" id="calentim-ex-c-c" value="06/21/2017" /><input type="text" class="vhide"><input type="text" id="calentim-ex-r-c" value="06/21/2017" /><br><br>
    <input type="text" id="calentim-ex-l-b" value="06/21/2017" /><input type="text" class="vhide"><input type="text" class="vhide"><input type="text" class="vhide"><input type="text" id="calentim-ex-r-b" value="06/21/2017" /><br><br>
    <input type="text" class="vhide"><input type="text" id="calentim-ex-b-r" value="06/21/2017" /><input type="text" id="calentim-ex-b-c" value="06/21/2017" /><input type="text" id="calentim-ex-b-l" value="06/21/2017" /><input type="text" class="vhide"><br><br>

JavaScript:

  <script type="text/javascript">
    $("#calentim-ex-t-r").calentim({
        showOn: "top",
        arrowOn: "right"
    });
    $("#calentim-ex-t-c").calentim({
        showOn: "top",
        arrowOn: "center"
    });
    $("#calentim-ex-t-l").calentim({
        showOn: "top",
        arrowOn: "left"
    });
    $("#calentim-ex-l-c").calentim({
        showOn: "left",
        arrowOn: "center"
    });
    $("#calentim-ex-l-t").calentim({
        showOn: "left",
        arrowOn: "top"
    });
    $("#calentim-ex-l-b").calentim({
        showOn: "left",
        arrowOn: "bottom"
    });
    $("#calentim-ex-c-c").calentim({
        showOn: "center",
        arrowOn: "center"
    });
    $("#calentim-ex-r-c").calentim({
        showOn: "right",
        arrowOn: "center"
    });
    $("#calentim-ex-r-t").calentim({
        showOn: "right",
        arrowOn: "top"
    });
    $("#calentim-ex-r-b").calentim({
        showOn: "right",
        arrowOn: "bottom"
    });

    $("#calentim-ex-b-r").calentim({
        showOn: "bottom",
        arrowOn: "right"
    });
    $("#calentim-ex-b-c").calentim({
        showOn: "bottom",
        arrowOn: "center"
    });
    $("#calentim-ex-b-l").calentim({
        showOn: "bottom",
        arrowOn: "left"
    });
  </script>

Hiding the header


Preview:

HTML:

      <input type="text" id="calentim-ex-2" />

JavaScript:

      <script type="text/javascript">
          $("#calentim-ex-2").calentim({showHeader: false});
      </script>

Preview:

HTML:

      <input type="text" id="calentim-ex-3" />

JavaScript:

      <script type="text/javascript">
          $("#calentim-ex-3").calentim({showFooter: false});
      </script>

Hiding calendars


Preview:

HTML:

      <input type="text" id="calentim-ex-3-3" />

JavaScript:

      <script type="text/javascript">
          $("#calentim-ex-3-3").calentim({
        showCalendars: false,
        format: "hh:mm A"
      });
      </script>

Hiding time pickers


Preview:

HTML:

      <input type="text" id="calentim-ex-3-4" />

JavaScript:

      <script type="text/javascript">
          $("#calentim-ex-3-4").calentim({showTimePickers: false, format: "L"});
      </script>

Empty on initialization


Preview:

HTML:

      <input type="text" id="calentim-ex-5-1" placeholder="Select a Date" />

JavaScript:

      <script type="text/javascript">
          $("#calentim-ex-5-1").calentim({startEmpty: true});
      </script>

Showing dropdown apply/cancel buttons


This will only work with dropdown desktop view, inline views don't support cancel and apply buttons. Mobile modal view already has them.
Preview:

HTML:

      <input type="text" id="calentim-ex-5-3" placeholder="Select a Date" />

JavaScript:

      <script type="text/javascript">
          $("#calentim-ex-5-1").calentim({showButtons: true});
      </script>

Changing hour format


Preview:

HTML:

    <input type="text" id="calentim-ex-3-1" />

JavaScript:

    <script type="text/javascript">
      $("#calentim-ex-3-1").calentim({
        format: "DD/MM/YYYY HH:mm",
        hourFormat: 24
      });
    </script>

Changing minute steps


Preview:

HTML:

    <input type="text" id="calentim-ex-3-2" />

JavaScript:

    <script type="text/javascript">
      $("#calentim-ex-3-2").calentim({
        minuteSteps: 15
      });
    </script>

Changing Timepicker arrow directions


Preview:

HTML:

    <input type="text" id="calentim-ex-3-5" />

JavaScript:

    <script type="text/javascript">
      $("#calentim-ex-3-5").calentim({
        reverseTimepickerArrows: true
      });
    </script>

Changing calendar count


Preview:

HTML:

      <input type="text" id="calentim-ex-4" />

JavaScript:

      <script type="text/javascript">
          $("#calentim-ex-4").calentim({calendarCount: 3});
      </script>

Inline calendar


Preview:

HTML:

      <input type="text" id="calentim-ex-5" />

JavaScript:

      <script type="text/javascript">
          $("#calentim-ex-5").calentim({inline: true});
      </script>

Inline time picker


Preview:

HTML:

      <input type="text" id="calentim-ex-5-2" />

JavaScript:

      <script type="text/javascript">
          $("#calentim-ex-5-2").calentim({
            inline: true,
            showCalendars: false,
            format: "hh:mm A"
          });
      </script>

Single date time picker


Preview:

HTML:

      <input type="text" id="calentim-ex-6" />

JavaScript:

      <script type="text/javascript">
          $("#calentim-ex-6").calentim({singleDate: true});
      </script>

Range/Single switch


Preview:

HTML:

<label for='single-calentim-mod'>
  <input type='radio' value="single"  id='single-calentim-mod' name="calentim-type-selector"
    class='calentim-type-selector'>
    &nbsp;Single Date
  </label>
<label for='multi-calentim-mod'>
  <input type='radio' value="multi"  id='multi-calentim-mod' name="calentim-type-selector"
    class='calentim-type-selector' checked>
  &nbsp;Multiple Dates
</label>
    <input type="text" id="calentim-ex-6-4" />

JavaScript:

  <script type="text/javascript">
  $("#calentim-ex-6-4").calentim();
  $(".calentim-type-selector").click(function(){
    $("#calentim-ex-6-4").data("calentim").destroy();
    $("#calentim-ex-6-4").calentim({
      singleDate: $("input[name='calentim-type-selector']:checked").val() == "single" ? true : false
    });
  });
  </script>

Linked Single Date Pickers


Preview:

Start Date:
End Date:

HTML:

  <div style='display: flex;'>
    <div>Start Date: <input type="text" id="calentim-ex-6-5-start" /></div>
    <div style='margin-left:20px;'>End Date:  <input type="text" id="calentim-ex-6-5-end" /></div>
  </div>

JavaScript:

  <script type="text/javascript">
    var calentimStart, calentimEnd, startSelected = null, endSelected = null;
    var ondrawEvent = function (instance) {
        if (instance.globals.initComplete) {
            instance.readTimeFromDisplay();
            updateInputs();
        }
    };
    var updateInputs = function () {
        if (startSelected && endSelected && startSelected.hasOwnProperty("_isAMomentObject") && endSelected.hasOwnProperty("_isAMomentObject")) {
            if (startSelected.isAfter(endSelected, "day")) {
                endSelected = startSelected.clone().add(1, "days");
            }
        }
        if (startSelected && startSelected.hasOwnProperty("_isAMomentObject")) {
            calentimStart.config.startDate = startSelected;
            calentimEnd.config.startDate = startSelected;
            calentimEnd.config.minDate = startSelected;
            calentimStart.$elem.val(startSelected.format(calentimStart.config.format));
        }
        if (endSelected && endSelected.hasOwnProperty("_isAMomentObject")) {
            calentimStart.config.endDate = endSelected;
            calentimEnd.config.endDate = endSelected;
            calentimEnd.$elem.val(endSelected.format(calentimEnd.config.format));
        }
    };
    // start always selects start date.
    $("#calentim-ex-6-5-start").calentim({
        oninit: function (instance) {
            instance.globals.delayInputUpdate = true;
            instance.$elem.val(instance.config.startDate.format(instance.config.format));
            calentimStart = instance;
        },
        ondraw: ondrawEvent,
        onfirstselect: function (instance, start) {
            startSelected = start.clone();
            instance.globals.startSelected = false;
            updateInputs();
            instance.hideDropdown();
            calentimEnd.showDropdown();
        },
        onbeforeselect: function (instance, start, end) {
            startSelected = start.clone();
            endSelected = end.clone();
            updateInputs();
        }
    });
    // end always selects end date.
    $("#calentim-ex-6-5-end").calentim({
        oninit: function (instance) {
            instance.globals.delayInputUpdate = true;
            instance.$elem.val(instance.config.endDate.format(instance.config.format));
            instance.$elem.val("");
            calentimEnd = instance;
        },
        ondraw: ondrawEvent,
        onfirstselect: function (instance, start) {
            if (calentimStart.config.endDate)
                endSelected = start.clone().set({ hours: calentimStart.config.endDate.hours(), minutes: calentimStart.config.endDate.minutes(), seconds: calentimStart.config.endDate.seconds() });
            else
                endSelected = start.clone();
            instance.globals.startSelected = false;
            updateInputs();
            instance.input.find(".calentim-apply").attr("disabled",false);
        },
        onbeforeselect: function (instance, start, end) {
            startSelected = start.clone();
            endSelected = end.clone();
            updateInputs();
        }
    });
</script>

Minimal Single date time picker


Preview:

HTML:

    <input type="text" id="calentim-ex-6-2" />

JavaScript:

    <script type="text/javascript">
      $("#calentim-ex-6-2").calentim({
        singleDate: true,
        calendarCount: 1,
        showHeader: false,
        showFooter: false,
        autoCloseOnSelect: true
      });
    </script>

Ranges on the Right


Preview:

HTML:

    <input type="text" id="calentim-ex-6-6-1" />

JavaScript:

    <script type="text/javascript">
      $("#calentim-ex-6-6-1").calentim({
        rangeOrientation: "vertical"
      });
    </script>

Ranges on the Right with Buttons


Preview:

HTML:

    <input type="text" id="calentim-ex-6-6-2" />

JavaScript:

    <script type="text/javascript">
      $("#calentim-ex-6-6-2").calentim({
        rangeOrientation: "vertical",
        showButtons: true
      });
    </script>

Ranges on the Right (inline)


Preview:

HTML:

    <input type="text" id="calentim-ex-6-6-3" />

JavaScript:

    <script type="text/javascript">
      $("#calentim-ex-6-6-3").calentim({
        inline: true,
        rangeOrientation: "vertical"
      });
    </script>

Showing week numbers


Preview:

HTML:

    <input type="text" id="calentim-ex-6-6-4" />

JavaScript:

    <script type="text/javascript">
      $("#calentim-ex-6-6-4").calentim({
        showWeekNumbers: true
      });
    </script>

Auto Close on Select


Preview:

HTML:

  <input type="text" id="calentim-ex-6-1" />

JavaScript:

  <script type="text/javascript">
    $("#calentim-ex-6-1").calentim({autoCloseOnSelect: true});
  </script>

Defining Min/Max Dates


Preview:

HTML:

  <input type="text" id="calentim-ex-6-3" />

JavaScript:

  <script type="text/javascript">
    $("#calentim-ex-6-3").calentim({
      minDate: moment().subtract(1, "weeks").startOf("week"),
      maxDate: moment().add(1, "weeks").endOf("week")
    });
  </script>

Defining custom ranges


Preview:

HTML:

      <input type="text" id="calentim-ex-7" />

JavaScript:

      <script type="text/javascript">
          $("#calentim-ex-7").calentim({ranges: [
              {
                  title: "Next Week",
                  startDate: moment().add(1,"weeks").startOf("week"),
                  endDate: moment().add(1,"weeks").endOf("week")
              },
              {
                  title: "Today",
                  startDate: moment(),
                  endDate: moment()
              },
              {
                  title: "Yesterday",
                  startDate: moment().subtract(1,"days"),
                  endDate: moment().subtract(1,"days")
              },
              {
                  title: "Last 7 days",
                  startDate: moment().subtract(7,"days"),
                  endDate: moment().subtract(1,"days")
              },
              {
                  title: "Last 30 days",
                  startDate: moment().subtract(30,"days"),
                  endDate: moment().subtract(1,"days")
              },
              {
                  title: "This month",
                  startDate: moment().startOf("month"),
                  endDate: moment().endOf("month")
              },
              {
                  title: "Last month",
                  startDate: moment().subtract(1,"months").startOf("month"),
                  endDate: moment().subtract(1,"months").endOf("month")
              }
          ]});
      </script>

Custom events


Preview:

HTML:

      <input type="text" id="calentim-ex-8" />
      <div class="calentimlabel"></div>

JavaScript:

      <script type="text/javascript">
          $("#calentim-ex-8").calentim({
              onafterselect: function(calentim, startDate, endDate) {
                 calentim.$elem.closest(".well").find(".calentimlabel")
                .text("You have chosen between " + startDate.format('LLLL') + " and " + endDate.format('LLLL'));
              }
          });
      </script>

Change first day of week


Preview:

HTML:

      <input type="text" id="calentim-ex-9" />

JavaScript:

      <script type="text/javascript">
          $("#calentim-ex-9").calentim({startOnMonday: true});
      </script>

Changing locale


Preview:

HTML:

      <input type="text" id="calentim-ex-10" />

JavaScript:

      <script type="text/javascript">
          var userLanguage = navigator.language || navigator.userLanguage;
          if(userLanguage == "en") userLanguage = "fr";
          $("#calentim-ex-10").calentim({locale: userLanguage });
      </script>

Changing locale (inline)


Preview:

HTML:

      <input type="text" id="calentim-ex-10-2" />

JavaScript:

      <script type="text/javascript">
          var userLanguage = navigator.language || navigator.userLanguage;
          if(userLanguage == "en") userLanguage = "fr";
          $("#calentim-ex-10-2").calentim({locale: userLanguage, inline: true });
      </script>

Week Select Mode


Preview:

HTML:

    <input type="text" id="calentim-ex-10-1" />

JavaScript:

    <script type="text/javascript">
      $("#calentim-ex-10").calentim({
        onfirstselect: function(elem,start){
            elem.config.startDate = moment(start).startOf("week");
            elem.config.endDate = moment(start).endOf("week");
            elem.globals.endSelected = true;
            elem.globals.startSelected = false;
            elem.globals.hoverDate = null;
            elem.$elem.find( ".calentim-apply" ).removeAttr( "disabled" );
            elem.updateInput();
        }
      });
    </script>

Custom target element


Preview:

HTML:

    <input type="text" id="calentim-ex-11-target" />
    <button id="calentim-ex-11">Open calentim</button>

JavaScript:

      <script type="text/javascript">
          $("#calentim-ex-11").calentim({target: $("#calentim-ex-11-target")});
      </script>

Custom disabled ranges (with callback)


Note: This task would only fill the input on Wednesdays, because the only valid (selectable) dates are Wednesdays on the calendar. If the start day or end day isn't selectable, the plugin will revert itself to startEmpty state when initialized. Preview:

HTML:

    <input type="text" id="calentim-ex-13" />

JavaScript:

    <script type="text/javascript">
      $("#calentim-ex-13").calentim({
        disableDays: function(day){
          return day.day() != 3;
        }
      });
    </script>

Custom disabled ranges (with array)


Preview:

HTML:

    <input type="text" id="calentim-ex-13-2" value="03/19/2017 12:00 AM - 03/20/2017 12:00 AM" />

JavaScript:

    <script type="text/javascript">
      $("#calentim-ex-13-2").calentim({
        disabledRanges: [
          {
            "start": moment("10/03/2017","DD/MM/YYYY"),
            "end": moment("18/03/2017", "DD/MM/YYYY")
          },
          {
            "start": moment("01/04/2017","DD/MM/YYYY"),
            "end": moment("05/04/2017", "DD/MM/YYYY")
          },
          {
            "start": moment("11/04/2017","DD/MM/YYYY"),
            "end": moment("15/04/2017", "DD/MM/YYYY")
          }
        ]
      });
    </script>

Custom disabled ranges (preserve continuousity)


Preview:

HTML:

    <input type="text" id="calentim-ex-13-3" value="03/19/2017 12:00 AM - 03/20/2017 12:00 AM" />

JavaScript:

    <script type="text/javascript">
      $("#calentim-ex-13-3").calentim({
        continuous: true,
        disabledRanges: [
          {
            start: moment("10/03/2017","DD/MM/YYYY"),
            end: moment("18/03/2017", "DD/MM/YYYY")
          },
          {
            "start": moment("01/04/2017","DD/MM/YYYY"),
            "end": moment("05/04/2017", "DD/MM/YYYY")
          },
          {
            "start": moment("11/04/2017","DD/MM/YYYY"),
            "end": moment("15/04/2017", "DD/MM/YYYY")
          }
        ]
      });
    </script>

Show & Hide with triggers


Preview:

HTML:

    <input type="text" id="calentim-ex-13-1" />
    <button class="calentim-show">Show Instance</button>
    <button class="calentim-hide">Hide Instance</button>

JavaScript:

    <script type="text/javascript">
      $("#calentim-ex-13-1").calentim();
      $(".calentim-show").on("click",function(e){
        var calentim = $("#calentim-ex-13-1").data("calentim");
        calentim.showDropdown(e);
      });
      $(".calentim-hide").on("click",function(e){
        var calentim = $("#calentim-ex-13-1").data("calentim");
        calentim.hideDropdown(e);
      });
    </script>

Using inside a modal


Preview:

HTML:

    <!-- Modal -->
    <div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
      <div class="modal-dialog" role="document">
        <div class="modal-content">
          <div class="modal-body">
            <input type="text" id="calentim-ex-12" />
          </div>
          <div class="modal-footer">
            <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
          </div>
        </div>
      </div>
    </div>
    <!-- Button trigger modal -->
    <button type="button" class="btn btn-primary" onclick="$('#myModal').modal('show');" >
          Launch demo modal
    </button>

JavaScript:

      <script type="text/javascript">
          $("#calentim-ex-12").calentim();
      </script>

Important Notes

  • I left the calentim object fully accessible to the inner variables, so you can alter the object's config in any event. For example, you can alter the max date of the calendar after first selection like this (limiting the user to select max 7 days of the first selection):

      onfirstselect: function(calentim, startDate){
          calentim.config.maxDate = startDate.clone().add(7,"days");
      },
      onafterselect: function(calentim, startDate, endDate){
          calentim.config.maxDate = null;
      }
    

    or another example, disabling previous date selection:

      onfirstselect: function(calentim, startDate){
          calentim.config.minDate = startDate.clone();
      },
      onafterselect: function(calentim, startDate, endDate){
          calentim.config.minDate = null;
      }
    
  • The cloning is very important when adding or subtracting, because they modify the reference element too! As you can see in the above examples, the startDate and the endDate elements are cloned when defining the maxDate and minDate values. If you don't want to modify the startDate or endDate intentionally, use cloning.

  • Mobile only supports modal like interface. Dropdowns and inline options currently don't work on mobile phones. Added inline support on mobile devices on version 1.1.2.

  • Only one event can be bound using the initialize config object. Multiple events are not supported.

Changelog

  • v1.0.0

    • Released initial version.
  • v1.0.1

    • fixed minute step overflow error on last step range
    • fixed ineffective initial value on startEmpty: true setting
    • fixed parameterless hideDropdown call bug in firefox
    • fixed multiple instance closing issues
    • added option to remove time picker
    • added infinite scroll on timepickers
  • v1.0.2

    • fixed target element confusion when different target option is specified
    • added showCalendars option to disable date selection (only time picker)
  • v1.1.0

    • fixed an issue about time pickers setting the wrong value on first click
    • fixed autoCloseOnSelect on singleDate version / mobile views
    • changed code to make clicking on disabled days select start/end date
    • added some transition delays to make it smoother
    • added keyboard navigation (enableKeyboard option)
      • up: previous week
      • down: next week
      • left: previous day
      • right: next day
      • space: select day
      • pageup: previous month
      • pagedown next month
      • shift + pageup: previous year
      • shift + pagedown: next year
    • added easy year switch buttons on year list
    • fixed startEmpty cell selected classes
    • added destroy method and some extra tests
    • fix custom target element reading in fetchInputs method
  • v1.1.1

    • fixed the month change problem which is caused by a reset when validating dates.
  • v1.1.2

    • fixed the problem about showing the initial month when the selected date is in a different month.
    • added inline view support on mobile devices
    • fixed startEmpty behaviour when clicking the cancel button on mobile
  • v1.1.3

    • added showButtons property for not automatically updating the input, default false
    • added tests for showButtons property
    • added time changes to onbeforechange and onafterchange event
    • fixed range selection on instances with startEmpty: true defined
    • fixed hovering bug after month change when first date is selected
  • v1.1.4

    • fixed button disabled state with startEmpty and showButtons are both active
    • reapplied deleted locale setting
    • innerWidth function was called on javascript object, not jQuery object, fixed.
    • buttons now don't submit forms.
  • v1.1.5

    • configuration objects attached to prototype converted to independent objects
    • startEmpty property clears input on initialization
    • added jshint javascript linter to gruntfile
    • some optimizations
    • moved event bubbling in one method
    • added "left" "right" display options ("showOn" option, default "bottom")
    • added auto positioning enable/disable flag ("autoAlign" option, default "true")
    • added position recalculation on window scroll and resize events
    • fixed hour:minute scrolling issue
    • fixed css issue about month selector in small calendars
    • fixed locale error on month selector
    • added adjustment for font-size in month selector page
  • v1.1.6

    • Repeating day issue caused by daylight saving time activation fixed.
  • v1.1.7

    • fixed header display bug on startEmpty
    • converted moment instances to unix timestamps on reDrawCells method
    • added first and last hover classes (border radius effect)
    • removed autoprefixer and added postcss plugin for browser compatible CSS
    • fixed visibility issues
    • Added calentim-not-in-month class for the days that don't belong to that month
    • Replaced moment's .startOf("day") to middleOfDay() extension function to minimize DST change bugs.
    • switched from grunt-jasmine to karma test runner
  • v1.1.8

    • added next day selection demo to linked single time pickers example
    • fixed ESC key hiding inline calendars bug.
    • added backup and restore time pickers method to keep time values intact on month changes
  • v1.1.9

    • fixed display bug on header (start week of day showed day number instead of name)
    • improved linked single date picker example
  • v1.2.0

    • updated jQuery library in demos and readme to v3.1.2
    • updated getDimensions method to more paint and memory friendly version
    • added setStart, setEnd, setMinDate, setMaxDate and setDisplayDate methods
    • added istanbul test code coverage tools
    • added start and end date validation regarding minimum and maximum allowed dates
    • added reverseTimepickerArrows option to reverse the actions of time picker arrows
  • v1.2.1

    • changed prev and next hour/minute displays regarding to reverseTimePickerArrows setting.
    • fixed 12h display bug on showing dropdown in 24h format
    • fixed dropdown positioning on inner scrolling container other than window
  • v1.2.2

    • fixed calendar header locale bug
    • fixed startOnMonday dismissing the 1st day row when its on sunday
  • v1.2.3

    • added predefined events to hideDropdown and showDropdown to prevent var undefined exception.
    • updated example about linked date pickers
    • implemented ontimechange event
    • added month name format on monthselector
    • added week numbers on calendars
  • v1.2.4

    • Added right side range list panel settings
    • Updated documentation
    • added smart positioning on top/bottom dropdowns
    • added selected range indicators
    • massive performance upgrade
    • added arrowOn parameter which moves the arrow to the desired position.
    • improved positioning on viewport edges
    • added center/center display option
  • Based on Moment.js http://www.momentjs.com
    Copyright (c) JS Foundation and other contributors
    Moment.js is freely distributable under the terms of the MIT license.
    All rights reserved.

  • Includes hammer.js http://hammerjs.github.io
    Copyright (C) 2011-2014 by Jorik Tangelder (Eight Media)
    hammer.js is freely distributable under the terms of the MIT license.
    All rights reserved.