formatted_times 0.0.4 → 0.0.5

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,15 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: e2b2caa1b5c3262a52e5ffe41ba0115c0c9bab9d
4
- data.tar.gz: 9d239141b1cb9e5b56aea7fe9cd68b445cb946cc
2
+ !binary "U0hBMQ==":
3
+ metadata.gz: !binary |-
4
+ OTgzMTNjZDM5NjlkZDZhNjNmNzkyODM3NzQwNjMyMmQwMWI3NDNjMQ==
5
+ data.tar.gz: !binary |-
6
+ OWU1YTlmZWQyODc4OTJhNDFiNjcxNDY4ZTJjYzcyMjM3NjQ5NTQ3NA==
5
7
  SHA512:
6
- metadata.gz: f0ab070c6449962d2605119154df3bc543a69de3c0d66e6839eb6546aff0d7ec5425fad6d83b906272e4ffe5a3117a56f264e19611285d3dfe82157031a0f5bd
7
- data.tar.gz: 550d2956d66f7909d82d46baf97665f1cb98c85d98c44ad71588d5286822e11cfa7c85ea0af43b3e168a4ea78f3ef543074ab18796be8b6fd21479fbf9eb4b02
8
+ metadata.gz: !binary |-
9
+ MDA5MDcwYzVhZmI0MzI0NjNlZGNkNDVhYTM3NTkwMGU5ODM3ZTE5ODA2ZGU2
10
+ MDdiNDY1OGE5N2JmYmZjMTg3NjBhNzM1ODc0NzM5OGE1MzAzYTdkZTg3NjEz
11
+ YzQ1ZGU4OTZhNDk5NjJiNGNjMTRjNGNmNTM5OTE1ZTIwMzMwODA=
12
+ data.tar.gz: !binary |-
13
+ ZmM2ZDVlOGY2Zjg2YWQ2N2Q4OWVkMzFmNDAwNmE5ZjM0OGVkYzUyN2JlOTI5
14
+ NzcwN2M0NWRlNGZlZGYzNDFlNGFlNTc4MTczNWJiNWE3ZWQ1NTEyNWIwNGI2
15
+ NGRiNzhlZDVjN2Q2NDkzZjk2NjdjYzdmMjIxM2IyYzZiNTUwNGI=
data/README.md CHANGED
@@ -113,27 +113,40 @@ Or install it yourself as:
113
113
  # Getting desizered seperator
114
114
  User.first.created_at.frmt_dd_mm_yy '/' #=> "27/09/14"
115
115
 
116
- # Some simple usage:
116
+ # Usage:
117
117
  2.1.2 :012 > User.first.created_at.frmt_dd_hh_yy ', '
118
118
  => "27, Sep, 14"
119
119
  2.1.2 :020 > User.first.created_at.frmt_dd_hh_yy_HH_MM_SS
120
120
  => "27 : Sep : 14 : 08 : 44"
121
121
 
122
- # Multiple seperators
123
- 2.1.2 :002 > User.first.created_at.frmt_dd_mm_yy(', ', true)
124
- => "27,09 14"
125
- 2.1.2 :006 > User.first.created_at.frmt_dd_hh_yy(',-', true)
126
- => "27,Sep-14"
122
+ # To format Date object :
123
+ 2.1.2 :002 > Date.today.frmt_dd_mm_yy
124
+ => "21/06/16"
125
+
126
+ # To format datetime object from current timestamp :
127
+ 2.1.2 :007 > Time.now.frmt_dd_hh_yy_HH_MM_SS
128
+ => "21/Jun/16/13/49/16"
129
+
130
+ 2.1.2 :003 > DateTime.now.frmt_dd_hh_yy_HH_MM_SS
131
+ => "21/Jun/16/13/50/16"
132
+
133
+
134
+ # Multiple seperators
135
+ 2.1.2 :002 > User.first.created_at.frmt_dd_mm_yy(', ', true)
136
+ => "27,09 14"
137
+ 2.1.2 :006 > User.first.created_at.frmt_dd_hh_yy(',-', true)
138
+ => "27,Sep-14"
127
139
 
128
140
 
129
141
  Methods from formatted times accepts two arguments a string as seperator and boolean to specify weather given separator is to be used as multiple separator string or single separator string. In case of multiple separator strings the separator strings are devided into character arrays and interleaved into the strftime methods option string.
