public void replaceState(final String state) {
    final String[] stateParts = state.split("/");
    final TimeUnit timeUnit =
        TimeUnit.fromValue(stateParts[0].equals("date") ? "day" : stateParts[0]);

    final int year, month, week;

    switch (timeUnit) {
      case DAY:
        setDate(stateParts[1]);
        break;
      case WEEK:
        year = Integer.valueOf(stateParts[1]);
        week = Integer.valueOf(stateParts[2]);
        setWeek(year, week);
        break;
      case MONTH:
        year = Integer.valueOf(stateParts[1]);
        month = Integer.valueOf(stateParts[2]);
        setMonth(year, month);
        break;
      case YEAR:
        year = Integer.valueOf(stateParts[1]);
        setYear(year);
        break;
    }
  }
  public String toJSONString(final Configuration env) {
    // TODO: Include information in JSON that tells which calendar cells should
    // be lit up - don't want to use UTC timestamps to determine that info

    final JSONObject json = new JSONObject();
    json.put("timeUnit", timeUnit.toString());
    json.put("currentTimespanLabel", timespanLabel());
    json.put("isToday", isToday());
    json.put("state", getState());
    json.put("start", getStart());
    json.put("end", getEnd());
    return json.toString();
  }