Git Product home page Git Product logo

custom_date_time_formats's Introduction

Custom Date Time Formats

Rails plugin that tries to simplify adding custom date and time formats

Installation

script/plugin install git://github.com/cingel/custom_date_time_formats.git

Usage

First add your custom formats like this (ApplicationController could be a good place for this)

CustomDateTimeFormats.add_time_formats :hr => "%d.%m.%Y. %H:%M:%S", :human => "%m/%d/%Y %H:%M:%S"
CustomDateTimeFormats.add_date_formats :hr => "%d.%m.%Y.", :human => "%m/%d/%Y"

and use it like this

Time.now.to_s(:hr) => "24.05.2010. 15:32:01"
Date.today.to_s(:human) => "05/24/2010"

or

user = User.first
user.created_at.to_s => "2010-05-20 22:00:08 UTC"
user.created_at.to_s(:hr) => "20.05.2010. 22:00:08"
user.created_at.to_date.to_s(:human) => "05/20/2010"

Notes

  • See lib/custom_date_time_formats.rb for the list of predefined formats

  • If you add date format it will be automatically added as time format unless time format with that name already exists

Resources

api.rubyonrails.org/classes/ActiveSupport/CoreExtensions/Time/Conversions.html api.rubyonrails.org/classes/ActiveSupport/CoreExtensions/Date/Conversions.html

Copyright © 2010 Cingel d.o.o., released under the MIT license

custom_date_time_formats's People

Contributors

vlado avatar

Stargazers

Cingel d.o.o. avatar

Watchers

Cingel d.o.o. avatar James Cloos 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.