hoodoo 2.9.0 → 2.10.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: 18fc233fa796b76a8275e120ca461c417262e23ead78bc600171506feb851b13
4
- data.tar.gz: 3c8aaa457667904c1fb073e8423241f6455f3e78b1339ab36b99f7601481fb50
3
+ metadata.gz: 558f4ad8d5dd9efe88b282630fcb24a5fc244382e7dc3ff769b21998c38c058e
4
+ data.tar.gz: 0b2b67b5d32e25c160f1a4ec755898b294fb742044615557c05a9d18769e8699
5
5
  SHA512:
6
- metadata.gz: ecb400413ec681232584714aa0b58efc50ec8c15eacc2814372c38fee617c99d83c7899cd807dfdda9469f91790cda63f39958f11acb37a8015564b019a9bebf
7
- data.tar.gz: 8280be1231ab84f35fccf6872eea53923040229e6355afe891bd356a6b2fc7d1e608a5725ab26d3ec13e459a0b8806a9896190c921d5f0d10f9d6435a3bfe8b0
6
+ metadata.gz: 9dc89cb9a030e29d0c678a4cef606fff9ad2bee6761148573c4c5ea8e8fa173ffc99dcf0f2e50f7ca6ac7f90baac80a6854314159cc53adc2624e2326478622b
7
+ data.tar.gz: de09f589b82a11eec89cd494860b9b2c3ee00262fd16cd18307296d88caf3ab3b5eef2ce28387adc525dc924a9d34d1074dd13233edb6346e9b61470eb8d9804
@@ -354,11 +354,14 @@ module Hoodoo
354
354
  # +input+:: A value that's passed to ::rationalise_datetime with the
355
355
  # result checked against `now` allowing for clock drift.
356
356
  #
357
- # If the given input is not parseable as a date-time like object, then
358
- # the method it will throw a RuntimeError exception via
357
+ # +backdated_to+:: Optional. The "now" of the context, defaulting to
358
+ # +DateTime.now+.
359
+ #
360
+ # If the given input or `backdated_to` is not parseable as a date-time like
361
+ # object, then the method it will throw a RuntimeError exception via
359
362
  # ::rationalise_datetime.
360
363
  #
361
- def self.is_in_future?( input )
364
+ def self.is_in_future?( input, backdated_to=DateTime.now )
362
365
 
363
366
  # See also ::clear_clock_drift_configuration_cache!.
364
367
  #
@@ -370,10 +373,12 @@ module Hoodoo
370
373
 
371
374
  value = self.rationalise_datetime( input )
372
375
 
376
+ backdated_now = self.rationalise_datetime( backdated_to )
377
+
373
378
  # Unlike Time, integer addition to DateTime adds days. There are 86400
374
379
  # seconds per day, so below we add @@clock_drift_tolerance seconds.
375
380
  #
376
- value > DateTime.now + Rational(@@clock_drift_tolerance, 86400)
381
+ value > backdated_now + Rational(@@clock_drift_tolerance, 86400)
377
382
 
378
383
  end
379
384
 
@@ -12,11 +12,11 @@ module Hoodoo
12
12
  # The Hoodoo gem version. If this changes, be sure to re-run
13
13
  # <tt>bundle install</tt> or <tt>bundle update</tt>.
14
14
  #
15
- VERSION = '2.9.0'
15
+ VERSION = '2.10.0'
16
16
 
17
17
  # The Hoodoo gem date. If this changes, be sure to re-run
18
18
  # <tt>bundle install</tt> or <tt>bundle update</tt>.
19
19
  #
20
- DATE = '2018-08-21'
20
+ DATE = '2018-12-04'
21
21
 
22
22
  end
@@ -498,22 +498,74 @@ describe Hoodoo::Utilities do
498
498
  ENV[ 'HOODOO_CLOCK_DRIFT_TOLERANCE' ] = @old_drift
499
499
  end
500
500
 
501
- it 'says "no" for "now"' do
502
- expect( Hoodoo::Utilities.is_in_future?( Time.now ) ).to eq( false )
503
- end
501
+ context 'when comparing to now' do
502
+ it 'says "no" for "now"' do
503
+ expect( Hoodoo::Utilities.is_in_future?( Time.now ) ).to eq( false )
504
+ end
505
+
506
+ it 'says "no" inside default drift allowance' do
507
+ expect( Hoodoo::Utilities.is_in_future?( Time.now + ( @default / 2 ) ) ).to eq( false )
508
+ end
504
509
 
