moments 0.1.0 → 0.2.0

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
  SHA256:
3
- metadata.gz: 2cfe9d93c489151bacb9c2c4b8de955a038db05cddf2a6d7edcb60c24532f8f3
4
- data.tar.gz: be776d177f3878449fb8aabab929cbe84bb31965e428cef9c31bd72d3ce964a7
3
+ metadata.gz: 0b85363c9163c9935f75833c74b4e7d587cc70d962ca4f86e14e6d8a3bb14196
4
+ data.tar.gz: 1a6421e682139a2cefb0b82d12bcd5d08cb2f8220ab20a65f9646938e0ee1653
5
5
  SHA512:
6
- metadata.gz: 6b231e18ee429b37402e44571866f860a57e8b86957db6a18a75463fb6c3e325b7b7ec5dfe1da62d01259d78b749f3272bbd1c3078c268b8d1fbfcb70a3e55db
7
- data.tar.gz: fab01ca909e9c5418ad1ca734a4709e11a81effe6bc283bf8cb5174f2d62548d29bd7a3bedc85be2c2b23902f6f614694bc45dc229184bb657c00bf0373dfdf4
6
+ metadata.gz: 360367e75466166fc7bb786fa4d0247b23d7ba61b118286bc137c7b697ef25a12bf3d847f0b2907de9a899ee1d3132298b5196ef93387b536e800fca8132c24a
7
+ data.tar.gz: e374f88fd8029894bdeee1e0ea79ae58188552fe43438dfb56e37335a36121b91c6b14e0d8b7a814ff0901c10c9928916051f1ea38a1b28997bce3ff47f932a9
data/.rspec CHANGED
@@ -1,4 +1,2 @@
1
- --warnings
2
- --color
3
- --format documentation
4
1
  --require spec_helper
2
+ --color
data/.rubocop.yml CHANGED
@@ -1,42 +1,81 @@
1
- Layout/LineLength:
1
+ # inherit_from: .rubocop_todo.yml
2
+
3
+ AllCops:
4
+ TargetRubyVersion: 2.5
5
+ NewCops: enable
6
+ SuggestExtensions: false
7
+ Exclude:
8
+ - 'gemfiles/*.gemfile'
9
+ - 'vendor/**/*'
10
+
11
+ Style/Documentation:
12
+ Enabled: false
13
+
14
+ Style/BlockDelimiters:
15
+ Exclude:
16
+ - spec/**/*_spec.rb
17
+
18
+ Style/GuardClause:
19
+ Enabled: false
20
+
21
+ Style/IfUnlessModifier:
22
+ Enabled: false
23
+
24
+ Layout/SpaceInsideHashLiteralBraces:
25
+ Enabled: false
26
+
27
+ Style/Lambda:
28
+ Enabled: false
29
+
30
+ Style/RaiseArgs:
31
+ Enabled: false
32
+
33
+ Style/SignalException:
34
+ Enabled: false
35
+
36
+ Metrics/AbcSize:
37
+ Max: 25
38
+
39
+ Metrics/ClassLength:
40
+ Max: 120
41
+
42
+ Metrics/ModuleLength:
2
43
  Max: 100
44
+
45
+ Layout/LineLength:
46
+ Enabled: false
47
+
48
+ Metrics/BlockLength:
49
+ Exclude:
50
+ - spec/**/*_spec.rb
51
+
52
+ Metrics/MethodLength:
53
+ Max: 15
54
+
55
+ Style/SingleLineBlockParams:
56
+ Enabled: false
57
+
58
+ Layout/EndAlignment:
59
+ EnforcedStyleAlignWith: variable
60
+
61
+ Style/FormatString:
62
+ Enabled: false
63
+
64
+ Layout/MultilineMethodCallIndentation:
65
+ EnforcedStyle: indented
66
+
3
67
  Layout/MultilineOperationIndentation:
4
68
  EnforcedStyle: indented