130
142
 
131
- Now you can add custom formats with a hash where its key will be the name of the method to call and value will be strftime argument string. Please refer following example:
132
- # Custom format definition
133
- > FormattedTimes.define_formats({:short_date => '%d %h, %Y'})
134
- # after execution of above statement you can use
135
- > User.first.created_at.short_date
136
- => "18 Nov, 2014"
143
+ Now you can add custom formats with a hash where its key will be the name of the method to call and value will be strftime argument string. Please refer following example.
144
+
145
+ #Custom format definition
146
+ FormattedTimes.define_formats({:short_date => '%d %h, %Y'})
147
+ #after execution of above statement you can use
148
+ User.first.created_at.short_date
149
+ => "18 Nov, 2014"
137
150
 
138
151
 
139
152
  ## Contributing
@@ -142,4 +155,4 @@ Now you can add custom formats with a hash where its key will be the name of the
142
155
  2. Create your feature branch (`git checkout -b my-new-feature`)
143
156
  3. Commit your changes (`git commit -am 'Add some feature'`)
144
157
  4. Push to the branch (`git push origin my-new-feature`)
145
- 5. Create new Pull Request
158
+ 5. Create new Pull Request
@@ -1 +1,2 @@
1
1
  Ravi Ture
2
+ Amit Sharma
@@ -10,7 +10,7 @@ Gem::Specification.new do |spec|
10
10
  spec.email = ["raviture@gmail.com"]
11
11
  spec.summary = %q{Provides way for clean formatted time stamps}
12
12
  spec.description = %q{This gem simply overrides the method_missing of ActiveSupport::TimeWithZone module and includes the functionality for responding to various methods that will retrieve a time stamp in required format.}
13
- spec.homepage = ""
13
+ spec.homepage = "https://github.com/ravi-ture/formatted_times"
14
14
  spec.license = "MIT"
15
15
 
16
16
  spec.files = `git ls-files`.split($/)
@@ -1,4 +1,6 @@
1
+ require "formatted_times/format_time"
1
2
  require "formatted_times/active_support_ext"
3
+ require "formatted_times/date_time_ext"
2
4
  require "formatted_times/version"
3
5
 
4
6
 
@@ -1,81 +1,7 @@
1
1
 
2
2
  module ActiveSupport
3
3
  class TimeWithZone
4
-
5
- FORMATTING_OPTIONS = {
6
-
7
- # Date related options
8
-
9
- 'YY' => '%Y',
10
- 'CC' => '%C',
11
- 'yy' => '%y',
12
- 'mm' => '%m',
13
- 'BB' => '%B',
14
- 'bb' => '%b',
15
- 'hh' => '%h',
16
- 'dd' => '%d',
17
- 'ee' => '%e',
18
- 'jj' => '%j',
19
-
20
- # Time related options
21
-
22
- 'HH' => '%H',
23
- 'kk' => '%k',
24
- 'II' => '%I',
25
- 'll' => '%l',
26
- 'PP' => '%P',
27
- 'pp' => '%p',
28
- 'MM' => '%M',
29
- 'SS' => '%S',
30
- 'LL' => '%L',
31
- 'NN' => '%N',
32
- '3N' => '%3N',
33
- '6N' => '%6N',
34
- '9N' => '%9N',
35
- '12N' => '%12N',
36
-
37
- # Time zone related Options
38
-
39
- 'zz' => '%z',
40
- '1z' => '%:z',
41
- '2z' => '%::z',
42
- '3z' => '%:::z',
43
- 'ZZ' => '%Z',
44
-
45
- # Weekday related options
46
-
47
- 'AA' => '%A',
48
- 'aa' => '%a',
49
- 'uu' => '%u',
50
- 'ww' => '%w',
51
- 'GG' => '%G',
52
- 'gg' => '%g',
53
- 'VV' => '%V',
54
- 'UU' => '%U',
55
- 'WW' => '%W',
56
-
57
- # Seconds related opions
58
-
59
- 'ss' => '%s',
60
- 'QQ' => '%Q',
61
-
62
- # Literal string related options
63
-
64
- 'nn' => '%n',
65
- 'tt' => '%t',
66
-
67
- # Combination Options
68
-
69
- 'cc' => '%c',
70
- 'DD' => '%D',
71
- 'FF' => '%F',
72
- 'vv' => '%v',
73
- 'xx' => '%x',
74
- 'XX' => '%X',
75
- 'rr' => '%r',
76
- 'RR' => '%R',
77
- 'TT' => '%T'
78
- }
4
+ include FormatTime
79
5
 
