Permalink
Browse files

fixed issue with `Date[.prototype].lexicalize` sometimes returning "t…

…oday" instead of "yesterday"
  • Loading branch information...
1 parent 2ce206f commit 19c9a61a9e0ad5597298c718f85a8a07dc0c28a7 @constantology committed Mar 26, 2013
Showing with 11 additions and 3 deletions.
  1. +2 −1 d8.js
  2. +1 −1 d8.min.js
  3. +2 −1 src/lexicalize.js
  4. +2 −0 test/d8.test.js
  5. +2 −0 test/locale/GR.test.js
  6. +2 −0 test/locale/en-US.test.js
View
3 d8.js
@@ -513,7 +513,8 @@
use_noun = today || dkeys[1] != 'hours' || diff.hours < 25;
}
index = 3; break;
- case 'hours' : use_noun = diff.hours / 24 >= .75;
+ case 'hours' : today = date.format( 'l' ) === now.format( 'l' );
+ use_noun = diff.hours / 24 >= .75;
determiner = this.an;
index = 4; break;
case 'minutes' : index = 5; break;
View

Large diffs are not rendered by default.

Oops, something went wrong.
View
@@ -44,7 +44,8 @@
use_noun = today || dkeys[1] != 'hours' || diff.hours < 25;
}
index = 3; break;
- case 'hours' : use_noun = diff.hours / 24 >= .75;
+ case 'hours' : today = date.format( 'l' ) === now.format( 'l' );
+ use_noun = diff.hours / 24 >= .75;
determiner = this.an;
index = 4; break;
case 'minutes' : index = 5; break;
View
@@ -424,7 +424,9 @@ suite( 'd8 (en-GB/default)', function() {
expect( ( new Date( 2012, 0, 1 ) ).adjust( Date.WEEK, 7 ).lexicalize( new Date( 2012, 0, 1 ), 'approx' ) ).to.equal( 'about 1 and a half months from now' );
expect( ( new Date( 2012, 0, 1 ) ).adjust( Date.DAY, -1 ).lexicalize( new Date( 2012, 0, 1 ), 'approx' ) ).to.equal( 'yesterday' );
+ expect( ( new Date( 2012, 0, 1, 12 ) ).adjust( Date.HOUR, -18 ).lexicalize( new Date( 2012, 0, 1, 12 ), 'approx' ) ).to.equal( 'yesterday' );
expect( ( new Date( 2012, 0, 1 ) ).adjust( Date.DAY, 1 ).lexicalize( new Date( 2012, 0, 1 ), 'approx' ) ).to.equal( 'tomorrow' );
+ expect( ( new Date( 2012, 0, 1, 12 ) ).adjust( Date.HOUR, 18 ).lexicalize( new Date( 2012, 0, 1, 12 ), 'approx' ) ).to.equal( 'tomorrow' );
expect( ( new Date( 2012, 0, 1 ) ).adjust( Date.DAY, -2 ).adjust( Date.HOUR, -6 ).lexicalize( new Date( 2012, 0, 1 ), 'approx' ) ).to.equal( 'almost 2 and a half days ago' );
expect( ( new Date( 2012, 0, 1 ) ).adjust( Date.DAY, 2 ).adjust( Date.HOUR, 6 ).lexicalize( new Date( 2012, 0, 1 ), 'approx' ) ).to.equal( 'almost 2 and a half days from now' );
expect( ( new Date( 2012, 0, 1 ) ).adjust( Date.DAY, -3 ).lexicalize( new Date( 2012, 0, 1 ), 'approx' ) ).to.equal( '3 days ago' );
View
@@ -423,7 +423,9 @@ suite( 'd8 (greek-"ish")', function() {
expect( ( new Date( 2012, 0, 1 ) ).adjust( Date.WEEK, 7 ).lexicalize( new Date( 2012, 0, 1 ), 'approx' ) ).to.equal( 'περίπου 1 και μισή μήνες από τώρα' );
expect( ( new Date( 2012, 0, 1 ) ).adjust( Date.DAY, -1 ).lexicalize( new Date( 2012, 0, 1 ), 'approx' ) ).to.equal( 'εχθές' );
+ expect( ( new Date( 2012, 0, 1, 12 ) ).adjust( Date.HOUR, -18 ).lexicalize( new Date( 2012, 0, 1, 12 ), 'approx' ) ).to.equal( 'εχθές' );
expect( ( new Date( 2012, 0, 1 ) ).adjust( Date.DAY, 1 ).lexicalize( new Date( 2012, 0, 1 ), 'approx' ) ).to.equal( 'αύριο' );
+ expect( ( new Date( 2012, 0, 1, 12 ) ).adjust( Date.HOUR, 18 ).lexicalize( new Date( 2012, 0, 1, 12 ), 'approx' ) ).to.equal( 'αύριο' );
expect( ( new Date( 2012, 0, 1 ) ).adjust( Date.DAY, -2 ).adjust( Date.HOUR, -6 ).lexicalize( new Date( 2012, 0, 1 ), 'approx' ) ).to.equal( 'σχεδόν 2 και μισή ημέρες πριν' );
expect( ( new Date( 2012, 0, 1 ) ).adjust( Date.DAY, 2 ).adjust( Date.HOUR, 6 ).lexicalize( new Date( 2012, 0, 1 ), 'approx' ) ).to.equal( 'σχεδόν 2 και μισή ημέρες από τώρα' );
expect( ( new Date( 2012, 0, 1 ) ).adjust( Date.DAY, -3 ).lexicalize( new Date( 2012, 0, 1 ), 'approx' ) ).to.equal( '3 ημέρες πριν' );
@@ -421,7 +421,9 @@ suite( 'd8 (en-US)', function() {
expect( ( new Date( 2012, 0, 1 ) ).adjust( Date.WEEK, 7 ).lexicalize( new Date( 2012, 0, 1 ), 'approx' ) ).to.equal( 'about 1 and a half months from now' );
expect( ( new Date( 2012, 0, 1 ) ).adjust( Date.DAY, -1 ).lexicalize( new Date( 2012, 0, 1 ), 'approx' ) ).to.equal( 'yesterday' );
+ expect( ( new Date( 2012, 0, 1, 12 ) ).adjust( Date.HOUR, -18 ).lexicalize( new Date( 2012, 0, 1, 12 ), 'approx' ) ).to.equal( 'yesterday' );
expect( ( new Date( 2012, 0, 1 ) ).adjust( Date.DAY, 1 ).lexicalize( new Date( 2012, 0, 1 ), 'approx' ) ).to.equal( 'tomorrow' );
+ expect( ( new Date( 2012, 0, 1, 12 ) ).adjust( Date.HOUR, 18 ).lexicalize( new Date( 2012, 0, 1, 12 ), 'approx' ) ).to.equal( 'tomorrow' );
expect( ( new Date( 2012, 0, 1 ) ).adjust( Date.DAY, -2 ).adjust( Date.HOUR, -6 ).lexicalize( new Date( 2012, 0, 1 ), 'approx' ) ).to.equal( 'almost 2 and a half days ago' );
expect( ( new Date( 2012, 0, 1 ) ).adjust( Date.DAY, 2 ).adjust( Date.HOUR, 6 ).lexicalize( new Date( 2012, 0, 1 ), 'approx' ) ).to.equal( 'almost 2 and a half days from now' );
expect( ( new Date( 2012, 0, 1 ) ).adjust( Date.DAY, -3 ).lexicalize( new Date( 2012, 0, 1 ), 'approx' ) ).to.equal( '3 days ago' );

0 comments on commit 19c9a61

Please sign in to comment.