Jasmine Fiddle

by Winter Soldier

HTML

<script src="https://cdnjs.cloudflare.com/ajax/libs/jasmine/2.5.2/jasmine.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jasmine/2.5.2/jasmine-html.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jasmine/2.5.2/boot.js"></script>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/jasmine/2.5.2/jasmine.css">
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.1.1/jquery.js"></script>

JavaScript

/** I've run these tests from US(EST) **/
/** Testing from the observers location which is US **/
describe('js date testing', function() {
  it('build server from UK', function() {
    var ukDate = new Date("Mar 25 2015 01:56:24 UTC+0000");
    // If I print ukDate as is- I see Tue Mar 24 2015 20:56:24 GMT-0400 (Eastern Daylight Time)
    // But lets mock it since we would like the tests to pass as I assume the user is in US.
    spyOn(ukDate, 'toLocaleDateString').and.returnValue("3/24/2015");
    var val = ukDate.toLocaleDateString();
    expect(val).toEqual("3/24/2015");
    expect(ukDate.getUTCDate()).toEqual(25);
  });

  it('build server from another planet that is 22 hours east of UK', function() {
    var aliensWatch = new Date("Mar 25 2015 01:56:24 UTC+2200");
    // If I print aliensWatch as is- I see Mon Mar 23 2015 23:56:24 GMT-0400 (Eastern Daylight Time)
    // But lets mock it since we would like the tests to pass as I assume the user is in US.
    spyOn(aliensWatch, 'toLocaleDateString').and.returnValue("3/23/2015");
    var val = aliensWatch.toLocaleDateString();
    expect(val).toEqual("3/23/2015");
    expect(aliensWatch.getUTCDate()).toEqual(24);
  });

});