505
- it 'says "no" inside default drift allowance' do
506
- expect( Hoodoo::Utilities.is_in_future?( Time.now + ( @default / 2 ) ) ).to eq( false )
510
+ # Hoodoo Guides: "...less than or equal to... ...is permitted...".
511
+ #
512
+ it 'says "no" at default drift allowance' do
513
+ expect( Hoodoo::Utilities.is_in_future?( Time.now + @default ) ).to eq( false )
514
+ end
515
+
516
+ it 'says "yes" outside default drift allowance' do
517
+ expect( Hoodoo::Utilities.is_in_future?( Time.now + @default + 1 ) ).to eq( true )
518
+ end
507
519
  end
508
520
 
509
- # Hoodoo Guides: "...less than or equal to... ...is permitted...".
510
- #
511
- it 'says "no" at default drift allowance' do
512
- expect( Hoodoo::Utilities.is_in_future?( Time.now + @default ) ).to eq( false )
521
+ context 'when comparing to a date in the past' do
522
+
523
+ before(:each) do
524
+ @past_date = Time.now - ( @default * 2 )
525
+ end
526
+
527
+ it 'says "yes" for "now"' do
528
+ expect( Hoodoo::Utilities.is_in_future?( Time.now, @past_date ) ).to eq( true )
529
+ end
530
+
531
+ it 'says "no" inside default drift allowance' do
532
+ expect( Hoodoo::Utilities.is_in_future?( @past_date + ( @default / 2 ), @past_date ) ).to eq( false )
533
+ end
534
+
535
+ it 'says "no" at default drift allowance' do
536
+ expect( Hoodoo::Utilities.is_in_future?( @past_date + @default, @past_date ) ).to eq( false )
537
+ end
538
+
539
+ it 'says "yes" outside default drift allowance' do
540
+ expect( Hoodoo::Utilities.is_in_future?( @past_date + @default + 1, @past_date ) ).to eq( true )
541
+ end
513
542
  end
514
543
 
515
- it 'says "yes" outside default drift allowance' do
516
- expect( Hoodoo::Utilities.is_in_future?( Time.now + @default + 1 ) ).to eq( true )
544
+ context 'when comparing to a date in the future' do
545
+
546
+ before(:each) do
547
+ @future_date = Time.now + ( @default * 2 )
548
+ end
549
+
550
+ it 'says "no" for "now"' do
551
+ expect( Hoodoo::Utilities.is_in_future?( Time.now, @future_date ) ).to eq( false )
552
+ end
553
+
554
+ it 'says "no" for a date before the future date, but after "now"' do
555
+ expect( Hoodoo::Utilities.is_in_future?( Time.now + ( @default / 2 ), @future_date ) ).to eq( false )
556
+ end
557
+
558
+ it 'says "no" inside default drift allowance' do
559
+ expect( Hoodoo::Utilities.is_in_future?( @future_date + ( @default / 2 ), @future_date ) ).to eq( false )
560
+ end
561
+
562
+ it 'says "no" at default drift allowance' do
563
+ expect( Hoodoo::Utilities.is_in_future?( @future_date + @default, @future_date ) ).to eq( false )
564
+ end
565
+
566
+ it 'says "yes" outside default drift allowance' do
567
+ expect( Hoodoo::Utilities.is_in_future?( @future_date + @default + 1, @future_date ) ).to eq( true )
568
+ end
517
569
  end
518
570
 
519
571
  it 'drift allowance can be reconfigured' do
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hoodoo
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.9.0
4
+ version: 2.10.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Loyalty New Zealand
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-08-21 00:00:00.000000000 Z
11
+ date: 2018-12-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rack
@@ -598,7 +598,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
598
598
  version: '0'
599
599
  requirements: []
600
600
  rubyforge_project:
601
- rubygems_version: 2.7.7
601
+ rubygems_version: 2.7.8
602
602
  signing_key:
603
603
  specification_version: 4
604
604
  summary: Opinionated APIs