formatted_times 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 3db7169cb56d965f83e7890c24e2a6258f9ca027
4
- data.tar.gz: 3eeb2e6da82417ccd28b180c322e84dcf0787946
3
+ metadata.gz: 855574b5f77d303a2897e4f475b8c1b0bd417a76
4
+ data.tar.gz: ec74ca6e910e527ed18722236c68803daa867ae1
5
5
  SHA512:
6
- metadata.gz: 7d2f3a8b5bcdd355508d46542a825293e21c912ae3ea130f7750b6be9ae0d8d7c417184c91dc9554f085b13e7abf2c2aa0e753ca1002465f03685d4893d2086a
7
- data.tar.gz: 0b5de059f655e73dd831ac709e2ceb7770032087111a970abd12395ea5f2c7bc7a16d66e5e3bdf0dacfaca6435103eaab5a29e2f3a14694b1545b252acb66d76
6
+ metadata.gz: 85bfe87382bc73fd0a6160cb19f149297375a5ab675a1b44825569c3f519155e4dd639cc746616dd8ebd283c0ef264f0559e9ca332d28ab547183b7b3921bd10
7
+ data.tar.gz: 9910c68f46f07ca4030699e9ef1f361dc626b462e9110c37f43073d64af255b6e4efeb0247fcff98c9172097b206d47ef8c9775d5bb44a5ee76723ef97281ce8
data/README.md CHANGED
@@ -26,70 +26,84 @@ Or install it yourself as:
26
26
 
27
27
  # Date related options
28
28
 
29
- 'YY' => '%Y',
30
- 'CC' => '%C',
31
- 'yy' => '%y',
32
- 'mm' => '%m',
33
- 'BB' => '%B',
34
- 'bb' => '%b',
35
- 'hh' => '%h',
36
- 'dd' => '%d',
37
- 'ee' => '%e',
38
- 'jj' => '%j',
29
+ 'YY' => '%Y', # Year with century (can be negative, 4 digits at least)
30
+ # -0001, 0000, 1995, 2009, 14292, etc.
31
+ 'CC' => '%C', # year / 100 (round down. 20 in 2009)
32
+ 'yy' => '%y', # year % 100 (00..99)
33
+ 'mm' => '%m', # Month of the year, zero-padded (01..12)
34
+ # %_m blank-padded ( 1..12)
35
+ # %-m no-padded (1..12)
36
+ 'BB' => '%B', # The full month name (``January'')
37
+ # %^B uppercased (``JANUARY'')
38
+ 'bb' => '%b', # The abbreviated month name (``Jan'')
39
+ # %^b uppercased (``JAN'')
40
+ 'hh' => '%h', # Equivalent to %b
41
+ 'dd' => '%d', # Day of the month, zero-padded (01..31)
42
+ # %-d no-padded (1..31)
43
+ 'ee' => '%e', # Day of the month, blank-padded ( 1..31)
44
+ 'jj' => '%j', # Day of the year (001..366)
39
45
 
40
46
  # Time related options
41
47
 
42
- 'HH' => '%H',
43
- 'kk' => '%k',
44
- 'II' => '%I',
45
- 'll' => '%l',
46
- 'PP' => '%P',
47
- 'pp' => '%p',
48
- 'MM' => '%M',
49
- 'SS' => '%S',
50
- 'LL' => '%L',
51
- 'NN' => '%N',
52
- '3N' => '%3N',
53
- '6N' => '%6N',
54
- '9N' => '%9N',
55
- '12N' => '%12N',
48
+ 'HH' => '%H', # Hour of the day, 24-hour clock, zero-padded (00..23)
49
+ 'kk' => '%k', # Hour of the day, 24-hour clock, blank-padded ( 0..23)
50
+ 'II' => '%I', # Hour of the day, 12-hour clock, zero-padded (01..12)
51
+ 'll' => '%l', # Hour of the day, 12-hour clock, blank-padded ( 1..12)
52
+ 'PP' => '%P', # Meridian indicator, lowercase (``am'' or ``pm'')
53
+ 'pp' => '%p', # Meridian indicator, uppercase (``AM'' or ``PM'')
54
+ 'MM' => '%M', # Minute of the hour (00..59)
55
+ 'SS' => '%S', # Second of the minute (00..59)
56
+ 'LL' => '%L', # Millisecond of the second (000..999)
57
+ 'NN' => '%N', # Fractional seconds digits, default is 9 digits (nanosecond)
58
+ '3N' => '%3N', # Fractional miliseconds digits, 3 digits
59
+ '6N' => '%6N', # Fractional macroseconds digits, 6 digits
60
+ '9N' => '%9N', # Fractional nanoseconds digits, 9 digits
61
+ '12N' => '%12N', # Fractional picoseconds digits, 12 digits
56
62
 
57
63
  # Time zone related Options
58
64
 
59
- 'zz' => '%z',
60
- '1z' => '%:z',
61
- '2z' => '%::z',
62
- '3z' => '%:::z',
63
- 'ZZ' => '%Z',
65
+ 'zz' => '%z', # Time zone as hour and minute offset from UTC (e.g. +0900)
66
+ '1z' => '%:z', # hour and minute offset from UTC with a colon (e.g. +09:00)
67
+ '2z' => '%::z', # hour, minute and second offset from UTC (e.g. +09:00:00)
68
+ '3z' => '%:::z', # hour, minute and second offset from UTC (e.g. +09, +09:30, +09:30:30)
69
+ 'ZZ' => '%Z', # Time zone abbreviation name
64
70
 
