|
| 1 | +require "spec" |
| 2 | +require "../src/*" |
| 3 | + |
| 4 | +describe "SwiftScheduling" do |
| 5 | + it "NOW translates to two hours later" do |
| 6 | + start = Time.parse_utc("2012-02-13T09:00:00", "%Y-%m-%dT%H:%M:%S") |
| 7 | + expected = Time.parse_utc("2012-02-13T11:00:00", "%Y-%m-%dT%H:%M:%S") |
| 8 | + SwiftScheduling.delivery_date(start, "NOW").should eq(expected) |
| 9 | + end |
| 10 | + |
| 11 | + pending "ASAP before one in the afternoon translates to today at five in the afternoon" do |
| 12 | + start = Time.parse_utc("1999-06-03T09:45:00", "%Y-%m-%dT%H:%M:%S") |
| 13 | + expected = Time.parse_utc("1999-06-03T17:00:00", "%Y-%m-%dT%H:%M:%S") |
| 14 | + SwiftScheduling.delivery_date(start, "ASAP").should eq(expected) |
| 15 | + end |
| 16 | + |
| 17 | + pending "ASAP at one in the afternoon translates to tomorrow at one in the afternoon" do |
| 18 | + start = Time.parse_utc("2008-12-21T13:00:00", "%Y-%m-%dT%H:%M:%S") |
| 19 | + expected = Time.parse_utc("2008-12-22T13:00:00", "%Y-%m-%dT%H:%M:%S") |
| 20 | + SwiftScheduling.delivery_date(start, "ASAP").should eq(expected) |
| 21 | + end |
| 22 | + |
| 23 | + pending "ASAP after one in the afternoon translates to tomorrow at one in the afternoon" do |
| 24 | + start = Time.parse_utc("2008-12-21T14:50:00", "%Y-%m-%dT%H:%M:%S") |
| 25 | + expected = Time.parse_utc("2008-12-22T13:00:00", "%Y-%m-%dT%H:%M:%S") |
| 26 | + SwiftScheduling.delivery_date(start, "ASAP").should eq(expected) |
| 27 | + end |
| 28 | + |
| 29 | + pending "EOW on Monday translates to Friday at five in the afternoon" do |
| 30 | + start = Time.parse_utc("2025-02-03T16:00:00", "%Y-%m-%dT%H:%M:%S") |
| 31 | + expected = Time.parse_utc("2025-02-07T17:00:00", "%Y-%m-%dT%H:%M:%S") |
| 32 | + SwiftScheduling.delivery_date(start, "EOW").should eq(expected) |
| 33 | + end |
| 34 | + |
| 35 | + pending "EOW on Tuesday translates to Friday at five in the afternoon" do |
| 36 | + start = Time.parse_utc("1997-04-29T10:50:00", "%Y-%m-%dT%H:%M:%S") |
| 37 | + expected = Time.parse_utc("1997-05-02T17:00:00", "%Y-%m-%dT%H:%M:%S") |
| 38 | + SwiftScheduling.delivery_date(start, "EOW").should eq(expected) |
| 39 | + end |
| 40 | + |
| 41 | + pending "EOW on Wednesday translates to Friday at five in the afternoon" do |
| 42 | + start = Time.parse_utc("2005-09-14T11:00:00", "%Y-%m-%dT%H:%M:%S") |
| 43 | + expected = Time.parse_utc("2005-09-16T17:00:00", "%Y-%m-%dT%H:%M:%S") |
| 44 | + SwiftScheduling.delivery_date(start, "EOW").should eq(expected) |
| 45 | + end |
| 46 | + |
| 47 | + pending "EOW on Thursday translates to Sunday at eight in the evening" do |
| 48 | + start = Time.parse_utc("2011-05-19T08:30:00", "%Y-%m-%dT%H:%M:%S") |
| 49 | + expected = Time.parse_utc("2011-05-22T20:00:00", "%Y-%m-%dT%H:%M:%S") |
| 50 | + SwiftScheduling.delivery_date(start, "EOW").should eq(expected) |
| 51 | + end |
| 52 | + |
| 53 | + pending "EOW on Friday translates to Sunday at eight in the evening" do |
| 54 | + start = Time.parse_utc("2022-08-05T14:00:00", "%Y-%m-%dT%H:%M:%S") |
| 55 | + expected = Time.parse_utc("2022-08-07T20:00:00", "%Y-%m-%dT%H:%M:%S") |
| 56 | + SwiftScheduling.delivery_date(start, "EOW").should eq(expected) |
| 57 | + end |
| 58 | + |
| 59 | + pending "EOW translates to leap day" do |
| 60 | + start = Time.parse_utc("2008-02-25T10:30:00", "%Y-%m-%dT%H:%M:%S") |
| 61 | + expected = Time.parse_utc("2008-02-29T17:00:00", "%Y-%m-%dT%H:%M:%S") |
| 62 | + SwiftScheduling.delivery_date(start, "EOW").should eq(expected) |
| 63 | + end |
| 64 | + |
| 65 | + pending "2M before the second month of this year translates to the first workday of the second month of this year" do |
| 66 | + start = Time.parse_utc("2007-01-02T14:15:00", "%Y-%m-%dT%H:%M:%S") |
| 67 | + expected = Time.parse_utc("2007-02-01T08:00:00", "%Y-%m-%dT%H:%M:%S") |
| 68 | + SwiftScheduling.delivery_date(start, "2M").should eq(expected) |
| 69 | + end |
| 70 | + |
| 71 | + pending "11M in the eleventh month translates to the first workday of the eleventh month of next year" do |
| 72 | + start = Time.parse_utc("2013-11-21T15:30:00", "%Y-%m-%dT%H:%M:%S") |
| 73 | + expected = Time.parse_utc("2014-11-03T08:00:00", "%Y-%m-%dT%H:%M:%S") |
| 74 | + SwiftScheduling.delivery_date(start, "11M").should eq(expected) |
| 75 | + end |
| 76 | + |
| 77 | + pending "4M in the ninth month translates to the first workday of the fourth month of next year" do |
| 78 | + start = Time.parse_utc("2019-11-18T15:15:00", "%Y-%m-%dT%H:%M:%S") |
| 79 | + expected = Time.parse_utc("2020-04-01T08:00:00", "%Y-%m-%dT%H:%M:%S") |
| 80 | + SwiftScheduling.delivery_date(start, "4M").should eq(expected) |
| 81 | + end |
| 82 | + |
| 83 | + pending "Q1 in the first quarter translates to the last workday of the first quarter of this year" do |
| 84 | + start = Time.parse_utc("2003-01-01T10:45:00", "%Y-%m-%dT%H:%M:%S") |
| 85 | + expected = Time.parse_utc("2003-03-31T08:00:00", "%Y-%m-%dT%H:%M:%S") |
| 86 | + SwiftScheduling.delivery_date(start, "Q1").should eq(expected) |
| 87 | + end |
| 88 | + |
| 89 | + pending "Q4 in the second quarter translates to the last workday of the fourth quarter of this year" do |
| 90 | + start = Time.parse_utc("2001-04-09T09:00:00", "%Y-%m-%dT%H:%M:%S") |
| 91 | + expected = Time.parse_utc("2001-12-31T08:00:00", "%Y-%m-%dT%H:%M:%S") |
| 92 | + SwiftScheduling.delivery_date(start, "Q4").should eq(expected) |
| 93 | + end |
| 94 | + |
| 95 | + pending "Q3 in the fourth quarter translates to the last workday of the third quarter of next year" do |
| 96 | + start = Time.parse_utc("2022-10-06T11:00:00", "%Y-%m-%dT%H:%M:%S") |
| 97 | + expected = Time.parse_utc("2023-09-29T08:00:00", "%Y-%m-%dT%H:%M:%S") |
| 98 | + SwiftScheduling.delivery_date(start, "Q3").should eq(expected) |
| 99 | + end |
| 100 | +end |
0 commit comments