New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

github.com/darkleaf/date_range_formatter

Package Overview
Dependencies
Alerts
File Explorer
Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

github.com/darkleaf/date_range_formatter

  • v0.1.2
  • Source
  • Go
  • Socket score

Version published
Created
Source

Date Range Formatter

Build Status Gem Version Build Status

This gem makes working with dates more pretty. It works well with Ruby application and most frameworks like Ruby on Rails.

Installation

Very simple. Just add this code to Gemfile:

gem 'date_range_formatter'

Usage

Imagine the situation when you need to show dates of some stuff at your website. For example:

1 - 9 May 2014
2 January 2015
15 July 2016 - 13 February 2017

After that you should call the module DateRangeFormatter with arguments wchich describes the range of dates and format to display. For example, we have date_beginning, date_ending and format by default:

DateRangeFormatter.format('2013-01-14', '2013-02-15')
#=> '14 January - 15 February 2013'

Also you can use format_range method and enumerable object:

DateRangeFormatter.format_range(['2013-02-20', '2013-01-14', '2013-01-15'])
#=> '14 January - 20 February 2013'

If you want to show dates by another format, you can call it:

date_beginning = Date.new(2013, 01, 14)
date_ending = Date.new(2014, 02, 15)
date_range_str = DateRangeFormatter.format(date_beginning, date_ending, 'short')

If you want to show hours, you can call it:

DateRangeFormatter.format('10:00 2013-01-14', '20:00 2013-01-14', :with_time)
#=> '14 January 2013, 10am - 08pm'

See predefined formats. Also you can override this formats or add your own.

That's all. Enjoy your profit!

Other

This idea was appeared by looking at the article. Thanks to @mbillard.

FAQs

Package last updated on 06 Oct 2021

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc