Skip to content

Commit 19cd0a0

Browse files
committed
Fixes ocpsoft#81
1 parent fb2846c commit 19cd0a0

13 files changed

Lines changed: 90 additions & 103 deletions

‎core/src/main/java/org/ocpsoft/prettytime/PrettyTime.java‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,8 @@ public Duration approximateDuration(Date then)
146146
* the difference between the reference {@link Date}, and the given {@link Date}. If the given {@link Date} is
147147
* <code>null</code>, the current value of {@link System#currentTimeMillis()} will be used instead.
148148
* <p>
149-
* <b>Note</b>: Precision may be lost if no supplied {@link TimeUnit} is granular enough to represent one millisecond
149+
* <b>Note</b>: Precision may be lost if no supplied {@link TimeUnit} is granular enough to represent the remainder
150+
* of time (in milliseconds).
150151
*
151152
* @param then The {@link Date} to be compared against the reference timestamp, or <i>now</i> if no reference
152153
* timestamp was provided
@@ -177,7 +178,9 @@ public List<Duration> calculatePreciseDuration(Date then)
177178
break;
178179
}
179180
}
180-
result.add(duration);
181+
182+
if (duration.getUnit().isPrecise())
183+
result.add(duration);
181184
}
182185
return result;
183186
}

‎core/src/main/java/org/ocpsoft/prettytime/TimeUnit.java‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,4 +41,10 @@ public interface TimeUnit
4141
* this.getMillisPerUnit()</code> or infinity if there are no greater TimeUnits
4242
*/
4343
public long getMaxQuantity();
44+
45+
/**
46+
* Whether or not this {@link TimeUnit} represents a price measurement of time, or a general concept of time. E.g:
47+
* "minute" as opposed to "moment".
48+
*/
49+
public boolean isPrecise();
4450
}

‎core/src/main/java/org/ocpsoft/prettytime/i18n/Resources.java‎

Lines changed: 6 additions & 101 deletions
Original file line numberDiff line numberDiff line change
@@ -15,107 +15,12 @@
1515
*/
1616
package org.ocpsoft.prettytime.i18n;
1717

18-
import java.util.ListResourceBundle;
19-
20-
public class Resources extends ListResourceBundle
18+
/**
19+
* Default resource bundle (English.)
20+
*
21+
* @author <a href="mailto:lincolnbaxter@gmail.com">Lincoln Baxter, III</a>
22+
*/
23+
public class Resources extends Resources_en
2124
{
22-
private static final Object[][] OBJECTS = new Object[][] {
23-
{ "CenturyPattern", "%n %u" },
24-
{ "CenturyFuturePrefix", "" },
25-
{ "CenturyFutureSuffix", " from now" },
26-
{ "CenturyPastPrefix", "" },
27-
{ "CenturyPastSuffix", " ago" },
28-
{ "CenturySingularName", "century" },
29-
{ "CenturyPluralName", "centuries" },
30-
{ "DayPattern", "%n %u" },
31-
{ "DayFuturePrefix", "" },
32-
{ "DayFutureSuffix", " from now" },
33-
{ "DayPastPrefix", "" },
34-
{ "DayPastSuffix", " ago" },
35-
{ "DaySingularName", "day" },
36-
{ "DayPluralName", "days" },
37-
{ "DecadePattern", "%n %u" },
38-
{ "DecadeFuturePrefix", "" },
39-
{ "DecadeFutureSuffix", " from now" },
40-
{ "DecadePastPrefix", "" },
41-
{ "DecadePastSuffix", " ago" },
42-
{ "DecadeSingularName", "decade" },
43-
{ "DecadePluralName", "decades" },
44-
{ "HourPattern", "%n %u" },
45-
{ "HourFuturePrefix", "" },
46-
{ "HourFutureSuffix", " from now" },
47-
{ "HourPastPrefix", "" },
48-
{ "HourPastSuffix", " ago" },
49-
{ "HourSingularName", "hour" },
50-
{ "HourPluralName", "hours" },
51-
{ "JustNowPattern", "%u" },
52-
{ "JustNowFuturePrefix", "" },
53-
{ "JustNowFutureSuffix", "moments from now" },
54-
{ "JustNowPastPrefix", "moments ago" },
55-
{ "JustNowPastSuffix", "" },
56-
{ "JustNowSingularName", "" },
57-
{ "JustNowPluralName", "" },
58-
{ "MillenniumPattern", "%n %u" },
59-
{ "MillenniumFuturePrefix", "" },
60-
{ "MillenniumFutureSuffix", " from now" },
61-
{ "MillenniumPastPrefix", "" },
62-
{ "MillenniumPastSuffix", " ago" },
63-
{ "MillenniumSingularName", "millennium" },
64-
{ "MillenniumPluralName", "millennia" },
65-
{ "MillisecondPattern", "%n %u" },
66-
{ "MillisecondFuturePrefix", "" },
67-
{ "MillisecondFutureSuffix", " from now" },
68-
{ "MillisecondPastPrefix", "" },
69-
{ "MillisecondPastSuffix", " ago" },
70-
{ "MillisecondSingularName", "millisecond" },
71-
{ "MillisecondPluralName", "milliseconds" },
72-
{ "MinutePattern", "%n %u" },
73-
{ "MinuteFuturePrefix", "" },
74-
{ "MinuteFutureSuffix", " from now" },
75-
{ "MinutePastPrefix", "" },
76-
{ "MinutePastSuffix", " ago" },
77-
{ "MinuteSingularName", "minute" },
78-
{ "MinutePluralName", "minutes" },
79-
{ "MonthPattern", "%n %u" },
80-
{ "MonthFuturePrefix", "" },
81-
{ "MonthFutureSuffix", " from now" },
82-
{ "MonthPastPrefix", "" },
83-
{ "MonthPastSuffix", " ago" },
84-
{ "MonthSingularName", "month" },
85-
{ "MonthPluralName", "months" },
86-
{ "SecondPattern", "%n %u" },
87-
{ "SecondFuturePrefix", "" },
88-
{ "SecondFutureSuffix", " from now" },
89-
{ "SecondPastPrefix", "" },
90-
{ "SecondPastSuffix", " ago" },
91-
{ "SecondSingularName", "second" },
92-
{ "SecondPluralName", "seconds" },
93-
{ "WeekPattern", "%n %u" },
94-
{ "WeekFuturePrefix", "" },
95-
{ "WeekFutureSuffix", " from now" },
96-
{ "WeekPastPrefix", "" },
97-
{ "WeekPastSuffix", " ago" },
98-
{ "WeekSingularName", "week" },
99-
{ "WeekPluralName", "weeks" },
100-
{ "YearPattern", "%n %u" },
101-
{ "YearFuturePrefix", "" },
102-
{ "YearFutureSuffix", " from now" },
103-
{ "YearPastPrefix", "" },
104-
{ "YearPastSuffix", " ago" },
105-
{ "YearSingularName", "year" },
106-
{ "YearPluralName", "years" },
107-
{ "AbstractTimeUnitPattern", "" },
108-
{ "AbstractTimeUnitFuturePrefix", "" },
109-
{ "AbstractTimeUnitFutureSuffix", "" },
110-
{ "AbstractTimeUnitPastPrefix", "" },
111-
{ "AbstractTimeUnitPastSuffix", "" },
112-
{ "AbstractTimeUnitSingularName", "" },
113-
{ "AbstractTimeUnitPluralName", "" } };
114-
115-
@Override
116-
public Object[][] getContents()
117-
{
118-
return OBJECTS;
119-
}
12025

12126
}

