Giter Club home page Giter Club logo

daterangepicker's Introduction

DateRangePicker - the best (?) date range picker control for OS X

(At least I don't know of any better. If you do, please tell me.)

The popover for customized date ranges Some possible looks for the control The menu for preset date ranges

Usage

Just drag the date range picker onto your Storyboard or Nib. It looks particularly good in the toolbar with segmentStyle = .Separated. If you wish to center the picker in the toolbar, I can recommend using TAAdaptiveSpaceItem.

You can observe changes in the date range by key-value-observing startDate and endDate and/or setting a target and action on the DateRangePickerView control.

Features

  • Perfect for use in a toolbar, but can also be used anywhere else
  • Date range presets: "Last 7/15/30/90/365 days", "Today/Yesterday/This week/month/quarter/year"
  • Pretty display of these presets as well as previous/future months (as e.g. "October 2015")
  • "Back" and "Forward" buttons let you shift the date range by its current duration, e.g. 7 days earlier/later, previous/next month/week/quarter/year
    • I.e. "real" month-by-month stepping through the data, not in simple 30-day intervals
  • Completely custom date ranges selectable in a popover (which can be used without the control as well)
  • Lets you specify minimum and maximum dates that can not be exceeded
    • These are reflected in the interface - the "Back"/"Forward" buttons get disabled when the date range reaches the minimum/maximum
  • Provides a sophisticated, serializable (so you can persist it between launches of your app) date range structure (implemented as a Swift enum)
  • Provides some useful date computation functions as an extension to NSDate
  • Usable from Objective-C
    • Exposes KVO/KVC-compatible startDate and endDate properties
    • Date range changes are also sent via NSControl's target-action pattern
    • Exposes -dateRangeAsData and -loadDateRangeFromData: methods that let you persist the date range in Objective-C as well
    • The NSDate extensions are also available from NSDate
  • Customizable segmented control styles
  • Localizations: English, German (feel free to add others!)
  • High code quality
    • Adheres to Cocoa "Best Practices" (if you find any antipatterns, let me know)
    • Full test coverage for the date range structure and date computations
  • Interface Builder-compatible (@IBDesignable)
  • Small and self-contained

What's missing

  • The date presets can currently not be customized (but you can easily replace them in ExpandedDateRangePickerController)
  • Date presets for "Last month/week/quarter/year" and "Next month/week/quarter/year" are currently not available (but could be added easily, and you can still reach them by selecting "This week/month/quarter/year" and then pressing "Back"/"Forward")
  • Found something else? Submit a pull request or contact me :-)

Compatibility

Requires (and tested on) OS X 10.9 or later. Looks a lot better in the toolbar with OS X 10.10 ;-)

Notes for legacy Nibs

If your Nib uses the old initWithFrame: initialization or is deflated on OS X 10.9, there is a bug with custom views in NSToolbar. This results in the date range picker's frame not being initialized correctly. In order to avoid this, I recommend the following procedure:

  • Create a dummy NSToolbarItem with an empty Custom View of the desired size and add an IBOutlet for the NSToolbarItem
  • Add the picker as a standalone view to the Nib and add an IBOutlet for it as well
  • In -awakeFromNib, programmatically set the toolbar item's view to be the picker

License

This library is available under the ISC license, which is a simplified variant of the two-clause BSD license.

If you use this library, I appreciate if you let me know @daniel_a_a on Twitter. I also have a blog.

daterangepicker's People

Contributors

mrmage avatar thierryh91200 avatar matttimmons avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.