jquery_format_date_time_rails 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 2c255540478b5a0cd724f567bad2d88dbecd0346
4
+ data.tar.gz: cc64858349f440dc96ca9f047729a3297ba3fe87
5
+ SHA512:
6
+ metadata.gz: 999cbe9d50db2d5dfd5f41c8704f7e0adb4d1031f39c4366d3044fdc7942e5363371c8691f1ac0d1447a4e9a822dde8769a213e89f959114ea3e3230d2fa85aa
7
+ data.tar.gz: 21acc4efcb2db75bbd1e239ce76191b430cde0c651a4bee8a3396beee0c358933004423c4481b68bc0d7024877ac251d8e705dc7d6f80214297e0011730461ef
data/.gitignore ADDED
@@ -0,0 +1,36 @@
1
+ *.gem
2
+ *.rbc
3
+ /.config
4
+ /coverage/
5
+ /InstalledFiles
6
+ /pkg/
7
+ /spec/reports/
8
+ /spec/examples.txt
9
+ /test/tmp/
10
+ /test/version_tmp/
11
+ /tmp/
12
+
13
+ ## Specific to RubyMotion:
14
+ .dat*
15
+ .repl_history
16
+ build/
17
+
18
+ ## Documentation cache and generated files:
19
+ /.yardoc/
20
+ /_yardoc/
21
+ /doc/
22
+ /rdoc/
23
+
24
+ ## Environment normalization:
25
+ /.bundle/
26
+ /vendor/bundle
27
+ /lib/bundler/man/
28
+
29
+ # for a library or gem, you might want to ignore these files since the code is
30
+ # intended to run in multiple environments; otherwise, check them in:
31
+ # Gemfile.lock
32
+ # .ruby-version
33
+ # .ruby-gemset
34
+
35
+ # unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
36
+ .rvmrc
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in jquery_format_date_time_rails.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2016 Kyle McDaniel
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,47 @@
1
+ # JqueryFormatDateTimeRails
2
+
3
+ A port of jquery.formatDateTime for rails.
4
+ https://github.com/agschwender/jquery.formatDateTime
5
+
6
+ Made at v1.1.6 (commit b5f9630a1d1b7a838456ae263840d4ac4461a9a8)
7
+
8
+ ## Installation
9
+
10
+ Add this line to your application's Gemfile:
11
+
12
+ ```ruby
13
+ gem 'jquery_format_date_time_rails'
14
+ ```
15
+
16
+ And then execute:
17
+
18
+ $ bundle
19
+
20
+ Or install it yourself as:
21
+
22
+ $ gem install jquery_format_date_time_rails
23
+
24
+ Then, add the following to your app's application.js
25
+ ```ruby
26
+ //= require jquery_format_date_time_rails
27
+ ```
28
+
29
+ ## Usage
30
+
31
+ Use in your views like you would normally use the plugin. This just creates a smaller footprint.
32
+
33
+ ## Development
34
+
35
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake false` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
36
+
37
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
38
+
39
+ ## Contributing
40
+
41
+ Bug reports and pull requests are welcome on GitHub at https://github.com/mcdaniel67/jquery_format_date_time_rails.
42
+
43
+
44
+ ## License
45
+
46
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
47
+
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,271 @@
1
+ /*
2
+ * jQuery Format Date/Time - v1.1.6 - 2015-03-09
3
+ * https://github.com/agschwender/jquery.formatDateTime
4
+ * Copyright (c) 2015 Adam Gschwender
5
+ * Licensed MIT, GPLv2
6
+ */
7
+ ;(function (factory) {
8
+ if (typeof exports === 'object') {
9
+ // Node/CommonJS style for Browserify
10
+ module.exports = factory;
11
+ } else if (typeof define === 'function' && define.amd) {
12
+ // AMD. Register as an anonymous module.
13
+ define(['jquery'], factory);
14
+ } else {
15
+ // Browser globals: jQuery or jQuery-like library, such as Zepto
16
+ factory(window.jQuery || window.$);
17
+ }
18
+ }(function($) {
19
+
20
+ var ticksTo1970 = (((1970 - 1) * 365 + Math.floor(1970 / 4)
21
+ - Math.floor(1970 / 100)
22
+ + Math.floor(1970 / 400)) * 24 * 60 * 60 * 10000000);
23
+
24
+ var formatDateTime = function(format, date, settings) {
25
+ var output = '';
26
+ var literal = false;
27
+ var iFormat = 0;
28
+
29
+ // Check whether a format character is doubled
30
+ var lookAhead = function(match) {
31
+ var matches = (iFormat + 1 < format.length
32
+ && format.charAt(iFormat + 1) == match);
33
+ if (matches) {
34
+ iFormat++;
35
+ }
36
+ return matches;
37
+ };
38
+
39
+ // Format a number, with leading zero if necessary
40
+ var formatNumber = function(match, value, len) {
41
+ var num = '' + value;
42
+ if (lookAhead(match)) {
43
+ while (num.length < len) {
44
+ num = '0' + num;
45
+ }
46
+ }
47
+ return num;
48
+ };
49
+
50
+ // Format a name, short or long as requested
51
+ var formatName = function(match, value, shortNames, longNames) {
52
+ return (lookAhead(match) ? longNames[value] : shortNames[value]);
53
+ };
54
+
55
+ // Get the value for the supplied unit, e.g. year for y
56
+ var getUnitValue = function(unit) {
57
+ var utc = settings.utc;
58
+ switch (unit) {
59
+ case 'y': return utc ? date.getUTCFullYear() : date.getFullYear();
60
+ case 'm': return (utc ? date.getUTCMonth() : date.getMonth()) + 1;
61
+ case 'M': return utc ? date.getUTCMonth() : date.getMonth();
62
+ case 'd': return utc ? date.getUTCDate() : date.getDate();
63
+ case 'D': return utc ? date.getUTCDay() : date.getDay();
64
+ case 'g':
65
+ return (utc ? date.getUTCHours() : date.getHours()) % 12 || 12;
66
+ case 'h': return utc ? date.getUTCHours() : date.getHours();
67
+ case 'i': return utc ? date.getUTCMinutes() : date.getMinutes();
68
+ case 's': return utc ? date.getUTCSeconds() : date.getSeconds();
69
+ case 'u':
70
+ return utc ? date.getUTCMilliseconds() : date.getMilliseconds();
71
+ default: return '';
72
+ }
73
+ };
74
+
75
+ for (iFormat = 0; iFormat < format.length; iFormat++) {
76
+ if (literal) {
77
+ if (format.charAt(iFormat) == "'" && !lookAhead("'")) {
78
+ literal = false;
79
+ }
80
+ else {
81
+ output += format.charAt(iFormat);
82
+ }
83
+ } else {
84
+ switch (format.charAt(iFormat)) {
85
+ case 'a':
86
+ output += getUnitValue('h') < 12
87
+ ? settings.ampmNames[0]
88
+ : settings.ampmNames[1];
89
+ break;
90
+ case 'd':
91
+ output += formatNumber('d', getUnitValue('d'), 2);
92
+ break;
93
+ case 'S':
94
+ var v = getUnitValue(iFormat && format.charAt(iFormat-1));
95
+ output += (v && (settings.getSuffix || $.noop)(v)) || '';
96
+ break;
97
+ case 'D':
98
+ output += formatName('D',
99
+ getUnitValue('D'),
100
+ settings.dayNamesShort,
101
+ settings.dayNames);
102
+ break;
103
+ case 'o':
104
+ var end = new Date(date.getFullYear(),
105
+ date.getMonth(),
106
+ date.getDate()).getTime();
107
+ var start = new Date(date.getFullYear(), 0, 0).getTime();
108
+ output += formatNumber(
109
+ 'o', Math.round((end - start) / 86400000), 3);
110
+ break;
111
+ case 'g':
112
+ output += formatNumber('g', getUnitValue('g'), 2);
113
+ break;
114
+ case 'h':
115
+ output += formatNumber('h', getUnitValue('h'), 2);
116
+ break;
117
+ case 'u':
118
+ output += formatNumber('u', getUnitValue('u'), 3);
119
+ break;
120
+ case 'i':
121
+ output += formatNumber('i', getUnitValue('i'), 2);
122
+ break;
123
+ case 'm':
124
+ output += formatNumber('m', getUnitValue('m'), 2);
125
+ break;
126
+ case 'M':
127
+ output += formatName('M',
128
+ getUnitValue('M'),
129
+ settings.monthNamesShort,
130
+ settings.monthNames);
131
+ break;
132
+ case 's':
133
+ output += formatNumber('s', getUnitValue('s'), 2);
134
+ break;
135
+ case 'y':
136
+ output += (lookAhead('y')
137
+ ? getUnitValue('y')
138
+ : ('' + getUnitValue('y')).substr(2));
139
+ break;
140
+ case '@':
141
+ output += date.getTime();
142
+ break;
143
+ case '!':
144
+ output += date.getTime() * 10000 + ticksTo1970;
145
+ break;
146
+ case "'":
147
+ if (lookAhead("'")) {
148
+ output += "'";
149
+ } else {
150
+ literal = true;
151
+ }
152
+ break;
153
+ default:
154
+ output += format.charAt(iFormat);
155
+ }
156
+ }
157
+ }
158
+ return output;
159
+ };
160
+
161
+ $.fn.formatDateTime = function(format, settings) {
162
+ settings = $.extend({}, $.formatDateTime.defaults, settings);
163
+
164
+ this.each(function() {
165
+ var date = $(this).attr(settings.attribute);
166
+
167
+ // Use explicit format string first,
168
+ // then fallback to format attribute
169
+ var fmt = format || $(this).attr(settings.formatAttribute);
170
+
171
+ if (typeof date === 'undefined' || date === false) {
172
+ date = $(this).text();
173
+ }
174
+
175
+ if (date === '') {
176
+ $(this).text('');
177
+ } else {
178
+ $(this).text(formatDateTime(fmt, new Date(date), settings));
179
+ }
180
+ });
181
+
182
+ return this;
183
+ };
184
+
185
+ /**
186
+ Format a date object into a string value.
187
+ The format can be combinations of the following:
188
+ a - Ante meridiem and post meridiem
189
+ d - day of month (no leading zero)
190
+ dd - day of month (two digit)
191
+ o - day of year (no leading zeros)
192
+ oo - day of year (three digit)
193
+ D - day name short
194
+ DD - day name long
195
+ g - 12-hour hour format of day (no leading zero)
196
+ gg - 12-hour hour format of day (two digit)
197
+ h - 24-hour hour format of day (no leading zero)
198
+ hh - 24-hour hour format of day (two digit)
199
+ u - millisecond of second (no leading zeros)
200
+ uu - millisecond of second (three digit)
201
+ i - minute of hour (no leading zero)
202
+ ii - minute of hour (two digit)
203
+ m - month of year (no leading zero)
204
+ mm - month of year (two digit)
205
+ M - month name short
206
+ MM - month name long
207
+ S - ordinal suffix for the previous unit
208
+ s - second of minute (no leading zero)
209
+ ss - second of minute (two digit)
210
+ y - year (two digit)
211
+ yy - year (four digit)
212
+ @ - Unix timestamp (ms since 01/01/1970)
213
+ ! - Windows ticks (100ns since 01/01/0001)
214
+ '...' - literal text
215
+ '' - single quote
216
+
217
+ @param format string - the desired format of the date
218
+ @param date Date - the date value to format
219
+ @param settings Object - attributes include:
220
+ ampmNames string[2] - am/pm (optional)
221
+ dayNamesShort string[7] - abbreviated names of the days
222
+ from Sunday (optional)
223
+ dayNames string[7] - names of the days from Sunday (optional)
224
+ monthNamesShort string[12] - abbreviated names of the months
225
+ (optional)
226
+ monthNames string[12] - names of the months (optional)
227
+ getSuffix function(num) - accepts a number and returns
228
+ its suffix
229
+ attribute string - Attribute which stores datetime, defaults
230
+ to data-datetime, only valid when called
231
+ on dom element(s). If not present,
232
+ uses text.
233
+ formatAttribute string - Attribute which stores the format, defaults
234
+ to data-dateformat.
235
+ utc bool - render dates using UTC instead of local time
236
+ @return string - the date in the above format
237
+ */
238
+ $.formatDateTime = function(format, date, settings) {
239
+ settings = $.extend({}, $.formatDateTime.defaults, settings);
240
+ if (!date) { return ''; }
241
+ return formatDateTime(format, date, settings);
242
+ };
243
+
244
+ $.formatDateTime.defaults = {
245
+ monthNames: ['January','February','March','April','May','June',
246
+ 'July','August','September','October','November',
247
+ 'December'],
248
+ monthNamesShort: ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul',
249
+ 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'],
250
+ dayNames: ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday',
251
+ 'Friday', 'Saturday'],
252
+ dayNamesShort: ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat'],
253
+ ampmNames: ['AM', 'PM'],
254
+ getSuffix: function (num) {
255
+ if (num > 3 && num < 21) {
256
+ return 'th';
257
+ }
258
+
259
+ switch (num % 10) {
260
+ case 1: return "st";
261
+ case 2: return "nd";
262
+ case 3: return "rd";
263
+ default: return "th";
264
+ }
265
+ },
266
+ attribute: 'data-datetime',
267
+ formatAttribute: 'data-dateformat',
268
+ utc: false
269
+ };
270
+
271
+ }));
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "jquery_format_date_time_rails"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start
data/bin/setup ADDED
@@ -0,0 +1,7 @@
1
+ #!/bin/bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+
5
+ bundle install
6
+
7
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,32 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'jquery_format_date_time_rails/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "jquery_format_date_time_rails"
8
+ spec.version = JqueryFormatDateTimeRails::VERSION
9
+ spec.authors = ["Kyle McDaniel"]
10
+ spec.email = ["mcdaniel221@gmail.com"]
11
+
12
+ spec.summary = %q{Rails port of jquery.formatDateTime}
13
+ spec.description = %q{Rails port of jquery.formatDateTime. Works by just including in application.js.erb}
14
+ spec.homepage = "https://github.com/mcdaniel67/jquery_format_date_time_rails"
15
+ spec.license = "MIT"
16
+
17
+ # Prevent pushing this gem to RubyGems.org by setting 'allowed_push_host', or
18
+ # delete this section to allow pushing this gem to any host.
19
+ if spec.respond_to?(:metadata)
20
+ spec.metadata['allowed_push_host'] = "https://rubygems.org"
21
+ else
22
+ raise "RubyGems 2.0 or newer is required to protect against public gem pushes."
23
+ end
24
+
25
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
26
+ spec.bindir = "exe"
27
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
28
+ spec.require_paths = ["lib"]
29
+
30
+ spec.add_development_dependency "bundler", "~> 1.10"
31
+ spec.add_development_dependency "rake", "~> 10.0"
32
+ end
@@ -0,0 +1,6 @@
1
+ require "jquery_format_date_time_rails/version"
2
+ require "jquery_format_date_time_rails/engine"
3
+
4
+ module JqueryFormatDateTimeRails
5
+ # Your code goes here...
6
+ end
@@ -0,0 +1,4 @@
1
+ module JqueryFormatDateTimeRails
2
+ class Engine < Rails::Engine
3
+ end
4
+ end
@@ -0,0 +1,3 @@
1
+ module JqueryFormatDateTimeRails
2
+ VERSION = "0.1.0"
3
+ end
metadata ADDED
@@ -0,0 +1,85 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: jquery_format_date_time_rails
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Kyle McDaniel
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2016-04-04 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.10'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.10'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ description: Rails port of jquery.formatDateTime. Works by just including in application.js.erb
42
+ email:
43
+ - mcdaniel221@gmail.com
44
+ executables: []
45
+ extensions: []
46
+ extra_rdoc_files: []
47
+ files:
48
+ - ".gitignore"
49
+ - Gemfile
50
+ - LICENSE.txt
51
+ - README.md
52
+ - Rakefile
53
+ - app/assets/javascripts/jquery_format_date_time_rails.js
54
+ - bin/console
55
+ - bin/setup
56
+ - jquery_format_date_time_rails.gemspec
57
+ - lib/jquery_format_date_time_rails.rb
58
+ - lib/jquery_format_date_time_rails/engine.rb
59
+ - lib/jquery_format_date_time_rails/version.rb
60
+ homepage: https://github.com/mcdaniel67/jquery_format_date_time_rails
61
+ licenses:
62
+ - MIT
63
+ metadata:
64
+ allowed_push_host: https://rubygems.org
65
+ post_install_message:
66
+ rdoc_options: []
67
+ require_paths:
68
+ - lib
69
+ required_ruby_version: !ruby/object:Gem::Requirement
70
+ requirements:
71
+ - - ">="
72
+ - !ruby/object:Gem::Version
73
+ version: '0'
74
+ required_rubygems_version: !ruby/object:Gem::Requirement
75
+ requirements:
76
+ - - ">="
77
+ - !ruby/object:Gem::Version
78
+ version: '0'
79
+ requirements: []
80
+ rubyforge_project:
81
+ rubygems_version: 2.2.2
82
+ signing_key:
83
+ specification_version: 4
84
+ summary: Rails port of jquery.formatDateTime
85
+ test_files: []