80
6
  def method_missing(sym, *args, &block)
81
7
  method_name = sym.to_s
@@ -93,19 +19,5 @@ module ActiveSupport
93
19
  rescue NoMethodError => e
94
20
  raise e, e.message.sub(time.inspect, self.inspect), e.backtrace
95
21
  end
96
-
97
- def get_strftime_string(name, *args)
98
- separator = args[0] || ':'
99
- multiple_separator= args[1] || false
100
- options = name.split('_')
101
- options.shift
102
-
103
- invalid_options = options - FORMATTING_OPTIONS.keys
104
- raise ::ArgumentError, "Options #{invalid_options.join(', ')} are invalid." unless invalid_options.empty?
105
-
106
- strf_options = options.collect{ |option| FORMATTING_OPTIONS[option] }
107
- multiple_separator ? strf_options.zip(separator.chars).flatten.compact.join : strf_options.join(separator)
108
- end
109
-
110
22
  end
111
23
  end
@@ -0,0 +1,29 @@
1
+ module DateTimeExt
2
+ include FormatTime
3
+
4
+ def method_missing(sym, *args, &block)
5
+
6
+ method_name = sym.to_s
7
+
8
+ if method_name.starts_with? 'frmt_'
9
+ if args.length.in?([1, 2]) and args[0].is_a?(String)
10
+ strf_time_string = get_strftime_string(method_name, args[0], args[1])
11
+ else
12
+ strf_time_string = get_strftime_string(method_name)
13
+ end
14
+ return self.strftime(strf_time_string)
15
+ else
16
+ raise NoMethodError, "undefined method `#{method_name}' for #{self.inspect}:#{self.class.name}"
17
+ end
18
+
19
+ rescue NoMethodError => e
20
+ raise e, e.message.sub(self.inspect, self.inspect), e.backtrace
21
+ end
22
+ end
23
+
24
+ class Date; include DateTimeExt end
25
+
26
+ class DateTime; include DateTimeExt end
27
+
28
+ class Time; include DateTimeExt end
29
+
@@ -0,0 +1,90 @@
1
+ module FormatTime
2
+
3
+ FORMATTING_OPTIONS = {
4
+
5
+ # Date related options
6
+
7
+ 'YY' => '%Y',
8
+ 'CC' => '%C',
9
+ 'yy' => '%y',
10
+ 'mm' => '%m',
11
+ 'BB' => '%B',
12
+ 'bb' => '%b',
13
+ 'hh' => '%h',
14
+ 'dd' => '%d',
15
+ 'ee' => '%e',
16
+ 'jj' => '%j',
17
+
18
+ # Time related options
19
+
20
+ 'HH' => '%H',
21
+ 'kk' => '%k',
22
+ 'II' => '%I',
23
+ 'll' => '%l',
24
+ 'PP' => '%P',
25
+ 'pp' => '%p',
26
+ 'MM' => '%M',
27
+ 'SS' => '%S',
28
+ 'LL' => '%L',
29
+ 'NN' => '%N',
30
+ '3N' => '%3N',
31
+ '6N' => '%6N',
32
+ '9N' => '%9N',
33
+ '12N' => '%12N',
34
+
35
+ # Time zone related Options
36
+
37
+ 'zz' => '%z',
38
+ '1z' => '%:z',
39
+ '2z' => '%::z',
40
+ '3z' => '%:::z',
41
+ 'ZZ' => '%Z',
42
+
43
+ # Weekday related options
44
+
45
+ 'AA' => '%A',
46
+ 'aa' => '%a',
47
+ 'uu' => '%u',
48
+ 'ww' => '%w',
49
+ 'GG' => '%G',
50
+ 'gg' => '%g',
51
+ 'VV' => '%V',
52
+ 'UU' => '%U',
53
+ 'WW' => '%W',
54
+
55
+ # Seconds related opions
56
+
57
+ 'ss' => '%s',
58
+ 'QQ' => '%Q',
59
+
60
+ # Literal string related options
61
+
62
+ 'nn' => '%n',
63
+ 'tt' => '%t',
64
+
65
+ # Combination Options
66
+
67
+ 'cc' => '%c',
68
+ 'DD' => '%D',
69
+ 'FF' => '%F',
70
+ 'vv' => '%v',
71
+ 'xx' => '%x',
72
+ 'XX' => '%X',
73
+ 'rr' => '%r',
74
+ 'RR' => '%R',
75
+ 'TT' => '%T'
76
+ }
77
+
78
+ def get_strftime_string(name, *args)
79
+ separator = args[0] || '/'
80
+ multiple_separator= args[1] || false
81
+ options = name.split('_')
82
+ options.shift
83
+
84
+ invalid_options = options - FORMATTING_OPTIONS.keys
85
+ raise ::ArgumentError, "Options #{invalid_options.join(', ')} are invalid." unless invalid_options.empty?
86
+
87
+ strf_options = options.collect{ |option| FORMATTING_OPTIONS[option] }
88
+ multiple_separator ? strf_options.zip(separator.chars).flatten.compact.join : strf_options.join(separator)
89
+ end
90
+ end
@@ -1,3 +1,3 @@
1
1
  module FormattedTimes
