Commit b32d190

mokhan <mokhan@ce5e1baf-6525-42e4-a1b2-857ea38da20a>
2009-04-24 20:31:08
got rid of the date interface.
git-svn-id: https://svn.xp-dev.com/svn/mokhan-mo.money@193 ce5e1baf-6525-42e4-a1b2-857ea38da20a
1 parent 1049889
Changed files (8)
trunk
product
Gorilla.Commons.Utility
MoMoney.Domain
MoMoney.Service
trunk/product/Gorilla.Commons.Utility/Date.cs
@@ -4,14 +4,8 @@ using Gorilla.Commons.Utility.Extensions;
 
 namespace Gorilla.Commons.Utility
 {
-    public interface IDate : IComparable<IDate>, IComparable, IEquatable<IDate>
-    {
-        bool is_in(IYear year);
-        DateTime to_date_time();
-    }
-
     [Serializable]
-    public class Date : IDate, IEquatable<Date>
+    public class Date :  IComparable<Date>, IComparable, IEquatable<Date>
     {
         readonly long ticks;
 
@@ -40,7 +34,7 @@ namespace Gorilla.Commons.Utility
             return date.to_date_time();
         }
 
-        public int CompareTo(IDate other)
+        public int CompareTo(Date other)
         {
             var the_other_date = other.downcast_to<Date>();
             if (ticks.Equals(the_other_date.ticks))
@@ -50,16 +44,11 @@ namespace Gorilla.Commons.Utility
             return ticks > the_other_date.ticks ? 1 : -1;
         }
 
-        public bool Equals(Date obj)
-        {
-            if (ReferenceEquals(null, obj)) return false;
-            if (ReferenceEquals(this, obj)) return true;
-            return obj.ticks == ticks;
-        }
-
-        public bool Equals(IDate other)
+        public bool Equals(Date other)
         {
-            return other.CompareTo(this) == 0;
+            if (ReferenceEquals(null, other)) return false;
+            if (ReferenceEquals(this, other)) return true;
+            return other.ticks == ticks;
         }
 
         public override bool Equals(object obj)
@@ -75,6 +64,16 @@ namespace Gorilla.Commons.Utility
             return ticks.GetHashCode();
         }
 
+        public static bool operator ==(Date left, Date right)
+        {
+            return Equals(left, right);
+        }
+
+        public static bool operator !=(Date left, Date right)
+        {
+            return !Equals(left, right);
+        }
+
         public override string ToString()
         {
             return new DateTime(ticks, DateTimeKind.Local).ToString("MMM dd yyyy", CultureInfo.InvariantCulture);
@@ -82,8 +81,8 @@ namespace Gorilla.Commons.Utility
 
         int IComparable.CompareTo(object obj)
         {
-            if (obj.is_an_implementation_of<IDate>())
-                return CompareTo(obj.downcast_to<IDate>());
+            if (obj.is_an_implementation_of<Date>())
+                return CompareTo(obj.downcast_to<Date>());
             throw new InvalidOperationException();
         }
     }
trunk/product/Gorilla.Commons.Utility/DateSpecs.cs
@@ -8,11 +8,11 @@ namespace Gorilla.Commons.Utility
     }
 
     [Concern(typeof (Date))]
-    public class when_two_dates_that_represent_the_same_day_are_asked_if_they_are_equal : concerns_for<IDate>
+    public class when_two_dates_that_represent_the_same_day_are_asked_if_they_are_equal : concerns_for<Date>
     {
         it should_return_true = () => result.should_be_equal_to(true);
 
-        public override IDate create_sut()
+        public override Date create_sut()
         {
             return new Date(2008, 09, 25);
         }
@@ -23,11 +23,11 @@ namespace Gorilla.Commons.Utility
     }
 
     [Concern(typeof (Date))]
-    public class when_an_older_date_is_compared_to_a_younger_date : concerns_for<IDate>
+    public class when_an_older_date_is_compared_to_a_younger_date : concerns_for<Date>
     {
         it should_return_a_positive_number = () => result.should_be_greater_than(0);
 
-        public override IDate create_sut()
+        public override Date create_sut()
         {
             return new Date(2008, 09, 25);
         }
trunk/product/MoMoney.Domain/Accounting/Billing/Bill.cs
@@ -12,7 +12,7 @@ namespace MoMoney.Domain.accounting.billing
         void pay(Money amount_to_pay);
         ICompany company_to_pay { get; }
         Money the_amount_owed { get; }
-        IDate due_date { get; }
+        Date due_date { get; }
     }
 
     [Serializable]
@@ -22,13 +22,13 @@ namespace MoMoney.Domain.accounting.billing
         {
             this.company_to_pay = company_to_pay;
             this.the_amount_owed = the_amount_owed;
-            this.due_date = due_date.as_a_date();
+            this.due_date = due_date;
             payments = new List<IPayment>();
         }
 
         public ICompany company_to_pay { get; private set; }
         public Money the_amount_owed { get; private set; }
-        public IDate due_date { get; private set; }
+        public Date due_date { get; private set; }
         public IList<IPayment> payments { get; private set; }
 
         public bool is_paid_for()
