Class: Date

Inherits:
Object show all
Defined in:
lib/ruby-rails-extensions/extensions/todays_date.rb,
lib/ruby-rails-extensions/extensions/input.rb,
lib/ruby-rails-extensions/extensions/month_year.rb,
lib/ruby-rails-extensions/extensions/safe_parse.rb,
lib/ruby-rails-extensions/extensions/day_of_week.rb,
lib/ruby-rails-extensions/extensions/current_week.rb,
lib/ruby-rails-extensions/extensions/display_user.rb,
lib/ruby-rails-extensions/extensions/current_month.rb,
lib/ruby-rails-extensions/extensions/month_and_year.rb

Overview

Requires ‘ActiveSupport::TimeWithZone` and `Time#to_local`

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.safe_parse(str) ⇒ Object

Parses the ‘str` and returns `nil` if invalid



17
18
19
20
21
# File 'lib/ruby-rails-extensions/extensions/safe_parse.rb', line 17

def safe_parse(str)
  parse(str)
rescue
  nil
end

.todays_dateDate

Returns today according to Eastern time

Returns:



10
11
12
# File 'lib/ruby-rails-extensions/extensions/todays_date.rb', line 10

def todays_date
  Time.zone.now.to_local.to_date
end

Instance Method Details

#current_monthObject

:nodoc:



14
15
16
# File 'lib/ruby-rails-extensions/extensions/current_month.rb', line 14

def current_month
  beginning_of_month..end_of_month
end

#current_weekObject



14
15
16
# File 'lib/ruby-rails-extensions/extensions/current_week.rb', line 14

def current_week
  beginning_of_week..end_of_week
end

#day_of_weekString

Returns - Full day word.

Returns:



14
15
16
# File 'lib/ruby-rails-extensions/extensions/day_of_week.rb', line 14

def day_of_week
  strftime('%A')
end

#display_user(all = false) ⇒ String

Returns - mm/dd/yyyy or m/d/yy.

Returns:

  • (String)
    • mm/dd/yyyy or m/d/yy



21
22
23
# File 'lib/ruby-rails-extensions/extensions/display_user.rb', line 21

def display_user(all = false)
  strftime(all ? '%m/%d/%Y' : '%-m/%-d/%y')
end

#input(_all = false) ⇒ String

Returns - yyyy-mm-dd.

Returns:



14
15
16
# File 'lib/ruby-rails-extensions/extensions/input.rb', line 14

def input(_all = false)
  strftime('%F')
end

#month_and_yearString

Returns - mm/yy.

Returns:



7
8
9
# File 'lib/ruby-rails-extensions/extensions/month_and_year.rb', line 7

def month_and_year
  strftime('%m/%y')
end

#month_yearString

Returns - yyyy-mm.

Returns:



7
8
9
# File 'lib/ruby-rails-extensions/extensions/month_year.rb', line 7

def month_year
  input[0, 7]
end