 import Tunits
 
 class TimeUnitTests: QuickSpec {
+    static private func timeUnitWithCalendarWithMondayAsFirstWeekday() -> TimeUnit {
+        let tunit = TimeUnit()
+        let calendar = NSCalendar.currentCalendar()
+        calendar.firstWeekday = 2 // Monday
+        tunit.calendar = calendar
+        return tunit
+    }
+    
     override func spec() {
         describe("Initialization") {
             it ("can be initialized") {

                expect(TimeUnit.daysOfWeek(dateInWeekOfOctober7_2015)).to(equal(daysOfWeekOctober7_2015))
            }
            
// MARK: daysOfMonth
            it ("can create days of February 2015") {
                let daysInFebruary_2015 = [

                    expect(TimeUnit.beginningOfWeek(middleOfSeptember23_2015)).to(equal(beginningOfSeptember20_2015))
                }
                
                it ("can calculate the beginning of a week for a random date within the day") {
                    let randomTimeInSeptember25_2015 = dateFormatter.dateFromString("2015-09-25 10:43:27")!
                    expect(TimeUnit().beginningOfWeek(randomTimeInSeptember25_2015)).to(equal(beginningOfSeptember20_2015))
                    expect(TimeUnit.beginningOfWeek(randomTimeInSeptember25_2015)).to(equal(beginningOfSeptember20_2015))
                }
                
                it ("can calculate the beginning of a week with a calendar that has Monday as the first weekday") {
                    let beginningOfOctober5_2015 = dateFormatter.dateFromString("2015-10-05 00:00:00")!
                    let beginningOfOctober6_2015 = dateFormatter.dateFromString("2015-10-06 00:00:00")!
                    
                    let tunit = TimeUnitTests.timeUnitWithCalendarWithMondayAsFirstWeekday()
                    expect(tunit.beginningOfWeek(beginningOfOctober6_2015)).to(equal(beginningOfOctober5_2015))
                }
            }
            
