@Test public void resolveTime() { Calendar c = Calendar.getInstance(); c.set(2018, 4, 22, 9, 15, 30); Map<String, Object> map = make("{year:2018, month:5, day:22, hour:9, minute:15, second:30}"); assertEquals(c.getTimeInMillis(), resolver.resolveTime(map, now).getTime(), 100); }
Date resolveTime(Map<String, Object> timeMap, Calendar now){ final boolean[] useDefaults = {false}; Calendar calendar = Calendar.getInstance(); calendar.clear(); if(timeMap.containsKey(Constants.KEY_OFFSET)) resolveOffsets((Map<String, Object>)timeMap.get(Constants.KEY_OFFSET), now); zip(Constants.KEYS_TIME, Constants.KEYS_CAL_FIELD) .forEach((key, field) -> { if(timeMap.containsKey(key)) { int value = ((Number) timeMap.get(key)).intValue(); if(key.equals(Constants.KEY_MONTH)) value -= 1; calendar.set(field, value); useDefaults[0] = true; }else { if(useDefaults[0]) calendar.set(field, getDefault(field, now)); else { calendar.set(field, now.get(field)); if(key.equals(Constants.KEY_HOUR)) calendar.set(Calendar.AM_PM, now.get(Calendar.AM_PM)); } } return true; }); if(timeMap.containsKey(Constants.KEY_SHIFT)) resolveShift((String)timeMap.get(Constants.KEY_SHIFT), calendar); return calendar.getTime(); }
ArgumentResolver { Date resolveTime(Map<String, Object> timeMap, Calendar now){ final boolean[] useDefaults = {false}; Calendar calendar = Calendar.getInstance(); calendar.clear(); if(timeMap.containsKey(Constants.KEY_OFFSET)) resolveOffsets((Map<String, Object>)timeMap.get(Constants.KEY_OFFSET), now); zip(Constants.KEYS_TIME, Constants.KEYS_CAL_FIELD) .forEach((key, field) -> { if(timeMap.containsKey(key)) { int value = ((Number) timeMap.get(key)).intValue(); if(key.equals(Constants.KEY_MONTH)) value -= 1; calendar.set(field, value); useDefaults[0] = true; }else { if(useDefaults[0]) calendar.set(field, getDefault(field, now)); else { calendar.set(field, now.get(field)); if(key.equals(Constants.KEY_HOUR)) calendar.set(Calendar.AM_PM, now.get(Calendar.AM_PM)); } } return true; }); if(timeMap.containsKey(Constants.KEY_SHIFT)) resolveShift((String)timeMap.get(Constants.KEY_SHIFT), calendar); return calendar.getTime(); } }
ArgumentResolver { Date resolveTime(Map<String, Object> timeMap, Calendar now){ final boolean[] useDefaults = {false}; Calendar calendar = Calendar.getInstance(); calendar.clear(); if(timeMap.containsKey(Constants.KEY_OFFSET)) resolveOffsets((Map<String, Object>)timeMap.get(Constants.KEY_OFFSET), now); zip(Constants.KEYS_TIME, Constants.KEYS_CAL_FIELD) .forEach((key, field) -> { if(timeMap.containsKey(key)) { int value = ((Number) timeMap.get(key)).intValue(); if(key.equals(Constants.KEY_MONTH)) value -= 1; calendar.set(field, value); useDefaults[0] = true; }else { if(useDefaults[0]) calendar.set(field, getDefault(field, now)); else { calendar.set(field, now.get(field)); if(key.equals(Constants.KEY_HOUR)) calendar.set(Calendar.AM_PM, now.get(Calendar.AM_PM)); } } return true; }); if(timeMap.containsKey(Constants.KEY_SHIFT)) resolveShift((String)timeMap.get(Constants.KEY_SHIFT), calendar); return calendar.getTime(); } ArgumentResolver(Context context); }
ArgumentResolver { Date resolveTime(Map<String, Object> timeMap, Calendar now){ final boolean[] useDefaults = {false}; Calendar calendar = Calendar.getInstance(); calendar.clear(); if(timeMap.containsKey(Constants.KEY_OFFSET)) resolveOffsets((Map<String, Object>)timeMap.get(Constants.KEY_OFFSET), now); zip(Constants.KEYS_TIME, Constants.KEYS_CAL_FIELD) .forEach((key, field) -> { if(timeMap.containsKey(key)) { int value = ((Number) timeMap.get(key)).intValue(); if(key.equals(Constants.KEY_MONTH)) value -= 1; calendar.set(field, value); useDefaults[0] = true; }else { if(useDefaults[0]) calendar.set(field, getDefault(field, now)); else { calendar.set(field, now.get(field)); if(key.equals(Constants.KEY_HOUR)) calendar.set(Calendar.AM_PM, now.get(Calendar.AM_PM)); } } return true; }); if(timeMap.containsKey(Constants.KEY_SHIFT)) resolveShift((String)timeMap.get(Constants.KEY_SHIFT), calendar); return calendar.getTime(); } ArgumentResolver(Context context); Reminder resolve(Map<String, Object> map, String rawText, Calendar now); }
ArgumentResolver { Date resolveTime(Map<String, Object> timeMap, Calendar now){ final boolean[] useDefaults = {false}; Calendar calendar = Calendar.getInstance(); calendar.clear(); if(timeMap.containsKey(Constants.KEY_OFFSET)) resolveOffsets((Map<String, Object>)timeMap.get(Constants.KEY_OFFSET), now); zip(Constants.KEYS_TIME, Constants.KEYS_CAL_FIELD) .forEach((key, field) -> { if(timeMap.containsKey(key)) { int value = ((Number) timeMap.get(key)).intValue(); if(key.equals(Constants.KEY_MONTH)) value -= 1; calendar.set(field, value); useDefaults[0] = true; }else { if(useDefaults[0]) calendar.set(field, getDefault(field, now)); else { calendar.set(field, now.get(field)); if(key.equals(Constants.KEY_HOUR)) calendar.set(Calendar.AM_PM, now.get(Calendar.AM_PM)); } } return true; }); if(timeMap.containsKey(Constants.KEY_SHIFT)) resolveShift((String)timeMap.get(Constants.KEY_SHIFT), calendar); return calendar.getTime(); } ArgumentResolver(Context context); Reminder resolve(Map<String, Object> map, String rawText, Calendar now);  }