var moment = require("../../moment");

exports.utc = {
    setUp : function (cb) {
        moment.lang('en');
        cb();
    },

    tearDown : function (cb) {
        moment.lang('en');
        cb();
    },

    "utc and local" : function (test) {
        test.expect(7);

        var m = moment(Date.UTC(2011, 1, 2, 3, 4, 5, 6)), zone, expected;
        m.utc();
        // utc
        test.equal(m.date(), 2, "the day should be correct for utc");
        test.equal(m.day(), 3, "the date should be correct for utc");
        test.equal(m.hours(), 3, "the hours should be correct for utc");

        // local
        m.local();
        if (m.zone() > 180) {
            test.equal(m.date(), 1, "the date should be correct for local");
            test.equal(m.day(), 2, "the day should be correct for local");
        } else {
            test.equal(m.date(), 2, "the date should be correct for local");
            test.equal(m.day(), 3, "the day should be correct for local");
        }
        zone = Math.ceil(m.zone() / 60);
        expected = (24 + 3 - zone) % 24;
        test.equal(m.hours(), expected, "the hours (" + m.hours() + ") should be correct for local");
        test.equal(moment().utc().zone(), 0, "timezone in utc should always be zero");
        test.done();
    },

    "creating with utc" : function (test) {
        test.expect(7);

        var diff = moment.utc().valueOf() - moment().valueOf(), m;
        diff = Math.abs(diff);
        // we check the diff rather than equality because sometimes they are off by a millisecond

        test.ok(diff < 5, "Calling moment.utc() should default to the current time");

        m = moment.utc([2011, 1, 2, 3, 4, 5, 6]);
        test.equal(m.date(), 2, "the day should be correct for utc array");
        test.equal(m.hours(), 3, "the hours should be correct for utc array");

        m = moment.utc("2011-02-02 3:04:05", "YYYY-MM-DD HH:mm:ss");
        test.equal(m.date(), 2, "the day should be correct for utc parsing format");
        test.equal(m.hours(), 3, "the hours should be correct for utc parsing format");

        m = moment.utc("2011-02-02T03:04:05+00:00");
        test.equal(m.date(), 2, "the day should be correct for utc parsing iso");
        test.equal(m.hours(), 3, "the hours should be correct for utc parsing iso");

        test.done();
    },

    "creating with utc without timezone" : function (test) {
        test.expect(4);

        var m = moment.utc("2012-01-02T08:20:00");
        test.equal(m.date(), 2, "the day should be correct for utc parse without timezone");
        test.equal(m.hours(), 8, "the hours should be correct for utc parse without timezone");

        m = moment.utc("2012-01-02T08:20:00+09:00");
        test.equal(m.date(), 1, "the day should be correct for utc parse with timezone");
        test.equal(m.hours(), 23, "the hours should be correct for utc parse with timezone");

        test.done();
    },

    "cloning with utc" : function (test) {
        test.expect(4);

        var m = moment.utc("2012-01-02T08:20:00");
        test.equal(moment.utc(m)._isUTC, true, "the local zone should be converted to UTC");
        test.equal(moment.utc(m.clone().utc())._isUTC, true, "the local zone should stay in UTC");

        m.zone(120);
        test.equal(moment.utc(m)._isUTC, true, "the explicit zone should stay in UTC");
        test.equal(moment.utc(m).zone(), 0, "the explicit zone should have an offset of 0");

        test.done();
    },

    "weekday with utc" : function (test) {
        test.expect(1);

        test.equal(
            moment('2013-09-15T00:00:00Z').utc().weekday(), // first minute of the day
            moment('2013-09-15T23:59:00Z').utc().weekday(), // last minute of the day
            "a UTC-moment's .weekday() should not be affected by the local timezone"
        );

        test.done();
    }
};

@@ -1254,24 +1254,25 @@
  be zero%22);%0A
+%0A
         test
@@ -1302,32 +1302,49 @@
 reating with utc
+ and no arguments
 %22 : function (te
@@ -1361,33 +1361,33 @@
     test.expect(
-7
+2
 );%0A%0A        var 
@@ -1390,46 +1390,89 @@
 var 
-diff = moment.utc().valueOf() -
+startOfTest = new Date().valueOf(),%0A            momentDefaultUtcTime =
  moment
+.utc
 ().v
@@ -1484,11 +1484,8 @@
 f(),
- m;
 %0A   
@@ -1493,39 +1493,69 @@
     
-diff = Math.abs(diff
+    afterMomentCreationTime = new Date().valueOf(
 );%0A
+%0A
         
 // w
@@ -1554,182 +1554,360 @@
     
-// we check the diff rather than equality because sometimes they are off by a millisecond%0A%0A        test.ok(diff %3C 5, %22Calling moment.utc() should default to the current time%22
+test.ok(startOfTest %3C= momentDefaultUtcTime, %22moment UTC default time should be now, not in the past%22);%0A        test.ok(momentDefaultUtcTime %3C= afterMomentCreationTime, %22moment UTC default time should be now, not in the future%22);%0A%0A        test.done();%0A    %7D,%0A%0A    %22creating with utc and a date parameter array%22 : function (test) %7B%0A        test.expect(6
 );%0A%0A
@@ -1906,32 +1906,36 @@
 ct(6);%0A%0A        
+var 
 m = moment.utc(%5B

Fix fragile utc default time test