https://github.com/mohsen-alizadeh/rails-pdate
Persian date utility to use in Rails projects
https://github.com/mohsen-alizadeh/rails-pdate
ruby
Last synced: about 1 year ago
JSON representation
Persian date utility to use in Rails projects
- Host: GitHub
- URL: https://github.com/mohsen-alizadeh/rails-pdate
- Owner: mohsen-alizadeh
- License: mit
- Created: 2013-11-30T16:01:47.000Z (over 12 years ago)
- Default Branch: master
- Last Pushed: 2016-09-20T14:48:11.000Z (almost 10 years ago)
- Last Synced: 2025-06-28T07:03:54.598Z (about 1 year ago)
- Topics: ruby
- Language: Ruby
- Homepage:
- Size: 138 KB
- Stars: 8
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.rdoc
- License: MIT-LICENSE
Awesome Lists containing this project
README
= RailsPdate {
}[https://codeclimate.com/github/mohsen-alizadeh/rails-pdate] {
}[https://travis-ci.org/mohsen-alizadeh/rails-pdate] {
}[https://codeclimate.com/github/mohsen-alizadeh/rails-pdate/coverage] {
}[https://codeclimate.com/github/mohsen-alizadeh/rails-pdate] {
}[https://badge.fury.io/rb/rails_pdate]
rails_pdate is very simple and easy gem library that can used in rails application.
rails_pdate gem has written in rails 4.0.0 but maybe work in previous versions of rails
== install
* put rails_pdate in Gemfile like this
gem 'rails_pdate'
* run bunle install
bundle install
== Examples
* parse string to PDate object
"1368-11-09".to_pdate # => 1368-11-09
"1368/11/09".to_pdate # => 1368-11-09
"1368/11/09".to_pdate.class # => PDate
* convert Date object to PDate object ( Convert from gregorian to persian )
Date.today.to_pdate # => 1392-09-23
Date.new(1990, 1, 29).to_pdate # => 1368-11-09
* convert PDate object to Date object ( convert from persian to gregorian )
PDate.new(1367, 8, 29).to_date # => Sun, 20 Nov 1988
PDate.new(1367, 8, 29).to_date.class # => Date
* convert PDate object to formatted string
PDate.new(1368, 11, 9).strftime("%Y %m %d") # => "1368 11 09"
# '%Y' => year
# '%m' => zero padding two digit month
# '%d' => zero padding two digit day
# '%C' => year / 100
# '%y' => year % 100
# '%B' => persian month name in finglish
# '%b' => persian month name
# '%e' => day