2
- VERSION = "0.0.4"
2
+ VERSION = "0.0.5"
3
3
  end
metadata CHANGED
@@ -1,55 +1,55 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: formatted_times
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
4
+ version: 0.0.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ravi Ture
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-03-03 00:00:00.000000000 Z
11
+ date: 2016-07-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - "~>"
17
+ - - ~>
18
18
  - !ruby/object:Gem::Version
19
19
  version: '1.5'
20
20
  type: :development
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - "~>"
24
+ - - ~>
25
25
  - !ruby/object:Gem::Version
26
26
  version: '1.5'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: rake
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - ">="
31
+ - - ! '>='
32
32
  - !ruby/object:Gem::Version
33
33
  version: '0'
34
34
  type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - ">="
38
+ - - ! '>='
39
39
  - !ruby/object:Gem::Version
40
40
  version: '0'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: rails
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - "~>"
45
+ - - ~>
46
46
  - !ruby/object:Gem::Version
47
47
  version: 2.1.0
48
48
  type: :development
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
- - - "~>"
52
+ - - ~>
53
53
  - !ruby/object:Gem::Version
54
54
  version: 2.1.0
55
55
  description: This gem simply overrides the method_missing of ActiveSupport::TimeWithZone
@@ -61,7 +61,7 @@ executables: []
61
61
  extensions: []
62
62
  extra_rdoc_files: []
63
63
  files:
64
- - ".gitignore"
64
+ - .gitignore
65
65
  - Gemfile
66
66
  - LICENSE.txt
67
67
  - README.md
@@ -70,8 +70,10 @@ files:
70
70
  - formatted_times.gemspec
71
71
  - lib/formatted_times.rb
72
72
  - lib/formatted_times/active_support_ext.rb
73
+ - lib/formatted_times/date_time_ext.rb
74
+ - lib/formatted_times/format_time.rb
73
75
  - lib/formatted_times/version.rb
74
- homepage: ''
76
+ homepage: https://github.com/ravi-ture/formatted_times
75
77
  licenses:
76
78
  - MIT
77
79
  metadata: {}
@@ -81,17 +83,17 @@ require_paths:
81
83
  - lib
82
84
  required_ruby_version: !ruby/object:Gem::Requirement
83
85
  requirements:
84
- - - ">="
86
+ - - ! '>='
85
87
  - !ruby/object:Gem::Version
86
88
  version: '0'
87
89
  required_rubygems_version: !ruby/object:Gem::Requirement
88
90
  requirements:
89
- - - ">="
91
+ - - ! '>='
90
92
  - !ruby/object:Gem::Version
91
93
  version: '0'
92
94
  requirements: []
93
95
  rubyforge_project:
94
- rubygems_version: 2.2.2
96
+ rubygems_version: 2.4.3
95
97
  signing_key:
96
98
  specification_version: 4
97
99
  summary: Provides way for clean formatted time stamps