period_dates 0.0.1 → 0.0.2

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: 9a0ac8e31ab344890740942edaacd0a58a24c04b
4
- data.tar.gz: 427de0486ece7e87be41666c785914e202c4798b
3
+ metadata.gz: 74b25c3bf9ff655f61f865f426c4eaacc2444cc1
4
+ data.tar.gz: 1e2a955ef80a22e5d48c9d2f9f531dfe54258da6
5
5
  SHA512:
6
- metadata.gz: 1cf4b5cfe09975c31f074ae9fc16086717f8b18164b3f3c3a75593ae7c5a51f581fef261bd9423313863c9a6b884d6fdc8f4d2130d80542d40c66a2a5001fc7a
7
- data.tar.gz: 966b275810c41b03c4515d1c77630bf4f55bd639adf3c8ae2ed9ee8af7fc52f291d3e029d02031128fd49ca910fe559e0d32641c99a328aca76cb41080035b90
6
+ metadata.gz: 2fdaedc8b1a5f8f371968c47131f584d1d021adc7e1a11d530f8685cfeba85261a1c34de993a00816b6b6ec2e33136c09a04957ef3ac7acf9cd690a11dbc4f1f
7
+ data.tar.gz: c2b0ad0aaa4daf76195c8d80a9aa17b63dceebcffc0f69e251e68b7903d3cbb7c3d571f3987a67368e7e23559b485c6024be10b9cc95bb97b9bdee44de04564c
data/README.rdoc CHANGED
@@ -19,6 +19,7 @@ Offset is optional and by default is 0
19
19
  - biannualy ( 6 months )
20
20
  - semestral ( 6 months )
21
21
 
22
+ Only this periods can be specifyed, if other period is given a exception will raise.
22
23
 
23
24
  # Use
24
25
 
@@ -28,3 +29,7 @@ dates = date.current_period_dates('biannually')
28
29
  => dates[0] = 2015-01-01 and dates[1] = 2015-06-01
