bongabdo 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +4 -0
- data/.rvmrc +49 -0
- data/Gemfile +4 -0
- data/Rakefile +1 -0
- data/bin/bongabdo +12 -0
- data/bongabdo.gemspec +18 -0
- data/lib/bongabdo.rb +6 -0
- data/lib/bongabdo/base.rb +88 -0
- data/lib/bongabdo/core_ext.rb +13 -0
- data/lib/bongabdo/version.rb +3 -0
- data/test/bongabdo_test.rb +35 -0
- metadata +67 -0
data/.gitignore
ADDED
data/.rvmrc
ADDED
@@ -0,0 +1,49 @@
|
|
1
|
+
#!/usr/bin/env bash
|
2
|
+
|
3
|
+
# This is an RVM Project .rvmrc file, used to automatically load the ruby
|
4
|
+
# development environment upon cd'ing into the directory
|
5
|
+
|
6
|
+
# First we specify our desired <ruby>[@<gemset>], the @gemset name is optional.
|
7
|
+
environment_id="ruby-1.9.2-p180@bongabdo"
|
8
|
+
|
9
|
+
#
|
10
|
+
# First we attempt to load the desired environment directly from the environment
|
11
|
+
# file. This is very fast and efficicent compared to running through the entire
|
12
|
+
# CLI and selector. If you want feedback on which environment was used then
|
13
|
+
# insert the word 'use' after --create as this triggers verbose mode.
|
14
|
+
#
|
15
|
+
if [[ -d "${rvm_path:-$HOME/.rvm}/environments" \
|
16
|
+
&& -s "${rvm_path:-$HOME/.rvm}/environments/$environment_id" ]] ; then
|
17
|
+
\. "${rvm_path:-$HOME/.rvm}/environments/$environment_id"
|
18
|
+
|
19
|
+
[[ -s ".rvm/hooks/after_use" ]] && . ".rvm/hooks/after_use"
|
20
|
+
else
|
21
|
+
# If the environment file has not yet been created, use the RVM CLI to select.
|
22
|
+
rvm --create "$environment_id"
|
23
|
+
fi
|
24
|
+
|
25
|
+
#
|
26
|
+
# If you use an RVM gemset file to install a list of gems (*.gems), you can have
|
27
|
+
# it be automatically loaded. Uncomment the following and adjust the filename if
|
28
|
+
# necessary.
|
29
|
+
#
|
30
|
+
# filename=".gems"
|
31
|
+
# if [[ -s "$filename" ]] ; then
|
32
|
+
# rvm gemset import "$filename" | grep -v already | grep -v listed | grep -v complete | sed '/^$/d'
|
33
|
+
# fi
|
34
|
+
|
35
|
+
#
|
36
|
+
# If you use bundler and would like to run bundle each time you enter the
|
37
|
+
# directory, you can uncomment the following code.
|
38
|
+
#
|
39
|
+
# # Ensure that Bundler is installed. Install it if it is not.
|
40
|
+
# if ! command -v bundle >/dev/null; then
|
41
|
+
# printf "The rubygem 'bundler' is not installed. Installing it now.\n"
|
42
|
+
# gem install bundler
|
43
|
+
# fi
|
44
|
+
#
|
45
|
+
# # Bundle while reducing excess noise.
|
46
|
+
# printf "Bundling your gems. This may take a few minutes on a fresh clone.\n"
|
47
|
+
# bundle | grep -v '^Using ' | grep -v ' is complete' | sed '/^$/d'
|
48
|
+
#
|
49
|
+
|
data/Gemfile
ADDED
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require 'bundler/gem_tasks'
|
data/bin/bongabdo
ADDED
data/bongabdo.gemspec
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
3
|
+
require "bongabdo/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |s|
|
6
|
+
s.name = "bongabdo"
|
7
|
+
s.version = Bongabdo::VERSION
|
8
|
+
s.authors = ["Bratish Goswami"]
|
9
|
+
s.email = ["bratishgoswami@gmail.com"]
|
10
|
+
s.homepage = "https://github.com/bratish/bongabdo"
|
11
|
+
s.summary = %q{Bengali date provider module}
|
12
|
+
s.description = %q{Gregorian date to Bongabdo converter.}
|
13
|
+
|
14
|
+
s.files = `git ls-files`.split("\n")
|
15
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
16
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
17
|
+
s.require_paths = ["lib"]
|
18
|
+
end
|
data/lib/bongabdo.rb
ADDED
@@ -0,0 +1,88 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
module Bongabdo
|
4
|
+
|
5
|
+
MONTHS = [
|
6
|
+
{'bn' => "বৈশাখ", 'en' => "Boishakh"},
|
7
|
+
{'bn' => "জ্যৈষ্ঠ",'en' => "Joishtho"},
|
8
|
+
{'bn' => "আষাঢ়", 'en' => "Asharh"},
|
9
|
+
{'bn' => "শ্রাবণ", 'en' => "Srabon"},
|
10
|
+
{'bn' => "ভাদ্র", 'en' => "Bhadro"},
|
11
|
+
{'bn' => "আশ্বিন", 'en' => "Ashwin"},
|
12
|
+
{'bn' => "কার্তিক", 'en' => "Kartik"},
|
13
|
+
{'bn' => "অগ্রহায়ন", 'en' => "Agrohayon"},
|
14
|
+
{'bn' => "পৌষ", 'en' => "Poush"},
|
15
|
+
{'bn' => "মাঘ", 'en' => "Magh"},
|
16
|
+
{'bn' => "ফাল্গুন", 'en' => "Falgun"},
|
17
|
+
{'bn' => "চৈত্র", 'en' => "Chaitro"}
|
18
|
+
]
|
19
|
+
|
20
|
+
class Base
|
21
|
+
attr_accessor :year, :month, :day
|
22
|
+
|
23
|
+
def initialize(d)
|
24
|
+
@day, @month, @year = calculate(d)
|
25
|
+
end
|
26
|
+
|
27
|
+
def month_name(num, lang='bn')
|
28
|
+
MONTHS[(num % 12) - 1][lang]
|
29
|
+
end
|
30
|
+
|
31
|
+
def self.today
|
32
|
+
self.new(Time.now.to_date)
|
33
|
+
end
|
34
|
+
|
35
|
+
def to_s(lang="bn")
|
36
|
+
return "#{@day}/#{@month}/#{@year}" if lang == "en"
|
37
|
+
"#{@day.to_bn}/#{@month.to_bn}/#{@year.to_bn}"
|
38
|
+
end
|
39
|
+
|
40
|
+
def long_format(lang="bn")
|
41
|
+
return "#{@day} #{month_name(@month, 'en')}, #{@year}" if lang == "en"
|
42
|
+
"#{@day.to_bn} #{month_name(@month)}, #{@year.to_bn}"
|
43
|
+
end
|
44
|
+
|
45
|
+
|
46
|
+
private
|
47
|
+
def calculate(inputdate)
|
48
|
+
days_to_add = [17, 18, 17, 17, 17, 17, 16, 16, 16, 15, 16, 16]
|
49
|
+
days_to_sub = [13, 12, 14, 13, 14, 14, 15, 15, 15, 15, 14, 14]
|
50
|
+
bn_month_day = [31, 31, 31, 31, 31, 31, 30, 30, 30, 30, 30, 30]
|
51
|
+
|
52
|
+
bn_month_day[10] = 31 if inputdate.leap? #Falgun
|
53
|
+
|
54
|
+
#Calculating Bengali Year
|
55
|
+
bn_year = inputdate.year - 594
|
56
|
+
|
57
|
+
bn_year += 1 if inputdate.yday >= 104 # in case of leap year
|
58
|
+
|
59
|
+
#Calculating Month
|
60
|
+
bn_month = inputdate.month + 8
|
61
|
+
if inputdate.month > 4
|
62
|
+
bn_month = inputdate.month - 4
|
63
|
+
end
|
64
|
+
|
65
|
+
bn_date = inputdate.day + days_to_add[inputdate.month - 1]
|
66
|
+
|
67
|
+
if (bn_date > bn_month_day[bn_month-1])
|
68
|
+
bn_month += 1
|
69
|
+
if (bn_month > 12)
|
70
|
+
bn_month -= 12
|
71
|
+
end
|
72
|
+
bn_date = inputdate.day - days_to_sub[inputdate.month-1]
|
73
|
+
end
|
74
|
+
|
75
|
+
if (inputdate.day < 14 && inputdate.month == 3 && inputdate.leap?) #1st - 15 March of leap year
|
76
|
+
bn_date -= 1
|
77
|
+
end
|
78
|
+
|
79
|
+
if (inputdate.day == 14 && inputdate.month == 3 && inputdate.leap?) #14th March of Non Leap Year, trouble some
|
80
|
+
bn_date = 30
|
81
|
+
bn_month = 11
|
82
|
+
end
|
83
|
+
|
84
|
+
return bn_date, bn_month, bn_year
|
85
|
+
end
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
@@ -0,0 +1,35 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'test/unit'
|
4
|
+
require File.join(File.expand_path(File.dirname(__FILE__)), "..", "lib", "bongabdo", "base")
|
5
|
+
require File.join(File.expand_path(File.dirname(__FILE__)), "..", "lib", "bongabdo", "core_ext")
|
6
|
+
require 'date'
|
7
|
+
|
8
|
+
class TestBongabdo < Test::Unit::TestCase
|
9
|
+
def test_it_sets_day
|
10
|
+
assert_equal(Bongabdo::Base.new(Date.new(2001,2,3)).day, 21)
|
11
|
+
end
|
12
|
+
|
13
|
+
def test_it_sets_month
|
14
|
+
assert_equal(Bongabdo::Base.new(Date.new(2001,2,3)).month, 10)
|
15
|
+
end
|
16
|
+
|
17
|
+
def test_it_sets_year
|
18
|
+
assert_equal(Bongabdo::Base.new(Date.new(2001,2,3)).year, 1407)
|
19
|
+
end
|
20
|
+
|
21
|
+
def test_to_s
|
22
|
+
assert(Bongabdo::Base.new(Date.new(2001,2,3)), "২১/১০/১৪০৭")
|
23
|
+
end
|
24
|
+
|
25
|
+
def test_month_name
|
26
|
+
assert_equal(Bongabdo::Base.new(Date.new(2001,2,3)).month_name(2), "জ্যৈষ্ঠ")
|
27
|
+
assert_equal(Bongabdo::Base.new(Date.new(2001,2,3)).month_name(2, 'bn'), "জ্যৈষ্ঠ")
|
28
|
+
assert_equal(Bongabdo::Base.new(Date.new(2001,2,3)).month_name(2, 'en'), "Joishtho")
|
29
|
+
end
|
30
|
+
|
31
|
+
def test_long_format
|
32
|
+
assert_equal(Bongabdo::Base.new(Date.new(2001,2,3)).long_format, "২১ মাঘ, ১৪০৭")
|
33
|
+
assert_equal(Bongabdo::Base.new(Date.new(2001,2,3)).long_format('en'), "21 Magh, 1407")
|
34
|
+
end
|
35
|
+
end
|
metadata
ADDED
@@ -0,0 +1,67 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: bongabdo
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
prerelease:
|
5
|
+
version: 0.0.3
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Bratish Goswami
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
|
13
|
+
date: 2012-03-15 00:00:00 +05:30
|
14
|
+
default_executable:
|
15
|
+
dependencies: []
|
16
|
+
|
17
|
+
description: Gregorian date to Bongabdo converter.
|
18
|
+
email:
|
19
|
+
- bratishgoswami@gmail.com
|
20
|
+
executables:
|
21
|
+
- bongabdo
|
22
|
+
extensions: []
|
23
|
+
|
24
|
+
extra_rdoc_files: []
|
25
|
+
|
26
|
+
files:
|
27
|
+
- .gitignore
|
28
|
+
- .rvmrc
|
29
|
+
- Gemfile
|
30
|
+
- Rakefile
|
31
|
+
- bin/bongabdo
|
32
|
+
- bongabdo.gemspec
|
33
|
+
- lib/bongabdo.rb
|
34
|
+
- lib/bongabdo/base.rb
|
35
|
+
- lib/bongabdo/core_ext.rb
|
36
|
+
- lib/bongabdo/version.rb
|
37
|
+
- test/bongabdo_test.rb
|
38
|
+
has_rdoc: true
|
39
|
+
homepage: https://github.com/bratish/bongabdo
|
40
|
+
licenses: []
|
41
|
+
|
42
|
+
post_install_message:
|
43
|
+
rdoc_options: []
|
44
|
+
|
45
|
+
require_paths:
|
46
|
+
- lib
|
47
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
48
|
+
none: false
|
49
|
+
requirements:
|
50
|
+
- - ">="
|
51
|
+
- !ruby/object:Gem::Version
|
52
|
+
version: "0"
|
53
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
54
|
+
none: false
|
55
|
+
requirements:
|
56
|
+
- - ">="
|
57
|
+
- !ruby/object:Gem::Version
|
58
|
+
version: "0"
|
59
|
+
requirements: []
|
60
|
+
|
61
|
+
rubyforge_project:
|
62
|
+
rubygems_version: 1.6.2
|
63
|
+
signing_key:
|
64
|
+
specification_version: 3
|
65
|
+
summary: Bengali date provider module
|
66
|
+
test_files:
|
67
|
+
- test/bongabdo_test.rb
|