trunk/product/MoMoney.Domain/Accounting/Billing/Company.cs
@@ -10,7 +10,7 @@ namespace MoMoney.Domain.accounting.billing
         string name { get; }
         void change_name_to(string company_name);
         void issue_bill_to(IAccountHolder customer, DateTime that_is_due_on, Money for_amount);
-        void pay(IAccountHolder person, Money amount, IDate date_of_payment);
+        void pay(IAccountHolder person, Money amount, Date date_of_payment);
     }
 
     [Serializable]
@@ -28,7 +28,7 @@ namespace MoMoney.Domain.accounting.billing
             customer.receive(new Bill(this, for_amount, that_is_due_on));
         }
 
-        public void pay(IAccountHolder person, Money amount, IDate date_of_payment)
+        public void pay(IAccountHolder person, Money amount, Date date_of_payment)
         {
             person.receive(new Income(date_of_payment, amount, this));
         }
trunk/product/MoMoney.Domain/Accounting/Growth/income.cs
@@ -7,7 +7,7 @@ namespace MoMoney.Domain.Accounting.Growth
 {
     public interface IIncome : IEntity
     {
-        IDate date_of_issue { get; }
+        Date date_of_issue { get; }
         Money amount_tendered { get; }
         ICompany company { get; }
     }
@@ -15,7 +15,7 @@ namespace MoMoney.Domain.Accounting.Growth
     [Serializable]
     internal class Income : Entity<IIncome>, IIncome
     {
-        public Income(IDate date_of_issue, Money amount_tendered, ICompany company)
+        public Income(Date date_of_issue, Money amount_tendered, ICompany company)
         {
             this.company = company;
             this.amount_tendered = amount_tendered;
@@ -24,7 +24,7 @@ namespace MoMoney.Domain.Accounting.Growth
 
         public ICompany company { get; private set; }
         public Money amount_tendered { get; private set; }
-        public IDate date_of_issue { get; private set; }
+        public Date date_of_issue { get; private set; }
 
         public bool Equals(Income obj)
         {
trunk/product/MoMoney.Domain/Accounting/AccountHolderSpecs.cs
@@ -2,6 +2,7 @@ using System;
 using System.Collections.Generic;
 using developwithpassion.bdd.contexts;
 using Gorilla.Commons.Testing;
+using Gorilla.Commons.Utility;
 using MoMoney.Domain.accounting.billing;
 using MoMoney.Domain.Accounting.Growth;
 using MoMoney.Domain.Core;
@@ -55,19 +56,15 @@ namespace MoMoney.Domain.accounting
                             income_for_february_2007 = an<IIncome>();
                             income_for_february_2008 = an<IIncome>();
 
-                            income_for_january_2007.is_told_to(x => x.date_of_issue).it_will_return(
-                                new DateTime(2007, 01, 01).as_a_date());
+                            income_for_january_2007.is_told_to(x => x.date_of_issue).it_will_return<Date>( new DateTime(2007, 01, 01));
                             income_for_january_2007.is_told_to(x => x.amount_tendered).it_will_return(new Money(1000, 00));
 
-                            income_for_february_2007.is_told_to(x => x.date_of_issue).it_will_return(
-                                new DateTime(2007, 02, 01).as_a_date());
+                            income_for_february_2007.is_told_to(x => x.date_of_issue).it_will_return<Date>( new DateTime(2007, 02, 01));
                             income_for_february_2007.is_told_to(x => x.amount_tendered).it_will_return(new Money(1000,
                                                                                                                  00));
 
-                            income_for_february_2008.is_told_to(x => x.date_of_issue).it_will_return(
-                                new DateTime(2008, 02, 01).as_a_date());
-                            income_for_february_2008.is_told_to(x => x.amount_tendered).it_will_return(new Money(1000,
-                                                                                                                 00));
+                            income_for_february_2008.is_told_to(x => x.date_of_issue).it_will_return<Date>( new DateTime(2008, 02, 01));
+                            income_for_february_2008.is_told_to(x => x.amount_tendered).it_will_return(new Money(1000, 00));
                         };
 
         because b = () =>
trunk/product/MoMoney.Domain/Core/DateExtensions.cs
@@ -5,11 +5,6 @@ namespace MoMoney.Domain.Core
 {
     public static class DateExtensions
     {
-        public static IDate as_a_date(this DateTime date)
-        {
-            return (Date) date;
-        }
-
         public static IYear as_a_year(this int year)
         {
             return new Year(new DateTime(year, 01, 01));
trunk/product/MoMoney.Service/Application/AddNewIncomeCommand.cs
@@ -35,7 +35,7 @@ namespace MoMoney.Service.Application
                     .pay(
                     tasks.get_the_current_customer(),
                     item.amount.as_money(),
-                    item.recieved_date.as_a_date()
+                    item.recieved_date
                     );
             }
         }
@@ -47,7 +47,7 @@ namespace MoMoney.Service.Application
                        .all()
                        .where(x => x.amount_tendered.Equals(income.amount.as_money()))
                        .where(x => x.company.id.Equals(income.company_id))
-                       .where(x => x.date_of_issue.Equals(income.recieved_date.as_a_date()))
+                       .where(x => x.date_of_issue.Equals(income.recieved_date))
                        .Count() > 0;
         }
     }