65
71
  # Weekday related options
66
72
 
67
- 'AA' => '%A',
68
- 'aa' => '%a',
69
- 'uu' => '%u',
70
- 'ww' => '%w',
73
+ 'AA' => '%A', # The full weekday name (``Sunday'')
74
+ # %^A uppercased (``SUNDAY'')
75
+ 'aa' => '%a', # The abbreviated name (``Sun'')
76
+ # %^a uppercased (``SUN'')
77
+ 'uu' => '%u', # Day of the week (Monday is 1, 1..7)
78
+ 'ww' => '%w', # Day of the week (Sunday is 0, 0..6)
79
+
80
+ 'GG' => '%G', # The week-based year
81
+ 'gg' => '%g', # The last 2 digits of the week-based year (00..99)
82
+ 'VV' => '%V', # Week number of the week-based year (01..53)
83
+ 'UU' => '%U', # Week number of the year. The week starts with Sunday. (00..53)
84
+ 'WW' => '%W', # Week number of the year. The week starts with Monday. (00..53)
71
85
 
72
86
  # Seconds related opions
73
87
 
74
- 'ss' => '%s',
75
- 'QQ' => '%Q',
88
+ 'ss' => '%s', # Number of seconds since 1970-01-01 00:00:00 UTC.
89
+ 'QQ' => '%Q', # Number of microseconds since 1970-01-01 00:00:00 UTC.
76
90
 
77
91
  # Literal string related options
78
92
 
79
- 'nn' => '%n',
80
- 'tt' => '%t',
93
+ 'nn' => '%n', # Newline character (\n)
94
+ 'tt' => '%t', # Tab character (\t)
81
95
 
82
96
  # Combination Options
83
97
 
84
- 'cc' => '%c',
85
- 'DD' => '%D',
86
- 'FF' => '%F',
87
- 'vv' => '%v',
88
- 'xx' => '%x',
89
- 'XX' => '%X',
90
- 'rr' => '%r',
91
- 'RR' => '%R',
92
- 'TT' => '%T'
98
+ 'cc' => '%c', # date and time (%a %b %e %T %Y)
99
+ 'DD' => '%D', # Date (%m/%d/%y)
100
+ 'FF' => '%F', # The ISO 8601 date format (%Y-%m-%d)
101
+ 'vv' => '%v', # VMS date (%e-%b-%Y)
102
+ 'xx' => '%x', # Same as %D
103
+ 'XX' => '%X', # Same as %T
104
+ 'rr' => '%r', # 12-hour time (%I:%M:%S %p)
105
+ 'RR' => '%R', # 24-hour time (%H:%M)
106
+ 'TT' => '%T' # 24-hour time (%H:%M:%S)
93
107
  }
94
108
 
95
109
  Now if you need date, month and year out of timestamp then you can simply use :
@@ -105,6 +119,14 @@ Or install it yourself as:
105
119
  2.1.2 :020 > User.first.created_at.frmt_dd_hh_yy_HH_MM_SS
106
120
  => "27 : Sep : 14 : 08 : 44"
107
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"
127
+
128
+
129
+ 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.
108
130
 
109
131
  ## Contributing
110
132
 
@@ -49,6 +49,11 @@ module ActiveSupport
49
49
  'aa' => '%a',
50
50
  'uu' => '%u',
51
51
  'ww' => '%w',
52
+ 'GG' => '%G',
53
+ 'gg' => '%g',
54
+ 'VV' => '%V',
55
+ 'UU' => '%U',
56
+ 'WW' => '%W',
52
57
 
53
58
  # Seconds related opions
54
59
 
@@ -78,8 +83,8 @@ module ActiveSupport
78
83
  method_name = sym.to_s
79
84
 
80
85
  if method_name.starts_with? 'frmt_'
81
- if args.length == 1 and args[0].is_a?(String)
82
- strf_time_string = get_strftime_string(method_name, args[0])
86
+ if args.length.in?([1, 2]) and args[0].is_a?(String)
87
+ strf_time_string = get_strftime_string(method_name, args[0], args[1])
83
88
  else
84
89
  strf_time_string = get_strftime_string(method_name)
85
90
  end
@@ -91,15 +96,17 @@ module ActiveSupport
91
96
  raise e, e.message.sub(time.inspect, self.inspect), e.backtrace
92
97
  end
93
98
 
94
- def get_strftime_string(name, separator=' : ')
99
+ def get_strftime_string(name, *args)
100
+ separator = args[0] || ':'
101
+ multiple_separator= args[1] || false
95
102
  options = name.split('_')
96
103
  options.shift
97
- invalid_options = options - FORMATTING_OPTIONS.keys
98
104
 
105
+ invalid_options = options - FORMATTING_OPTIONS.keys
99
106
  raise ::ArgumentError, "Options #{invalid_options.join(', ')} are invalid." unless invalid_options.empty?
100
107
 
101
- options.collect{ |option| FORMATTING_OPTIONS[option] }.join(separator)
102
-
108
+ strf_options = options.collect{ |option| FORMATTING_OPTIONS[option] }
109
+ multiple_separator ? strf_options.zip(separator.chars).flatten.compact.join : strf_options.join(separator)
103
110
  end
104
111
 
105
112
  end
@@ -1,3 +1,3 @@
1
1
  module FormattedTimes
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: formatted_times
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ravi Ture
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-12-08 00:00:00.000000000 Z
11
+ date: 2014-12-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler