module('local-time');

test('null getFormattedDate when datetime missing', function() {
  var time = document.createElement('time', 'local-time');
  time.setAttribute('format', '%Y-%m-%dT%H:%M:%SZ');
  equal(time.getFormattedDate(), null);
});

test('null getFormattedDate when format missing', function() {
  var time = document.createElement('time', 'local-time');
  time.setAttribute('datetime', '1970-01-01T00:00:00.000Z');
  equal(time.getFormattedDate(), null);
});

test('getFormattedDate for datetime and format attributes', function() {
  var time = document.createElement('time', 'local-time');
  time.setAttribute('datetime', '1970-01-01T00:00:00.000Z');
  time.setAttribute('format', '%Y-%m-%d');
  equal(time.getFormattedDate(), window.epochLocalDate);
});

test('getFormattedDate with %z timezone offset', function() {
  var time = document.createElement('time', 'local-time');
  time.setAttribute('datetime', '1970-01-01T00:00:00.000Z');
  time.setAttribute('format', '%z');
  ok(time.getFormattedDate().match(/[+-]\d\d\d\d/)[0]);
});

test('ignores contents if datetime attribute is missing', function() {
  var time = document.createElement('time', 'local-time');
  time.setAttribute('format', '%Y-%m-%dT%H:%M:%SZ');
  equal(time.textContent, '');
});

test('sets formatted contents to format attribute', function() {
  var time = document.createElement('time', 'local-time');
  time.setAttribute('datetime', '1970-01-01T00:00:00.000Z');
  time.setAttribute('format', '%Y-%m-%d');
  equal(time.textContent, window.epochLocalDate);
});

test('sets formatted contents when parsed element is upgraded', function() {
  var root = document.createElement('div');
  root.innerHTML = '<time is="local-time" datetime="1970-01-01T00:00:00.000Z" ' +
    'format="%Y-%m-%d"></time>';
  if ('CustomElements' in window) {
    window.CustomElements.upgradeSubtree(root);
  }
  equal(root.children[0].textContent, window.epochLocalDate);
});

@@ -236,37 +236,32 @@
 ll);%0A%7D);%0A%0Atest('
-null 
 getFormattedDate
@@ -257,24 +257,45 @@
 rmattedDate 
+returns empty string 
 when format 
@@ -462,36 +462,34 @@
 ormattedDate(), 
-null
+''
 );%0A%7D);%0A%0Atest('ge
@@ -507,31 +507,488 @@
 ate 
-for datetime and format
+with only date attributes', function() %7B%0A  var time = document.createElement('time', 'local-time');%0A  time.setAttribute('datetime', '1970-01-01T00:00:00.000Z');%0A  time.setAttribute('day', 'numeric');%0A  time.setAttribute('month', 'short');%0A  time.setAttribute('year', 'numeric');%0A%0A  var value = time.getFormattedDate();%0A  var acceptable = %5B'Dec 31, 1969', '31 Dec 1969', 'Jan 1, 1970', '1 Jan 1970'%5D;%0A  ok(acceptable.indexOf(value) !== -1);%0A%7D);%0A%0Atest('getFormattedDate without year
  att
@@ -985,33 +985,32 @@
 t year attribute
-s
 ', function() %7B%0A
@@ -1154,84 +1154,201 @@
 te('
-format', '%25Y-%25m-%25d');%0A  equal(time.getFormattedDate(), window.epochLocalDate
+day', 'numeric');%0A  time.setAttribute('month', 'short');%0A%0A  var value = time.getFormattedDate();%0A  var acceptable = %5B'Dec 31', '31 Dec', 'Jan 1', '1 Jan'%5D;%0A  ok(acceptable.indexOf(value !== -1)
 );%0A%7D
@@ -1383,26 +1383,28 @@
 ith 
-%25z
+only
  time
-zone offset
+ attributes
 ', f
@@ -1560,20 +1560,65 @@
 te('
-format', '%25z
+hour', 'numeric');%0A  time.setAttribute('minute', '2-digit
 ');%0A
@@ -1657,20 +1657,19 @@
 ch(/
-%5B+-%5D
+%5E
 %5Cd%5Cd
+:
 %5Cd%5Cd
+$
 /)%5B0
@@ -1832,36 +1832,23 @@
 te('
-format', '%25Y-%25m-%25dT%25H:%25M:%25SZ
+year', 'numeric
 ');%0A
@@ -2093,37 +2093,31 @@
 te('
-format', '%25Y-%25m-%25d
+year', 'numeric
 ');%0A  
-equal
+ok
 (tim
@@ -2129,39 +2129,58 @@
 tContent
-, window.epochLocalDate
+ === '1969' %7C%7C time.textContent === '1970'
 );%0A%7D);%0A%0A
@@ -2382,33 +2382,21 @@
 0Z%22 
-' +%0A    'format=%22%25Y-%25m-%25d
+year=%22numeric
 %22%3E%3C/
@@ -2493,22 +2493,27 @@
 ;%0A  %7D%0A  
-equal(
+var text = 
 root.chi
@@ -2536,31 +2536,49 @@
 tent
-, window.epochLocalDate
+;%0A  ok(text === '1969' %7C%7C text === '1970'
 );%0A%7D

Fix tests.