‎core/src/main/java/org/ocpsoft/prettytime/impl/ResourcesTimeUnit.java‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,12 @@ public void setMillisPerUnit(long millisPerUnit)
5757
this.millisPerUnit = millisPerUnit;
5858
}
5959

60+
@Override
61+
public boolean isPrecise()
62+
{
63+
return true;
64+
}
65+
6066
@Override
6167
public String toString()
6268
{

‎core/src/main/java/org/ocpsoft/prettytime/units/JustNow.java‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,4 +32,10 @@ protected String getResourceKeyPrefix()
3232
return "JustNow";
3333
}
3434

35+
@Override
36+
public boolean isPrecise()
37+
{
38+
return false;
39+
}
40+
3541
}

‎core/src/test/java/org/ocpsoft/prettytime/PrettyTimeI18n_AR_Test.java‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,12 @@ public long getMillisPerUnit()
190190
{
191191
return 5000;
192192
}
193+
194+
@Override
195+
public boolean isPrecise()
196+
{
197+
return false;
198+
}
193199
};
194200
t.clearUnits();
195201
t.registerUnit(unit, new SimpleTimeFormat()

‎core/src/test/java/org/ocpsoft/prettytime/PrettyTimeI18n_CA_Test.java‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,12 @@ public long getMillisPerUnit()
190190
{
191191
return 5000;
192192
}
193+
194+
@Override
195+
public boolean isPrecise()
196+
{
197+
return false;
198+
}
193199
};
194200
t.clearUnits();
195201
t.registerUnit(unit, new SimpleTimeFormat()

‎core/src/test/java/org/ocpsoft/prettytime/PrettyTimeI18n_FA_Test.java‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,12 @@ public long getMillisPerUnit()
192192
{
193193
return 5000;
194194
}
195+
196+
@Override
197+
public boolean isPrecise()
198+
{
199+
return false;
200+
}
195201
};
196202
t.clearUnits();
197203
t.registerUnit(unit, new SimpleTimeFormat()

‎core/src/test/java/org/ocpsoft/prettytime/PrettyTimeI18n_JA_Test.java‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,12 @@ public long getMillisPerUnit()
196196
{
197197
return 5000;
198198
}
199+
200+
@Override
201+
public boolean isPrecise()
202+
{
203+
return false;
204+
}
199205
};
200206
t.clearUnits();
201207
t.registerUnit(unit, new SimpleTimeFormat()

‎core/src/test/java/org/ocpsoft/prettytime/PrettyTimeI18n_KO_Test.java‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,12 @@ public long getMillisPerUnit()
190190
{
191191
return 5000;
192192
}
193+
194+
@Override
195+
public boolean isPrecise()
196+
{
197+
return false;
198+
}
193199
};
194200
t.clearUnits();
195201
t.registerUnit(unit, new SimpleTimeFormat()

0 commit comments

Comments
 (0)