Project

tick_tack

0.0
No commit activity in last 3 years
No release in over 3 years
Helps you writing calendar functionality by providing an abstraction for years, months, and days.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
 Dependencies

Development

~> 1.11
~> 5.0
~> 10.0
 Project Readme

Build Status Gem Version

TickTack

TickTack is a lean wrapper for Rubys native Date object to provide some helpful methods for easy calendar creation. See the Example section below for a better unterstanding!

Installation

Add this line to your application's Gemfile:

gem 'tick_tack'

And then execute:

$ bundle

Or install it yourself as:

$ gem install tick_tack

Usage

Calendar

Create a new calendar object

calendar = TickTack::Calendar.new

To overwrite the current date just pass in another date. This date is used as a fallback for the factory methods. For example - if you call calendar.month(2014) without a month, it will return the current month but in year 2014.

TickTack::Calendar.new(Date.new(2015, 5, 27))

Methods

  • calendar.now Returns the calendars base Date
  • calendar.year(2013) Returns the Year for the given year number
  • calendar.month(2013, 1) Returns the Month for the given year and month
  • calendar.day(2013, 1, 12) Returns the Day for the given year, month and day

Year

To get a year from the calendar call the year on the calendar object

year = calendar.year(2014)

Methods

  • year.first_day Get the first day of the year
  • year.last_day Get the last day of the year
  • year.month(2) Get the Month february in this year
  • year.months Get all months as an array for this year
  • year.contains?(other) Check if other is part of this year. other can be either a Month or a Day
  • year.next Get the next Year
  • year.previous Get the previous Year

Month

To get a month, you can either call the creator method on the calendar or on the Year:

month = calendar.month(2014, 5)
# or
month = year.month(5)

Methods

  • month.first_day Get the first day of the month
  • month.last_day Get the last day of the month
  • month.day(2) Get the requested Day on this month
  • month.weekdays Gets an array of all weeks from this month containing all days. Including overlapping days in other months. This is useful for rendering a month-view of an calendar.
  • month.contains?(day) Check if a Day is part of this month
  • month.next Get the next Month
  • month.previous Get the previous Month

Day

A day can be created from a calendar or month:

day = calendar.day(2014, 5, 30)
# or
day = month.day(30)

Methods

  • day.week_start Returns the first Day of the week which the current day is in. To configure the first day of the week, see Localization section below.
  • day.week_end Returns the last Day of the week which the current day is in.
  • day.weekdays Returns an array of Days for the week in which the current day is in.
  • day.next Returns the next Day
  • day.previous Returns the previous Day

Localization

Currently only dow (day of week) value can be overwritten which usually starts with 0. To set the day to monday, just pass in the locale config as second argument:

calendar = TickTack::Calendar.new(nil, {dow: 1})

Example

TODO... maybe tomorrow :)

Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/tomraithel/tick_tack.

License

The gem is available as open source under the terms of the MIT License.