5
- Layout/ArgumentAlignment:
6
- EnforcedStyle: with_fixed_indentation
7
- Layout/EmptyLinesAroundAttributeAccessor:
8
- Enabled: true
9
- Layout/SpaceAroundMethodCallOperator:
10
- Enabled: true
11
69
 
12
- Lint/DeprecatedOpenSSLConstant:
13
- Enabled: true
14
- Lint/MixedRegexpCaptureTypes:
15
- Enabled: true
16
- Lint/RaiseException:
17
- Enabled: true
18
- Lint/StructNewOverride:
19
- Enabled: true
70
+ Style/WordArray:
71
+ Enabled: false
20
72
 
21
- Style/ExponentialNotation:
22
- Enabled: true
23
- Style/HashEachMethods:
24
- Enabled: true
25
- Style/HashTransformKeys:
26
- Enabled: true
27
- Style/HashTransformValues:
28
- Enabled: true
29
- Style/RedundantFetchBlock:
30
- Enabled: true
31
- Style/RedundantRegexpCharacterClass:
32
- Enabled: true
33
- Style/RedundantRegexpEscape:
34
- Enabled: true
35
- Style/SlicingWithRange:
73
+ Style/RedundantSelf:
74
+ Enabled: false
75
+
76
+ Layout/HashAlignment:
36
77
  Enabled: true
78
+ EnforcedLastArgumentHashStyle: always_ignore
37
79
 
38
- Metrics/ParameterLists:
39
- CountKeywordArgs: false
40
- Metrics/BlockLength:
41
- Exclude:
42
- - spec/**/*
80
+ Style/TrivialAccessors:
81
+ AllowPredicates: true
data/CHANGELOG.md CHANGED
@@ -1,20 +1,31 @@
1
1
  # Changelog
2
2
 
3
- ## [v0.1.0](https://github.com/excpt/moments/tree/v0.1.0) (2020-08-18)
3
+ ## [Unreleased](https://github.com/excpt/moments/tree/HEAD)
4
4
 
