Skip to content
This repository

Fixed Single-second edge case. #871

Merged
merged 6 commits into from over 1 year ago

2 participants

Michael Krotscheck Tyler Keating
Michael Krotscheck

As promised, this fixes the edge case identified in the post-close comments on Pull Request #867 - to reiterate:

"Ok, so we (internally) identified a minor issue with this pull request, and that is in the edge case where the elapsed duration is exactly one second. The way the translation string is evaluated, it will try to find a string that terminates with "secondAgo" and or "secondIn", neither of which currently exists in the strings file or the unit tests. I'll fix it as soon as I'm back from vacation (sunday)."

Fix was to add the secondIn and secondAgo translation strings, and to adjust the unit tests to also test that particular edge case.

krotscheck added some commits
Michael Krotscheck krotscheck Added special getter for "elapsed" time. 05a59b2
Michael Krotscheck krotscheck Created "%E" and "%e" time formatters, for elapsed time measurments. 6838cc8
Michael Krotscheck krotscheck Added datetime/core dependency to datetime/localized. f3d6b47
Michael Krotscheck krotscheck Fixed source formatting.
Moved string formatting logic into datetime/localized as it depends on
localization.
Created stub method in datetime/core
Added %E and %e to unit tests in datetime/core
8578c01
Michael Krotscheck krotscheck Bugfix: Added an additional translation string (and appropriate unit
tests) for the one-second case that translates to _SC.DateTime.secondAgo
(previously unhandled)
d620d60
Michael Krotscheck krotscheck Merging upstream/master 032800b
Tyler Keating publickeating merged commit 5edc1cb into from
Tyler Keating

Thanks for staying on top of this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Showing 6 unique commits by 1 author.

Nov 13, 2012
Michael Krotscheck krotscheck Added special getter for "elapsed" time. 05a59b2
Nov 15, 2012
Michael Krotscheck krotscheck Created "%E" and "%e" time formatters, for elapsed time measurments. 6838cc8
Michael Krotscheck krotscheck Added datetime/core dependency to datetime/localized. f3d6b47
Michael Krotscheck krotscheck Fixed source formatting.
Moved string formatting logic into datetime/localized as it depends on
localization.
Created stub method in datetime/core
Added %E and %e to unit tests in datetime/core
8578c01
Dec 09, 2012
Michael Krotscheck krotscheck Bugfix: Added an additional translation string (and appropriate unit
tests) for the one-second case that translates to _SC.DateTime.secondAgo
(previously unhandled)
d620d60
Michael Krotscheck krotscheck Merging upstream/master 032800b
This page is out of date. Refresh to see the latest.
2  frameworks/datetime/frameworks/localized/resources/strings.js
@@ -13,6 +13,7 @@ SC.stringsFor('English', {
13 13 '_SC.DateTime.AMPMNames' : 'AM PM',
14 14
15 15 '_SC.DateTime.now' : 'Right now',
  16 + '_SC.DateTime.secondIn' : 'In a moment',
16 17 '_SC.DateTime.secondsIn' : 'In %e seconds',
17 18 '_SC.DateTime.minuteIn' : 'In a minute',
18 19 '_SC.DateTime.minutesIn' : 'In %e minutes',
@@ -27,6 +28,7 @@ SC.stringsFor('English', {
27 28 '_SC.DateTime.yearIn' : 'Next year',
28 29 '_SC.DateTime.yearsIn' : 'In %e years',
29 30
  31 + '_SC.DateTime.secondAgo' : 'A moment ago',
30 32 '_SC.DateTime.secondsAgo' : '%e seconds ago',
31 33 '_SC.DateTime.minuteAgo' : 'A minute ago',
32 34 '_SC.DateTime.minutesAgo' : '%e minutes ago',
10 frameworks/datetime/frameworks/localized/tests/system/datetime.js
@@ -23,8 +23,10 @@ module("SC.DateTime", {
23 23 test('FormatElapsed', function() {
24 24 var dateTimeTest = SC.DateTime.create();
25 25 equals(dateTimeTest.toFormattedString("%E"), "Right now");
26   -
27   - dateTimeTest = dateTimeTest.advance({ second: 20 }); // +20 seconds;
  26 +
  27 + dateTimeTest = dateTimeTest.advance({ second: 1 }); // +1 second;
  28 + equals(dateTimeTest.toFormattedString("%E"), "In a moment");
  29 + dateTimeTest = dateTimeTest.advance({ second: 19 }); // +19 seconds;
28 30 equals(dateTimeTest.toFormattedString("%E"), "In 20 seconds");
29 31 dateTimeTest = dateTimeTest.advance({ minute: 1 }); // +1 minute;
30 32 equals(dateTimeTest.toFormattedString("%E"), "In a minute");
@@ -55,7 +57,9 @@ test('FormatElapsed', function() {
55 57 equals(dateTimeTest.toFormattedString("%E"), "In 3 years");
56 58
57 59 var dateTimeTest = SC.DateTime.create();
58   - dateTimeTest = dateTimeTest.advance({ second: -20 }); // -20 seconds;
  60 + dateTimeTest = dateTimeTest.advance({ second: -1 }); // -1 second;
  61 + equals(dateTimeTest.toFormattedString("%E"), "A moment ago");
  62 + dateTimeTest = dateTimeTest.advance({ second: -19 }); // -19 seconds;
59 63 equals(dateTimeTest.toFormattedString("%E"), "20 seconds ago");
60 64 dateTimeTest = dateTimeTest.advance({ minute: -1 }); // -1 minute;
61 65 equals(dateTimeTest.toFormattedString("%E"), "A minute ago");

Tip: You can add notes to lines in a file. Hover to the left of a line to make a note

Something went wrong with that request. Please try again.