Skip to content

Commit

Permalink
Use hh:mm instead of hh:mm:ss in time config fmt.
Browse files Browse the repository at this point in the history
  • Loading branch information
laurentg committed Mar 31, 2015
1 parent 536e564 commit 404d38d
Showing 1 changed file with 10 additions and 8 deletions.
Expand Up @@ -66,7 +66,7 @@ public void configure(JsonNode config) {
pricingBySecond = new ArrayList<>(); pricingBySecond = new ArrayList<>();
for (Iterator<Map.Entry<String, JsonNode>> i = config.path("prices").fields(); i.hasNext();) { for (Iterator<Map.Entry<String, JsonNode>> i = config.path("prices").fields(); i.hasNext();) {
Map.Entry<String, JsonNode> kv = i.next(); Map.Entry<String, JsonNode> kv = i.next();
int maxTimeSec = hmsToSeconds(kv.getKey()); int maxTimeSec = hmToMinutes(kv.getKey()) * 60;
int priceCent = (int) Math.round(kv.getValue().asDouble() * 100); int priceCent = (int) Math.round(kv.getValue().asDouble() * 100);
pricingBySecond.add(new P2<>(maxTimeSec, priceCent)); pricingBySecond.add(new P2<>(maxTimeSec, priceCent));
} }
Expand Down Expand Up @@ -98,14 +98,16 @@ public int compare(P2<Integer> o1, P2<Integer> o2) {
} }
} }


private int hmsToSeconds(String hmsStr) { private int hmToMinutes(String hmStr) {
String[] hms = hmsStr.split(":"); String[] hm = hmStr.split(":");
int seconds = 0; if (hm.length > 2)
for (String field : hms) { throw new IllegalArgumentException("Invalid time: '" + hmStr + "'. Must be either 'hh:mm' or 'mm'.");
seconds *= 60; int minutes = 0;
for (String field : hm) {
minutes *= 60;
int fieldValue = Integer.parseInt(field); int fieldValue = Integer.parseInt(field);
seconds += fieldValue; minutes += fieldValue;
} }
return seconds; return minutes;
} }
} }

0 comments on commit 404d38d

Please sign in to comment.