5
- [Full Changelog](https://github.com/excpt/moments/compare/v0.0.2.alpha...v0.1.0)
5
+ [Full Changelog](https://github.com/excpt/moments/compare/v0.1.0...HEAD)
6
6
 
7
7
  **Closed issues:**
8
8
 
9
- - Replace Travis CI with another CI [\#3](https://github.com/excpt/moments/issues/3)
9
+ - Make a new release [\#7](https://github.com/excpt/moments/issues/7)
10
10
 
11
11
  **Merged pull requests:**
12
12
 
13
- - Fix `\#in\_\*` for times with miliseconds [\#6](https://github.com/excpt/moments/pull/6) ([AlexWayfer](https://github.com/AlexWayfer))
14
- - Fix diffs with different timezones, `Date` diffs and `\#in\_years` [\#5](https://github.com/excpt/moments/pull/5) ([AlexWayfer](https://github.com/AlexWayfer))
15
- - Add `\#in\_\*` methods, like `\#in\_seconds` [\#4](https://github.com/excpt/moments/pull/4) ([AlexWayfer](https://github.com/AlexWayfer))
13
+ - Parse string input whenever possible [\#10](https://github.com/excpt/moments/pull/10) ([RomanVanLoo](https://github.com/RomanVanLoo))
14
+ - Add `in_weeks` [\#9](https://github.com/excpt/moments/pull/9) ([RomanVanLoo](https://github.com/RomanVanLoo))
15
+ - Release 0.1.0 [\#8](https://github.com/excpt/moments/pull/8) ([excpt](https://github.com/excpt))
16
+ - Fix `#in_*` for times with miliseconds [\#6](https://github.com/excpt/moments/pull/6) ([AlexWayfer](https://github.com/AlexWayfer))
17
+ - Fix diffs with different timezones, `Date` diffs and `#in_years` [\#5](https://github.com/excpt/moments/pull/5) ([AlexWayfer](https://github.com/AlexWayfer))
18
+ - Add `#in_*` methods, like `#in_seconds` [\#4](https://github.com/excpt/moments/pull/4) ([AlexWayfer](https://github.com/AlexWayfer))
16
19
  - Many improvements [\#2](https://github.com/excpt/moments/pull/2) ([AlexWayfer](https://github.com/AlexWayfer))
17
20
 
21
+ ## [v0.1.0](https://github.com/excpt/moments/tree/v0.1.0) (2020-08-18)
22
+
23
+ [Full Changelog](https://github.com/excpt/moments/compare/v0.0.2.alpha...v0.1.0)
24
+
25
+ **Closed issues:**
26
+
27
+ - Replace Travis CI with another CI [\#3](https://github.com/excpt/moments/issues/3)
28
+
18
29
  ## [v0.0.2.alpha](https://github.com/excpt/moments/tree/v0.0.2.alpha) (2014-11-14)
19
30
 
20
31
  [Full Changelog](https://github.com/excpt/moments/compare/v0.0.1.alpha...v0.0.2.alpha)
@@ -65,11 +65,15 @@ module Moments
65
65
  in_hours / 24
66
66
  end
67
67
 
68
+ def in_weeks
69
+ in_days / 7
70
+ end
71
+
68
72
  def in_months
69
73
  months_diff = @ordered_to.month - @ordered_from.month
70
74
  months_diff -= 1 if months_diff.positive? && @ordered_to.mday < @ordered_from.mday
71
75
 
72
- (@ordered_to.year - @ordered_from.year) * 12 + months_diff
76
+ ((@ordered_to.year - @ordered_from.year) * 12) + months_diff
73
77
  end
74
78
 
75
79
  def in_years
@@ -96,12 +100,22 @@ module Moments
96
100
  when *TIME_CLASSES
97
101
  value.to_time.getutc
98
102
  when Date
99
- value
103
+ value.to_time
104
+ when String
105
+ begin
106
+ Time.parse(value).getutc
107
+ rescue ArgumentError
108
+ unsupported_format
109
+ end
100
110
  else
101
- raise ArgumentError, 'Unsupported format'
111
+ unsupported_format
102
112
  end
103
113
  end
104
114
 
115
+ def unsupported_format
116
+ raise ArgumentError, 'Unsupported format'
117
+ end
118
+
105
119
  def precise_difference
106
120
  @diff = calculate_diff
107
121
 
@@ -11,7 +11,7 @@ module Moments
11
11
  # major version
12
12
  MAJOR = 0
13
13
  # minor version
14
- MINOR = 1
14
+ MINOR = 2
15
15
  # patch version
16
16
  PATCH = 0
17
17
  # alpha, beta, etc. tag
data/moments.gemspec CHANGED
@@ -11,15 +11,15 @@ Gem::Specification.new do |spec|
11
11
  spec.description = ''
12
12
  spec.homepage = 'https://github.com/excpt/moments'
13
13
  spec.license = 'MIT'
14
+ spec.metadata['rubygems_mfa_required'] = 'true'
14
15
 
15
16
  spec.files = `git ls-files -z`.split("\x0")
16
17
  spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
17
- spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
18
18
  spec.require_paths = ['lib']
19
19
 
20
- spec.add_development_dependency 'bundler', '>= 1', '< 3'
21
- spec.add_development_dependency 'codeclimate-test-reporter', '~> 1.0'
22
- spec.add_development_dependency 'rake', '~> 13.0'
23
- spec.add_development_dependency 'rspec', '~> 3.0'
24
- spec.add_development_dependency 'rubocop', '~> 0.86.0'
20
+ spec.add_development_dependency 'bundler'
21
+ spec.add_development_dependency 'github_changelog_generator'
22
+ spec.add_development_dependency 'rake'
23
+ spec.add_development_dependency 'rspec'
24
+ spec.add_development_dependency 'rubocop'
25
25
  end
@@ -333,7 +333,10 @@ describe Moments::Difference do
333
333
  {
334
334
  years: 6,
335
335
  months: 5,
336
- days: 4
336
+ days: 4,
337
+ hours: 0,
338
+ minutes: 0,
339
+ seconds: 0
337
340
  }
338
341
  end
339
342
 
@@ -444,14 +447,7 @@ describe Moments::Difference do
444
447
  end
445
448
  end
446
449
 
447
- shared_examples 'in a component' do |
448
- when_seconds:,
449
- when_minutes:,
450
- when_hours:,
451
- when_days:,
452
- when_months:,
453
- when_years:
454
- |
450
+ shared_examples 'in a component' do |when_seconds:, when_minutes:, when_hours:, when_days:, when_months:, when_years:|
455
451
  context 'with equal dates' do
456
452
  let(:to) { from }
457
453
 
@@ -668,23 +664,23 @@ describe Moments::Difference do
668
664
  subject { Moments::Difference.new(from, to).in_seconds }
669
665
 
670
666
  include_examples 'in a component',
671
- when_seconds: 15,
672
- when_minutes: 12 * 60 + 15,
673
- when_hours: 8 * 60 * 60 + 12 * 60 + 15,
674
- when_days: 6 * 24 * 60 * 60 + 8 * 60 * 60 + 12 * 60 + 15,
675
- when_months:
676
- (31 + 28 + 31 + 30) * 24 * 60 * 60 +
677
- 6 * 24 * 60 * 60 +
678
- 8 * 60 * 60 +
679
- 12 * 60 +
680
- 15,
681
- when_years:
682
- 2 * 365 * 24 * 60 * 60 +
683
- (31 + 28 + 31 + 30) * 24 * 60 * 60 +
684
- 6 * 24 * 60 * 60 +
685
- 8 * 60 * 60 +
686
- 12 * 60 +
687
- 15
667
+ when_seconds: 15,
668
+ when_minutes: (12 * 60) + 15,
669
+ when_hours: (8 * 60 * 60) + (12 * 60) + 15,
670
+ when_days: (6 * 24 * 60 * 60) + (8 * 60 * 60) + (12 * 60) + 15,
671
+ when_months:
672
+ ((31 + 28 + 31 + 30) * 24 * 60 * 60) +
673
+ (6 * 24 * 60 * 60) +
674
+ (8 * 60 * 60) +
675
+ (12 * 60) +
676
+ 15,
677
+ when_years:
678
+ (2 * 365 * 24 * 60 * 60) +
679
+ ((31 + 28 + 31 + 30) * 24 * 60 * 60) +
680
+ (6 * 24 * 60 * 60) +
681
+ (8 * 60 * 60) +
682
+ (12 * 60) +
683
+ 15
688
684
 
689
685
  context 'with miliseconds' do
690
686
  context 'when `to` is a bit greater' do
@@ -721,81 +717,81 @@ describe Moments::Difference do
721
717
  subject { Moments::Difference.new(from, to).in_minutes }
722
718
 
723
719
  include_examples 'in a component',
724
- when_seconds: 0,
725
- when_minutes: 12,
726
- when_hours: 8 * 60 + 12,
727
- when_days: 6 * 24 * 60 + 8 * 60 + 12,
728
- when_months:
729
- (31 + 28 + 31 + 30) * 24 * 60 +
730
- 6 * 24 * 60 +
731
- 8 * 60 +
732
- 12,
733
- when_years:
734
- 2 * 365 * 24 * 60 +
735
- (31 + 28 + 31 + 30) * 24 * 60 +
736
- 6 * 24 * 60 +
737
- 8 * 60 +
738
- 12
720
+ when_seconds: 0,
721
+ when_minutes: 12,
722
+ when_hours: (8 * 60) + 12,
723
+ when_days: (6 * 24 * 60) + (8 * 60) + 12,
724
+ when_months:
725
+ ((31 + 28 + 31 + 30) * 24 * 60) +
726
+ (6 * 24 * 60) +
727
+ (8 * 60) +
728
+ 12,
729
+ when_years:
730
+ (2 * 365 * 24 * 60) +
731
+ ((31 + 28 + 31 + 30) * 24 * 60) +
732
+ (6 * 24 * 60) +
733
+ (8 * 60) +
734
+ 12
739
735
  end
740
736
 
741
737
  context '#in_hours' do
742
738
  subject { Moments::Difference.new(from, to).in_hours }
743
739
 
744
740
  include_examples 'in a component',
745
- when_seconds: 0,
746
- when_minutes: 0,
747
- when_hours: 8,
748
- when_days: 6 * 24 + 8,
749
- when_months:
750
- (31 + 28 + 31 + 30) * 24 +
751
- 6 * 24 +
752
- 8,
753
- when_years:
754
- 2 * 365 * 24 +
755
- (31 + 28 + 31 + 30) * 24 +
756
- 6 * 24 +
757
- 8
741
+ when_seconds: 0,
742
+ when_minutes: 0,
743
+ when_hours: 8,
744
+ when_days: (6 * 24) + 8,
745
+ when_months:
746
+ ((31 + 28 + 31 + 30) * 24) +
747
+ (6 * 24) +
748
+ 8,
749
+ when_years:
750
+ (2 * 365 * 24) +
751
+ ((31 + 28 + 31 + 30) * 24) +
752
+ (6 * 24) +
753
+ 8
758
754
  end
759
755
 
760
756
  context '#in_days' do
761
757
  subject { Moments::Difference.new(from, to).in_days }
762
758
 
763
759
  include_examples 'in a component',
764
- when_seconds: 0,
765
- when_minutes: 0,
766
- when_hours: 0,
767
- when_days: 6,
768
- when_months:
769
- (31 + 28 + 31 + 30) +
770
- 6,
771
- when_years:
772
- 2 * 365 +
773
- (31 + 28 + 31 + 30) +
774
- 6
760
+ when_seconds: 0,
761
+ when_minutes: 0,
762
+ when_hours: 0,
763
+ when_days: 6,
764
+ when_months:
765
+ (31 + 28 + 31 + 30) +
766
+ 6,
767
+ when_years:
768
+ (2 * 365) +
769
+ (31 + 28 + 31 + 30) +
770
+ 6
775
771
  end
776
772
 
777
773
  context '#in_months' do
778
774
  subject { Moments::Difference.new(from, to).in_months }
779
775
 
780
776
  include_examples 'in a component',
781
- when_seconds: 0,
782
- when_minutes: 0,
783
- when_hours: 0,
784
- when_days: 0,
785
- when_months: 4,
786
- when_years: 2 * 12 + 4
777
+ when_seconds: 0,
778
+ when_minutes: 0,
779
+ when_hours: 0,
780
+ when_days: 0,
781
+ when_months: 4,
782
+ when_years: (2 * 12) + 4
787
783
  end
788
784
 
789
785
  context '#in_years' do
790
786
  subject { Moments::Difference.new(from, to).in_years }
791
787
 
792
788
  include_examples 'in a component',
793
- when_seconds: 0,
794
- when_minutes: 0,
795
- when_hours: 0,
796
- when_days: 0,
797
- when_months: 0,
798
- when_years: 2
789
+ when_seconds: 0,
790
+ when_minutes: 0,
791
+ when_hours: 0,
792
+ when_days: 0,
793
+ when_months: 0,
794
+ when_years: 2
799
795
 
800
796
  context 'when `to` day is greater than `from` day' do
801
797
  let(:from) { Time.utc 2013, 1, 1, 0, 0, 0 }
data/spec/spec_helper.rb CHANGED
@@ -1,5 +1,3 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'codeclimate-test-reporter'
4
-
5
3
  require_relative '../lib/moments'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: moments
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tim Rudat
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-08-18 00:00:00.000000000 Z
11
+ date: 2022-05-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -16,76 +16,70 @@ dependencies:
16
16
  requirements:
17
17
  - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: '1'
20
- - - "<"
21
- - !ruby/object:Gem::Version
22
- version: '3'
19
+ version: '0'
23
20
  type: :development
24
21
  prerelease: false
25
22
  version_requirements: !ruby/object:Gem::Requirement
26
23
  requirements:
27
24
  - - ">="
28
25
  - !ruby/object:Gem::Version
29
- version: '1'
30
- - - "<"
31
- - !ruby/object:Gem::Version
32
- version: '3'
26
+ version: '0'
33
27
  - !ruby/object:Gem::Dependency
34
- name: codeclimate-test-reporter
28
+ name: github_changelog_generator
35
29
  requirement: !ruby/object:Gem::Requirement
36
30
  requirements:
37
- - - "~>"
31
+ - - ">="
38
32
  - !ruby/object:Gem::Version
39
- version: '1.0'
33
+ version: '0'
40
34
  type: :development
41
35
  prerelease: false
42
36
  version_requirements: !ruby/object:Gem::Requirement
43
37
  requirements:
44
- - - "~>"
38
+ - - ">="
45
39
  - !ruby/object:Gem::Version
46
- version: '1.0'
40
+ version: '0'
47
41
  - !ruby/object:Gem::Dependency
48
42
  name: rake
49
43
  requirement: !ruby/object:Gem::Requirement
50
44
  requirements:
51
- - - "~>"
45
+ - - ">="
52
46
  - !ruby/object:Gem::Version
53
- version: '13.0'
47
+ version: '0'
54
48
  type: :development
55
49
  prerelease: false
56
50
  version_requirements: !ruby/object:Gem::Requirement
57
51
  requirements:
58
- - - "~>"
52
+ - - ">="
59
53
  - !ruby/object:Gem::Version
60
- version: '13.0'
54
+ version: '0'
61
55
  - !ruby/object:Gem::Dependency
62
56
  name: rspec
63
57
  requirement: !ruby/object:Gem::Requirement
64
58
  requirements:
65
- - - "~>"
59
+ - - ">="
66
60
  - !ruby/object:Gem::Version
67
- version: '3.0'
61
+ version: '0'
68
62
  type: :development
69
63
  prerelease: false
70
64
  version_requirements: !ruby/object:Gem::Requirement
71
65
  requirements:
72
- - - "~>"
66
+ - - ">="
73
67
  - !ruby/object:Gem::Version
74
- version: '3.0'
68
+ version: '0'
75
69
  - !ruby/object:Gem::Dependency
76
70
  name: rubocop
77
71
  requirement: !ruby/object:Gem::Requirement
78
72
  requirements:
79
- - - "~>"
73
+ - - ">="
80
74
  - !ruby/object:Gem::Version
81
- version: 0.86.0
75
+ version: '0'
82
76
  type: :development
83
77
  prerelease: false
84
78
  version_requirements: !ruby/object:Gem::Requirement
85
79
  requirements:
86
- - - "~>"
80
+ - - ">="
87
81
  - !ruby/object:Gem::Version
88
- version: 0.86.0
82
+ version: '0'
89
83
  description: ''
90
84
  email:
91
85
  - timrudat@gmail.com
@@ -113,7 +107,8 @@ files:
113
107
  homepage: https://github.com/excpt/moments
114
108
  licenses:
115
109
  - MIT
116
- metadata: {}
110
+ metadata:
111
+ rubygems_mfa_required: 'true'
117
112
  post_install_message:
118
113
  rdoc_options: []
119
114
  require_paths:
@@ -129,11 +124,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
129
124
  - !ruby/object:Gem::Version
130
125
  version: '0'
131
126
  requirements: []
132
- rubygems_version: 3.1.2
127
+ rubygems_version: 3.3.7
133
128
  signing_key:
134
129
  specification_version: 4
135
130
  summary: Handles time differences.
136
- test_files:
137
- - spec/lib/moments/difference_spec.rb
138
- - spec/lib/moments_spec.rb
139
- - spec/spec_helper.rb
131
+ test_files: []