title: Mocking dates in AngularJS / Jasmine tests
body: <p>I have a directive that initializes the Date object several times in several functions. 
  When Unit testing the individual functions I can handle stubbing the date like this:</p>
  
  <pre><code>(function (global) {
    var NativeDate = global.Date;
  
    global.stubDateConstructor = function (fakeDate) {
        global.Date = function () {
            global.Date = NativeDate;
            return fakeDate;
        }
    }
  }(this));
  
  // ageInYears()
  it("should return the age in years of the person given his/her birthdate", function() {
      stubDateConstructor(new Date('2010/01/01'));
      expect(ageInYears('01-01-1990')).toBe(20);
      stubDateConstructor(new Date('2010/01/01'));
      expect(ageInYears('01-01-1900')).toBe(110);
  });
  </code></pre>
  
  <p>For unittesting the directive itself, which calls the ageInYears and several other similar functions this isn't going to work as I after one call to Date() stubDateConstructor will have reset Date() to the real Date object.</p>
  
  <p>Is there a native way in AngularJS / Jasmine to handle these situations, or should I look into Sinon e.g.?</p>