29
30
  ```
30
31
 
32
+
33
+ # To-Do
34
+
35
+ - Standarize interface
@@ -1,4 +1,11 @@
1
+ class PeriodDatesIncorrectPeriod < StandardError
2
+ end
3
+
1
4
  module Calculations
5
+ def available_periods
6
+ ["monthly","quarterly","biannually","semestral"]
7
+ end
8
+
2
9
  def prev_period_dates(period='monthly')
3
10
  bound_dates = []
4
11
 
@@ -17,7 +24,11 @@ module Calculations
17
24
  bound_dates[1] = self.prev_semester.at_end_of_semester
18
25
  end
19
26
 
20
- bound_dates
27
+ if !available_periods.include?(period)
28
+ raise PeriodDatesIncorrectPeriod, "Period must be one of this: #{available_periods.join(', ')}."
29
+ else
30
+ bound_dates
31
+ end
21
32
  end
22
33
 
23
34
  alias :last_period_dates :prev_period_dates
@@ -40,7 +51,11 @@ module Calculations
40
51
  bound_dates[1] = self.next_semester.at_end_of_semester
41
52
  end
42
53
 
43
- bound_dates
54
+ if !available_periods.include?(period)
55
+ raise PeriodDatesIncorrectPeriod, "Period must be one of this: #{available_periods.join(', ')}."
56
+ else
57
+ bound_dates
58
+ end
44
59
  end
45
60
 
46
61
  def current_period_dates(period='monthly')
@@ -61,21 +76,29 @@ module Calculations
61
76
  bound_dates[1] = self.at_end_of_semester
62
77
  end
63
78
 
64
- bound_dates
79
+ if !available_periods.include?(period)
80
+ raise PeriodDatesIncorrectPeriod, "Period must be one of this: #{available_periods.join(', ')}."
81
+ else
82
+ bound_dates
83
+ end
65
84
  end
66
85
 
67
86
  def offset_period_dates(offset=0,period='monthly')
68
87
  bound_dates = self.current_period_dates
69
88
 
70
- offset.abs.times do |time|
71
- if offset > 0
72
- bound_dates = bound_dates[0].next_period_dates(period)
73
- elsif offset < 0
74
- bound_dates = bound_dates[0].prev_period_dates(period)
89
+ if !available_periods.include?(period)
90
+ raise PeriodDatesIncorrectPeriod, "Period must be one of this: #{available_periods.join(', ')}."
91
+ else
92
+ offset.abs.times do |time|
93
+ if offset > 0
94
+ bound_dates = bound_dates[0].next_period_dates(period)
95
+ elsif offset < 0
96
+ bound_dates = bound_dates[0].prev_period_dates(period)
97
+ end
75
98
  end
76
- end
77
99
 
78
- bound_dates
100
+ bound_dates
101
+ end
79
102
  end
80
103
 
81
104
  end
@@ -1,3 +1,3 @@
1
1
  module PeriodDates
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
@@ -37,6 +37,13 @@ class CoreExtTest < ActiveSupport::TestCase
37
37
  assert_equal dates[1], date_to
38
38
  end
39
39
 
40
+ def test_date_time_last_period_dates_4
41
+ date = DateTime.new(2015,2,2)
42
+ date_from = DateTime.new(2014,7,1)
43
+ date_to = DateTime.new(2014,12,1).at_end_of_month
44
+ assert_raises( PeriodDatesIncorrectPeriod) { date.prev_period_dates('biFUUUUUUYU') }
45
+ end
46
+
40
47
 
41
48
  def test_date_time_current_period_dates
42
49
  date = DateTime.new(2015,4,3)
@@ -1406,5 +1406,405 @@ CoreExtTest: test_date_time_offset_period_dates_3
1406
1406
   (0.1ms) begin transaction
1407
1407
  ---------------------------
1408
1408
  PeriodDatesTest: test_truth
1409
+ ---------------------------
1410
+  (0.1ms) rollback transaction
1411
+  (0.1ms) begin transaction
1412
+ ---------------------------
1413
+ PeriodDatesTest: test_truth
1414
+ ---------------------------
1415
+  (0.1ms) rollback transaction
1416
+  (0.1ms) begin transaction
1417
+ ------------------------------------------------
1418
+ CoreExtTest: test_date_time_current_period_dates
1419
+ ------------------------------------------------
1420
+  (0.1ms) rollback transaction
1421
+  (0.1ms) begin transaction
1422
+ ---------------------------------------------
1423
+ CoreExtTest: test_date_time_last_period_dates
1424
+ ---------------------------------------------
1425
+  (0.1ms) rollback transaction
1426
+  (0.1ms) begin transaction
1427
+ -----------------------------------------------
1428
+ CoreExtTest: test_date_time_last_period_dates_2
1429
+ -----------------------------------------------
1430
+  (0.1ms) rollback transaction
1431
+  (0.1ms) begin transaction
1432
+ -----------------------------------------------
1433
+ CoreExtTest: test_date_time_last_period_dates_3
1434
+ -----------------------------------------------
1435
+  (0.0ms) rollback transaction
1436
+  (0.0ms) begin transaction
1437
+ -----------------------------------------------
1438
+ CoreExtTest: test_date_time_last_period_dates_4
1439
+ -----------------------------------------------
1440
+  (0.1ms) rollback transaction
1441
+  (0.0ms) begin transaction
1442
+ ---------------------------------------------
1443
+ CoreExtTest: test_date_time_next_period_dates
1444
+ ---------------------------------------------
1445
+  (0.0ms) rollback transaction
1446
+  (0.0ms) begin transaction
1447
+ -----------------------------------------------
1448
+ CoreExtTest: test_date_time_offset_period_dates
1449
+ -----------------------------------------------
1450
+  (0.0ms) rollback transaction
1451
+  (0.1ms) begin transaction
1452
+ -------------------------------------------------
1453
+ CoreExtTest: test_date_time_offset_period_dates_2
1454
+ -------------------------------------------------
1455
+  (0.1ms) rollback transaction
1456
+  (0.1ms) begin transaction
1457
+ -------------------------------------------------
1458
+ CoreExtTest: test_date_time_offset_period_dates_3
1459
+ -------------------------------------------------
1460
+  (0.1ms) rollback transaction
1461
+  (0.1ms) begin transaction
1462
+ ---------------------------
1463
+ PeriodDatesTest: test_truth
1464
+ ---------------------------
1465
+  (0.2ms) rollback transaction
1466
+  (0.1ms) begin transaction
1467
+ ------------------------------------------------
1468
+ CoreExtTest: test_date_time_current_period_dates
1469
+ ------------------------------------------------
1470
+  (0.1ms) rollback transaction
1471
+  (0.0ms) begin transaction
1472
+ ---------------------------------------------
1473
+ CoreExtTest: test_date_time_last_period_dates
1474
+ ---------------------------------------------
1475
+  (0.0ms) rollback transaction
1476
+  (0.0ms) begin transaction
1477
+ -----------------------------------------------
1478
+ CoreExtTest: test_date_time_last_period_dates_2
1479
+ -----------------------------------------------
1480
+  (0.0ms) rollback transaction
1481
+  (0.0ms) begin transaction
1482
+ -----------------------------------------------
1483
+ CoreExtTest: test_date_time_last_period_dates_3
1484
+ -----------------------------------------------
1485
+  (0.0ms) rollback transaction
1486
+  (0.1ms) begin transaction
1487
+ -----------------------------------------------
1488
+ CoreExtTest: test_date_time_last_period_dates_4
1489
+ -----------------------------------------------
1490
+  (0.0ms) rollback transaction
1491
+  (0.1ms) begin transaction
1492
+ ---------------------------------------------
1493
+ CoreExtTest: test_date_time_next_period_dates
1494
+ ---------------------------------------------
1495
+  (0.1ms) rollback transaction
1496
+  (0.0ms) begin transaction
1497
+ -----------------------------------------------
1498
+ CoreExtTest: test_date_time_offset_period_dates
1499
+ -----------------------------------------------
1500
+  (0.1ms) rollback transaction
1501
+  (0.1ms) begin transaction
1502
+ -------------------------------------------------
1503
+ CoreExtTest: test_date_time_offset_period_dates_2
1504
+ -------------------------------------------------
1505
+  (0.1ms) rollback transaction
1506
+  (0.1ms) begin transaction
1507
+ -------------------------------------------------
1508
+ CoreExtTest: test_date_time_offset_period_dates_3
1509
+ -------------------------------------------------
1510
+  (0.0ms) rollback transaction
1511
+  (0.1ms) begin transaction
1512
+ ---------------------------
1513
+ PeriodDatesTest: test_truth
1514
+ ---------------------------
1515
+  (0.1ms) rollback transaction
1516
+  (0.1ms) begin transaction
1517
+ ------------------------------------------------
1518
+ CoreExtTest: test_date_time_current_period_dates
1519
+ ------------------------------------------------
1520
+  (0.1ms) rollback transaction
1521
+  (0.1ms) begin transaction
1522
+ ---------------------------------------------
1523
+ CoreExtTest: test_date_time_last_period_dates
1524
+ ---------------------------------------------
1525
+  (0.1ms) rollback transaction
1526
+  (0.1ms) begin transaction
1527
+ -----------------------------------------------
1528
+ CoreExtTest: test_date_time_last_period_dates_2
1529
+ -----------------------------------------------
1530
+  (0.1ms) rollback transaction
1531
+  (0.1ms) begin transaction
1532
+ -----------------------------------------------
1533
+ CoreExtTest: test_date_time_last_period_dates_3
1534
+ -----------------------------------------------
1535
+  (0.1ms) rollback transaction
1536
+  (0.0ms) begin transaction
1537
+ -----------------------------------------------
1538
+ CoreExtTest: test_date_time_last_period_dates_4
1539
+ -----------------------------------------------
1540
+  (0.0ms) rollback transaction
1541
+  (0.0ms) begin transaction
1542
+ ---------------------------------------------
1543
+ CoreExtTest: test_date_time_next_period_dates
1544
+ ---------------------------------------------
1545
+  (0.0ms) rollback transaction
1546
+  (0.1ms) begin transaction
1547
+ -----------------------------------------------
1548
+ CoreExtTest: test_date_time_offset_period_dates
1549
+ -----------------------------------------------
1550
+  (0.1ms) rollback transaction
1551
+  (0.1ms) begin transaction
1552
+ -------------------------------------------------
1553
+ CoreExtTest: test_date_time_offset_period_dates_2
1554
+ -------------------------------------------------
1555
+  (0.1ms) rollback transaction
1556
+  (0.1ms) begin transaction
1557
+ -------------------------------------------------
1558
+ CoreExtTest: test_date_time_offset_period_dates_3
1559
+ -------------------------------------------------
1560
+  (0.1ms) rollback transaction
1561
+  (0.1ms) begin transaction
1562
+ ------------------------------------------------
1563
+ CoreExtTest: test_date_time_current_period_dates
1564
+ ------------------------------------------------
1565
+  (0.1ms) rollback transaction
1566
+  (0.1ms) begin transaction
1567
+ ---------------------------------------------
1568
+ CoreExtTest: test_date_time_last_period_dates
1569
+ ---------------------------------------------
1570
+  (0.1ms) rollback transaction
1571
+  (0.1ms) begin transaction
1572
+ -----------------------------------------------
1573
+ CoreExtTest: test_date_time_last_period_dates_2
1574
+ -----------------------------------------------
1575
+  (0.1ms) rollback transaction
1576
+  (0.1ms) begin transaction
1577
+ -----------------------------------------------
1578
+ CoreExtTest: test_date_time_last_period_dates_3
1579
+ -----------------------------------------------
1580
+  (0.1ms) rollback transaction
1581
+  (0.1ms) begin transaction
1582
+ -----------------------------------------------
1583
+ CoreExtTest: test_date_time_last_period_dates_4
1584
+ -----------------------------------------------
1585
+  (0.1ms) rollback transaction
1586
+  (0.1ms) begin transaction
1587
+ ---------------------------------------------
1588
+ CoreExtTest: test_date_time_next_period_dates
1589
+ ---------------------------------------------
1590
+  (0.1ms) rollback transaction
1591
+  (0.1ms) begin transaction
1592
+ -----------------------------------------------
1593
+ CoreExtTest: test_date_time_offset_period_dates
1594
+ -----------------------------------------------
1595
+  (0.1ms) rollback transaction
1596
+  (0.1ms) begin transaction
1597
+ -------------------------------------------------
1598
+ CoreExtTest: test_date_time_offset_period_dates_2
1599
+ -------------------------------------------------
1600
+  (0.1ms) rollback transaction
1601
+  (0.1ms) begin transaction
1602
+ -------------------------------------------------
1603
+ CoreExtTest: test_date_time_offset_period_dates_3
1604
+ -------------------------------------------------
1605
+  (0.1ms) rollback transaction
1606
+  (0.1ms) begin transaction
1607
+ ---------------------------
1608
+ PeriodDatesTest: test_truth
1609
+ ---------------------------
1610
+  (0.1ms) rollback transaction
1611
+  (0.1ms) begin transaction
1612
+ ---------------------------
1613
+ PeriodDatesTest: test_truth
1614
+ ---------------------------
1615
+  (0.1ms) rollback transaction
1616
+  (0.1ms) begin transaction
1617
+ ------------------------------------------------
1618
+ CoreExtTest: test_date_time_current_period_dates
1619
+ ------------------------------------------------
1620
+  (0.1ms) rollback transaction
1621
+  (0.1ms) begin transaction
1622
+ ---------------------------------------------
1623
+ CoreExtTest: test_date_time_last_period_dates
1624
+ ---------------------------------------------
1625
+  (0.0ms) rollback transaction
1626
+  (0.1ms) begin transaction
1627
+ -----------------------------------------------
1628
+ CoreExtTest: test_date_time_last_period_dates_2
1629
+ -----------------------------------------------
1630
+  (0.1ms) rollback transaction
1631
+  (0.1ms) begin transaction
1632
+ -----------------------------------------------
1633
+ CoreExtTest: test_date_time_last_period_dates_3
1634
+ -----------------------------------------------
1635
+  (0.1ms) rollback transaction
1636
+  (0.1ms) begin transaction
1637
+ -----------------------------------------------
1638
+ CoreExtTest: test_date_time_last_period_dates_4
1639
+ -----------------------------------------------
1640
+  (0.1ms) rollback transaction
1641
+  (0.1ms) begin transaction
1642
+ ---------------------------------------------
1643
+ CoreExtTest: test_date_time_next_period_dates
1644
+ ---------------------------------------------
1645
+  (0.1ms) rollback transaction
1646
+  (0.1ms) begin transaction
1647
+ -----------------------------------------------
1648
+ CoreExtTest: test_date_time_offset_period_dates
1649
+ -----------------------------------------------
1650
+  (0.1ms) rollback transaction
1651
+  (0.1ms) begin transaction
1652
+ -------------------------------------------------
1653
+ CoreExtTest: test_date_time_offset_period_dates_2
1654
+ -------------------------------------------------
1655
+  (0.1ms) rollback transaction
1656
+  (0.1ms) begin transaction
1657
+ -------------------------------------------------
1658
+ CoreExtTest: test_date_time_offset_period_dates_3
1659
+ -------------------------------------------------
1660
+  (0.0ms) rollback transaction
1661
+  (0.1ms) begin transaction
1662
+ ------------------------------------------------
1663
+ CoreExtTest: test_date_time_current_period_dates
1664
+ ------------------------------------------------
1665
+  (0.1ms) rollback transaction
1666
+  (0.1ms) begin transaction
1667
+ ---------------------------------------------
1668
+ CoreExtTest: test_date_time_last_period_dates
1669
+ ---------------------------------------------
1670
+  (0.0ms) rollback transaction
1671
+  (0.0ms) begin transaction
1672
+ -----------------------------------------------
1673
+ CoreExtTest: test_date_time_last_period_dates_2
1674
+ -----------------------------------------------
1675
+  (0.1ms) rollback transaction
1676
+  (0.1ms) begin transaction
1677
+ -----------------------------------------------
1678
+ CoreExtTest: test_date_time_last_period_dates_3
1679
+ -----------------------------------------------
1680
+  (0.1ms) rollback transaction
1681
+  (0.1ms) begin transaction
1682
+ -----------------------------------------------
1683
+ CoreExtTest: test_date_time_last_period_dates_4
1684
+ -----------------------------------------------
1685
+  (0.1ms) rollback transaction
1686
+  (0.1ms) begin transaction
1687
+ ---------------------------------------------
1688
+ CoreExtTest: test_date_time_next_period_dates
1689
+ ---------------------------------------------
1690
+  (0.1ms) rollback transaction
1691
+  (0.1ms) begin transaction
1692
+ -----------------------------------------------
1693
+ CoreExtTest: test_date_time_offset_period_dates
1694
+ -----------------------------------------------
1695
+  (0.1ms) rollback transaction
1696
+  (0.1ms) begin transaction
1697
+ -------------------------------------------------
1698
+ CoreExtTest: test_date_time_offset_period_dates_2
1699
+ -------------------------------------------------
1700
+  (0.1ms) rollback transaction
1701
+  (0.1ms) begin transaction
1702
+ -------------------------------------------------
1703
+ CoreExtTest: test_date_time_offset_period_dates_3
1704
+ -------------------------------------------------
1705
+  (0.1ms) rollback transaction
1706
+  (0.1ms) begin transaction
1707
+ ---------------------------
1708
+ PeriodDatesTest: test_truth
1709
+ ---------------------------
1710
+  (0.0ms) rollback transaction
1711
+  (0.7ms) begin transaction
1712
+ ------------------------------------------------
1713
+ CoreExtTest: test_date_time_current_period_dates
1714
+ ------------------------------------------------
1715
+  (0.1ms) rollback transaction
1716
+  (0.1ms) begin transaction
1717
+ ---------------------------------------------
1718
+ CoreExtTest: test_date_time_last_period_dates
1719
+ ---------------------------------------------
1720
+  (0.1ms) rollback transaction
1721
+  (0.0ms) begin transaction
1722
+ -----------------------------------------------
1723
+ CoreExtTest: test_date_time_last_period_dates_2
1724
+ -----------------------------------------------
1725
+  (0.1ms) rollback transaction
1726
+  (0.1ms) begin transaction
1727
+ -----------------------------------------------
1728
+ CoreExtTest: test_date_time_last_period_dates_3
1729
+ -----------------------------------------------
1730
+  (0.1ms) rollback transaction
1731
+  (0.1ms) begin transaction
1732
+ -----------------------------------------------
1733
+ CoreExtTest: test_date_time_last_period_dates_4
1734
+ -----------------------------------------------
1735
+  (0.1ms) rollback transaction
1736
+  (0.1ms) begin transaction
1737
+ ---------------------------------------------
1738
+ CoreExtTest: test_date_time_next_period_dates
1739
+ ---------------------------------------------
1740
+  (0.1ms) rollback transaction
1741
+  (0.1ms) begin transaction
1742
+ -----------------------------------------------
1743
+ CoreExtTest: test_date_time_offset_period_dates
1744
+ -----------------------------------------------
1745
+  (0.1ms) rollback transaction
1746
+  (0.1ms) begin transaction
1747
+ -------------------------------------------------
1748
+ CoreExtTest: test_date_time_offset_period_dates_2
1749
+ -------------------------------------------------
1750
+  (0.1ms) rollback transaction
1751
+  (0.1ms) begin transaction
1752
+ -------------------------------------------------
1753
+ CoreExtTest: test_date_time_offset_period_dates_3
1754
+ -------------------------------------------------
1755
+  (0.1ms) rollback transaction
1756
+  (0.1ms) begin transaction
1757
+ ---------------------------
1758
+ PeriodDatesTest: test_truth
1759
+ ---------------------------
1760
+  (0.0ms) rollback transaction
1761
+  (0.1ms) begin transaction
1762
+ ------------------------------------------------
1763
+ CoreExtTest: test_date_time_current_period_dates
1764
+ ------------------------------------------------
1765
+  (0.1ms) rollback transaction
1766
+  (0.1ms) begin transaction
1767
+ ---------------------------------------------
1768
+ CoreExtTest: test_date_time_last_period_dates
1769
+ ---------------------------------------------
1770
+  (0.0ms) rollback transaction
1771
+  (0.1ms) begin transaction
1772
+ -----------------------------------------------
1773
+ CoreExtTest: test_date_time_last_period_dates_2
1774
+ -----------------------------------------------
1775
+  (0.1ms) rollback transaction
1776
+  (0.1ms) begin transaction
1777
+ -----------------------------------------------
1778
+ CoreExtTest: test_date_time_last_period_dates_3
1779
+ -----------------------------------------------
1780
+  (0.0ms) rollback transaction
1781
+  (0.1ms) begin transaction
1782
+ -----------------------------------------------
1783
+ CoreExtTest: test_date_time_last_period_dates_4
1784
+ -----------------------------------------------
1785
+  (0.1ms) rollback transaction
1786
+  (0.0ms) begin transaction
1787
+ ---------------------------------------------
1788
+ CoreExtTest: test_date_time_next_period_dates
1789
+ ---------------------------------------------
1790
+  (0.0ms) rollback transaction
1791
+  (0.0ms) begin transaction
1792
+ -----------------------------------------------
1793
+ CoreExtTest: test_date_time_offset_period_dates
1794
+ -----------------------------------------------
1795
+  (0.0ms) rollback transaction
1796
+  (0.1ms) begin transaction
1797
+ -------------------------------------------------
1798
+ CoreExtTest: test_date_time_offset_period_dates_2
1799
+ -------------------------------------------------
1800
+  (0.1ms) rollback transaction
1801
+  (0.1ms) begin transaction
1802
+ -------------------------------------------------
1803
+ CoreExtTest: test_date_time_offset_period_dates_3
1804
+ -------------------------------------------------
1805
+  (0.1ms) rollback transaction
1806
+  (0.1ms) begin transaction
1807
+ ---------------------------
1808
+ PeriodDatesTest: test_truth
1409
1809
  ---------------------------
1410
1810
   (0.1ms) rollback transaction
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: period_dates
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Javi Fernández