Ejemplo n.º 1
0
  public void calculatePersonAge(Person person) {
    DateTime birthdate = person.getBirthdate();
    DateTime now = DateTime.now();

    Years years = Years.yearsBetween(birthdate, now);
    person.setAge(years.getYears());
  }
Ejemplo n.º 2
0
 private JSONArray constructResponse(Cursor c, String parameters) throws JSONException {
   JSONObject params = new JSONObject(parameters);
   c.moveToFirst();
   String[] columnNames = c.getColumnNames();
   JSONArray json = new JSONArray();
   String addressFieldName = null;
   if (params.has("addressFieldName") && null != params.getString("addressFieldName")) {
     addressFieldName =
         CaseFormat.LOWER_UNDERSCORE.to(
             CaseFormat.LOWER_CAMEL, params.getString("addressFieldName"));
   }
   while ((!c.isAfterLast())) {
     JSONObject obj = new JSONObject();
     for (int i = 0; i < columnNames.length; i++) {
       if (columnNames[i].equals("birthdate")) {
         obj.put(
             "age", Years.yearsBetween(DateTime.parse(c.getString(i)), new DateTime()).getYears());
       } else if (params.has("addressFieldName") && columnNames[i].equals(addressFieldName)) {
         JSONObject address = new JSONObject();
         address.put(params.getString("addressFieldName"), c.getString(i));
         obj.put("addressFieldValue", address);
       } else if (params.has("extraIdentifiers") && columnNames[i].equals("extraIdentifiers")) {
         JSONObject extraIdentifiers = new JSONObject();
         extraIdentifiers.put("extraIdentifiers", c.getString(i));
         obj.put("extraIdentifiers", extraIdentifiers);
       } else {
         obj.put(columnNames[i], c.getString(i));
       }
     }
     json.put(obj);
     c.moveToNext();
   }
   c.close();
   return json;
 }
Ejemplo n.º 3
0
  public static int getRecurrencesBetween(
      RecurrenceInterval interval, int multiplier, Date start, Date end) {
    DateTime then = new DateTime(start);
    DateTime now = new DateTime(end);

    int count = 1;
    switch (interval) {
      case ONCE:
        break;
      case DAY:
        count += Days.daysBetween(then, now).getDays() / multiplier;
        break;
      case MONTH:
        count += Months.monthsBetween(then, now).getMonths() / multiplier;
        break;
      case QUARTER:
        int quarters = Months.monthsBetween(then, now).getMonths() / 3;
        count += quarters / multiplier;
        break;
      case YEAR:
        count += Years.yearsBetween(then, now).getYears() / multiplier;
        break;
    }

    return count;
  }
Ejemplo n.º 4
0
 /**
  * 求两个直接的日期差,月份.
  *
  * <p>*MSECONDS|*SECONDS|*MINUTES|*HOURS|*DAYS|*MONTHS|*YEARS
  *
  * @param tDate 日期格式"20150404"
  * @param txDate 日期格式"20150404"
  * @param type type 选择 DAYS||MONTHS||YEARS
  * @return
  */
 public static int diff(String tDate, String txDate, String type) {
   if (txDate != null && tDate != null) {
     DateTime txDT = DateTime.parse(txDate, ISODateTimeFormat.basicDate());
     DateTime tDT = DateTime.parse(tDate, ISODateTimeFormat.basicDate());
     if (type.toUpperCase().endsWith("DAYS")) {
       return Days.daysBetween(txDT, tDT).getDays();
     } else if (type.toUpperCase().endsWith("MONTHS")) {
       return Months.monthsBetween(txDT, tDT).getMonths();
     } else if (type.toUpperCase().endsWith("YEARS")) {
       return Years.yearsBetween(txDT, tDT).getYears();
     } else if (type.toUpperCase().endsWith("YEARS")) {
       return Years.yearsBetween(txDT, tDT).getYears();
     }
   }
   return 0;
 }
Ejemplo n.º 5
0
 /**
  * 计算两个日期之间的时间间隔(不计算毫秒数)
  *
  * @param date1,date2
  * @param timeType
  * @return int
  */
 public static int periodBtDate(Date date1, Date date2, TimeType timeType) {
   if (date1 == null || date2 == null) {
     throw new IllegalArgumentException("date param can not be null");
   }
   DateTime start = fromDate(date1);
   DateTime end = fromDate(date2);
   int period = 0;
   switch (timeType.getCode()) {
     case "Y":
       period = Years.yearsBetween(start, end).getYears();
       break;
     case "M":
       period = Months.monthsBetween(start, end).getMonths();
       break;
     case "W":
       period = Weeks.weeksBetween(start, end).getWeeks();
       break;
     case "D":
       period = Days.daysBetween(start, end).getDays();
       break;
     case "H":
       period = Hours.hoursBetween(start, end).getHours();
       break;
     case "MIN":
       period = Minutes.minutesBetween(start, end).getMinutes();
       break;
     case "S":
       period = Seconds.secondsBetween(start, end).getSeconds();
       break;
     default:
       break;
   }
   return Math.abs(period);
 }
Ejemplo n.º 6
0
 public static int getYearsBetween(final String date1, final String date2, String format) {
   try {
     final DateTimeFormatter fmt =
         DateTimeFormat.forPattern(format)
             .withChronology(LenientChronology.getInstance(GregorianChronology.getInstance()));
     return Years.yearsBetween(fmt.parseDateTime(date1), fmt.parseDateTime(date2)).getYears();
   } catch (Exception ex) {
     ex.printStackTrace();
     return 0;
   }
 }
Ejemplo n.º 7
0
 /**
  * 求两个直接的日期差,月份.
  *
  * @param tDate
  * @param txDate
  * @param type 选择 DAYS||MONTHS||YEARS||HOURS||MSECONDS||MINUTES||SECONDS
  * @return
  */
 public static int diff(Date tDate, Date txDate, String type) {
   if (txDate != null && tDate != null) {
     DateTime txDT = new DateTime(txDate);
     DateTime tDT = new DateTime(tDate);
     if (type != null) {
       if (type.toUpperCase().endsWith("DAYS") || type.toUpperCase().endsWith("D")) {
         return Days.daysBetween(txDT, tDT).getDays();
       } else if (type.toUpperCase().endsWith("MONTHS")) {
         return Months.monthsBetween(txDT, tDT).getMonths();
       } else if (type.toUpperCase().endsWith("YEARS") || type.toUpperCase().endsWith("Y")) {
         return Years.yearsBetween(txDT, tDT).getYears();
       } else if (type.toUpperCase().endsWith("HOURS") || type.toUpperCase().endsWith("H")) {
         return Hours.hoursBetween(txDT, tDT).getHours();
       } else if (type.toUpperCase().endsWith("MSECONDS")) {
         return Seconds.secondsBetween(txDT, tDT).getSeconds();
       } else if (type.toUpperCase().endsWith("MINUTES")) {
         return Minutes.minutesBetween(txDT, tDT).getMinutes();
       } else if (type.toUpperCase().endsWith("SECONDS") || type.toUpperCase().endsWith("S")) {
         return Seconds.secondsBetween(txDT, tDT).getSeconds();
       }
     }
   }
   return 0;
 }
Ejemplo n.º 8
0
 public static int getAge(DateTime birthDate) {
   return Years.yearsBetween(birthDate, new DateTime()).getYears();
 }
Ejemplo n.º 9
0
  private Map<String, String> updateResumeMixInfo(Integer perId, String updateTable) {
    PerUser perUser = perUserEao.get(perId);
    if (perUser != null) {
      PerResumeBo vo;
      try {
        vo = perResumeEao.getResumeVo(perUser.getResId());
      } catch (Exception ex) {
        vo = null;
      }

      if (vo != null) {

        int degree = 0;
        String schoolName = "";
        String speciality = "";
        if (vo.getEducationInfoVoList() != null) {
          for (PerResumeBo.EducationInfoVo eduVo : vo.getEducationInfoVoList()) {
            if (eduVo != null && eduVo.getDegree() != null && eduVo.getDegree() > degree) {
              degree = eduVo.getDegree();
              schoolName = eduVo.getSchoolName();
              speciality = eduVo.getSpeciality();
            }
          }
        }

        ComReceiveAssistBo craVo = new ComReceiveAssistBo();
        if (vo.getWorkInfoVoList() != null && CollectionUtils.size(vo.getWorkInfoVoList()) > 0) {
          PerResumeBo.WorkInfoVo workVo = vo.getWorkInfoVoList().get(0);
          craVo.setLastPosName(workVo.getJobName());
          //                        craVo.setLastJobLocation(workVo.get); //个人简历无此数据
          craVo.setComName(workVo.getComName());
          craVo.setStart(workVo.getBegin());
          craVo.setEnd(workVo.getEnd());
        }

        craVo.setJobyearType(perUser.getJobyearType());
        craVo.setMobile(perUser.getMobile());
        if (vo.getIntentInfoVo() != null) {
          craVo.setSkill(vo.getIntentInfoVo().getProfessionSkill());
        }
        //                    craVo.setFileName();
        //                    craVo.setFilePath();

        // 计算年龄的公式修改为精确到年与搜索引擎匹配
        DateTime bDate = new DateTime(perUser.getBirthday());
        bDate = bDate.monthOfYear().setCopy(1).dayOfMonth().setCopy(1);
        DateTime nDate = DateTime.now();
        nDate = nDate.monthOfYear().setCopy(1).dayOfMonth().setCopy(2);
        Integer age = Years.yearsBetween(bDate, nDate).getYears();

        if (perUser.getResId() != null
            && perUser.getResId() > 0
            && StringUtils.isNotBlank(perUser.getUserName())) {
          getJdbcTemplateAction()
              .update(
                  "update "
                      + updateTable
                      + " set "
                      + "resume_id = ? , "
                      + "user_name=? , "
                      + "gender = ? , "
                      +
                      //                        "job_location = ? , " +
                      //                        "location = ? , " +
                      "age = ? , "
                      + "degree = ? , "
                      + "mix_info = ? , "
                      + "school_name = ? , "
                      + "speciality = ?, "
                      + "jobyear_type = ? "
                      + "where per_user_id = ?",
                  perUser.getResId(),
                  perUser.getUserName(),
                  perUser.getGender(),
                  //                            vo.getIntentInfoVo().getJobLocation(),
                  //                            "",
                  (age < 16 || age > 65) ? 16 : age,
                  degree,
                  (new Gson()).toJson(craVo),
                  schoolName,
                  speciality,
                  perUser.getJobyearType(),
                  perUser.getId());
        }

        Map<String, String> map = Maps.newHashMap();
        map.put("resumeId", String.valueOf(perUser.getResId()));
        map.put("userName", perUser.getUserName());
        map.put("gender", String.valueOf(perUser.getGender()));
        map.put("age", String.valueOf((age < 16 || age > 65) ? 16 : age));
        map.put("degree", String.valueOf(degree));
        map.put("mixInfo", (new Gson()).toJson(craVo));
        map.put("schoolName", schoolName);
        map.put("speciality", speciality);
        map.put("schoolName", schoolName);
        map.put("jobyearType", String.valueOf(perUser.getJobyearType()));

        return map;
      }
    }
    return null;
  }
Ejemplo n.º 10
0
  public void fillBuyHistoryPerInfo(ComResumeBuyHistory comResumeBuyHistory) {
    if (comResumeBuyHistory != null && StringUtils.isBlank(comResumeBuyHistory.getSchoolName())) {
      Integer perId = comResumeBuyHistory.getPerUserId();
      Integer id = comResumeBuyHistory.getId();

      try {
        Map<String, Object> perMap =
            getJdbcTemplate().queryForMap("SELECT * FROM per_user WHERE id=?", perId);

        String birthday = ObjectUtils.toString(perMap.get("birthday"));
        Integer age = 16;
        if (StringUtils.isNotBlank(birthday)) {
          // 计算年龄的公司修改为精确到年与搜索引擎匹配
          DateTime bDate = new DateTime(birthday);
          bDate = bDate.monthOfYear().setCopy(1).dayOfMonth().setCopy(1);
          DateTime nDate = DateTime.now();
          nDate = nDate.monthOfYear().setCopy(1).dayOfMonth().setCopy(1);
          age = Years.yearsBetween(bDate, nDate).getYears();
          age = (age < 16 || age > 65) ? 16 : age;
        }
        Integer gender = NumberUtils.toInt(ObjectUtils.toString(perMap.get("gender")), 0);
        Integer jobyearType = NumberUtils.toInt(ObjectUtils.toString(perMap.get("jobyearType")), 0);
        String schoolName = "";
        String speciality = "";
        String genderStr = OptionMap.getValueByType(OptionMap.OptionType.OPT_GENDER, gender, null);

        PerUser perUser = perUserEao.get(perId);
        if (perUser != null) {
          PerResumeBo vo;
          try {
            vo = perResumeEao.getResumeVo(perUser.getResId());
          } catch (Exception ex) {
            vo = null;
          }
          if (vo != null) {
            int degree = 0;
            if (vo.getEducationInfoVoList() != null) {
              for (PerResumeBo.EducationInfoVo eduVo : vo.getEducationInfoVoList()) {
                if (eduVo != null && eduVo.getDegree() != null && eduVo.getDegree() > degree) {
                  degree = eduVo.getDegree();
                  schoolName = eduVo.getSchoolName();
                  speciality = eduVo.getSpeciality();
                }
              }
            }
          }
        }
        String degreeStr =
            OptionMap.getValueByType(OptionMap.OptionType.OPT_PER_DEGREE, gender, null);
        ;

        comResumeBuyHistory.setAge(age);
        comResumeBuyHistory.setGender(genderStr);
        comResumeBuyHistory.setDegree(degreeStr);
        comResumeBuyHistory.setSchoolName(schoolName);
        comResumeBuyHistory.setSpeciality(speciality);
        comResumeBuyHistory.setJobyear(jobyearType);

        getJdbcTemplate()
            .update(
                "UPDATE com_resume_buy_history SET "
                    + " age = ?,"
                    + " gender = ?,"
                    + " degree = ?,"
                    + " school_name = ? "
                    + " speciality = ? "
                    + " jobyear = ? "
                    + " WHERE "
                    + " id=? ",
                age,
                genderStr,
                degreeStr,
                schoolName,
                speciality,
                jobyearType,
                id);

      } catch (Exception e) {
        // 不处理
      }
    }
  }
Ejemplo n.º 11
0
  public void fillIrcReservePerInfo(IrcReserve ircReserve) {
    if (ircReserve != null && StringUtils.isBlank(ircReserve.getUserName())) {
      Integer perId = ircReserve.getUserId();
      Integer resId = ircReserve.getResId();

      try {
        Map<String, Object> perMap =
            getJdbcTemplate().queryForMap("SELECT * FROM per_user WHERE id=?", perId);

        String birthday = ObjectUtils.toString(perMap.get("birthday"));
        Integer age = 16;
        if (StringUtils.isNotBlank(birthday)) {
          age = Years.yearsBetween(new DateTime(birthday), DateTime.now()).getYears();
          age = (age < 16 || age > 65) ? 16 : age;
        }
        String userName = ObjectUtils.toString(perMap.get("userName"));
        Integer gender = NumberUtils.toInt(ObjectUtils.toString(perMap.get("gender")), 0);
        Integer jobyearType = NumberUtils.toInt(ObjectUtils.toString(perMap.get("jobyearType")), 0);
        String schoolName = "";
        int degree = 0;
        PerUser perUser = perUserEao.get(perId);
        if (perUser != null) {
          PerResumeBo vo;
          try {
            vo = perResumeEao.getResumeVo(perUser.getResId());
          } catch (Exception ex) {
            vo = null;
          }
          if (vo != null) {
            if (vo.getEducationInfoVoList() != null) {
              for (PerResumeBo.EducationInfoVo eduVo : vo.getEducationInfoVoList()) {
                if (eduVo != null && eduVo.getDegree() != null && eduVo.getDegree() > degree) {
                  degree = eduVo.getDegree();
                  schoolName = eduVo.getSchoolName();
                }
              }
            }
          }
        }

        ircReserve.setUserName(userName);
        ircReserve.setGender(gender);
        ircReserve.setAge(age);
        ircReserve.setDegree(degree);
        ircReserve.setSchoolName(schoolName);
        ircReserve.setJobyearType(jobyearType);

        getJdbcTemplateIrc()
            .update(
                "UPDATE irc_reserve SET "
                    + " user_name = ?,"
                    + " age = ?,"
                    + " gender=?,"
                    + " jobyear_type = ? "
                    + " WHERE "
                    + " res_id=? ",
                userName,
                age,
                gender,
                jobyearType,
                resId);

      } catch (Exception e) {
        // 不处理
      }
    }
  }
  public void showDataEntryFragment(Event event, String programStage) {
    Bundle args = getArguments();
    DataEntryFragment fragment;
    String progId = mForm.getProgram().getId(); // new line :AgeToday
    if (event == null) {
      fragment =
          DataEntryFragment.newInstanceWithEnrollment(
              args.getString(ORG_UNIT_ID),
              args.getString(PROGRAM_ID),
              programStage,
              mForm.getEnrollment().localId);
    } else if (progId.equals("u9FZUM7kn38") && event != null) {
      /*- The If-Else block below is used to add the AgeToday Feature, a requirement for the HPV Campaign Program -*/
      fragment =
          DataEntryFragment.newInstanceWithEnrollment(
              args.getString(ORG_UNIT_ID),
              args.getString(PROGRAM_ID),
              programStage,
              event.getLocalEnrollmentId(),
              event.getLocalId());

      Enrollment enrollment = DataValueController.getEnrollment(event.getLocalEnrollmentId());
      List<TrackedEntityAttributeValue> teav = enrollment.getAttributes();
      // getActionBar().setSubtitle("Learner's AgeToday is: " + displayAge);
      // getActionBar().setDisplayShowTitleEnabled(true);

      for (TrackedEntityAttributeValue val : teav) {
        System.out.println("The learner details are: ->" + val.getValue());
      }

      // If passport number is entered then :  String learnerDob   = teav.get(4).getValue();
      // String learnerDob   = teav.get(3).getValue(); Training Instance - Position for LearnerDOB
      // when IDNumber is entered
      String learnerDob = teav.get(2).getValue(); // Staging Instance
      // String learnerDob   = teav.get(3).getValue();
      if (!isValidDate(learnerDob)) learnerDob = teav.get(3).getValue();
      System.out.println("What is in learnerstring :" + learnerDob);
      // --Use Joda Time to compute the learner's age today
      LocalDate birthdate = new LocalDate(learnerDob);
      LocalDate now = new LocalDate();
      // Compute learners age today
      Years learnersAgeToday = Years.yearsBetween(birthdate, now);

      System.out.println("The learners age today is:====>" + learnersAgeToday);
      ageToday = String.valueOf(learnersAgeToday);
      StringBuilder sbAgeToday = new StringBuilder(ageToday);
      sbAgeToday.delete(0, 1);

      sbAgeToday.append("EARS");
      System.out.println("The OLD learners age is:" + ageToday);
      //  String myDisplay = printLearnersAge();
      displayAge = sbAgeToday.toString();
      System.out.println("THE NEW LEARNERS AGE FIXED: " + displayAge);
      //   List<ProgramStageDataElement> programStageDataElements =
      // MetaDataController.getProgramStageDataElements
      // (MetaDataController.getProgramStage(event.getProgramStageId()));
      //  for(ProgramStageDataElement de: programStageDataElements) {
      //       System.out.println("The data elements in the program are:" + de.getDataElement());

      AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());

      builder
          .setMessage("The learner's Age Today is: " + displayAge)
          .setCancelable(false)
          .setTitle("Learner's Age Today Notification")
          .setPositiveButton(
              "OK",
              new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int id) {
                  dialog.dismiss();
                }
              });

      AlertDialog dialog = builder.create();
      dialog.show();

    } else {
      fragment =
          DataEntryFragment.newInstanceWithEnrollment(
              args.getString(ORG_UNIT_ID),
              args.getString(PROGRAM_ID),
              programStage,
              event.getLocalEnrollmentId(),
              event.getLocalId());
    }

    mNavigationHandler.switchFragment(fragment, ProgramOverviewFragment.CLASS_TAG, true);
  }
Ejemplo n.º 13
0
 public int getAge() {
   DateMidnight bd = new DateMidnight(birthdate);
   DateTime now = new DateTime(gameDate);
   Years age = Years.yearsBetween(bd, now);
   return age.getYears();
 }
    public Arrest(DateTime baseDate, PersonElementWrapper person) {

      date = person.birthdate;

      while (Years.yearsBetween(person.birthdate, date).getYears() < 14) {
        // make sure we don't arrest anyone younger than 14
        date = generateUniformRandomDateBetween(baseDate.minusYears(8), baseDate);
      }

      id =
          generateRandomID(
              "A",
              10); // could be a problem in the unlikely event you generate two arrests with the
                   // same id (this is used as an xml id)
      recordId = generateRandomID("", 3) + generateRandomID("-", 7);
      int chargeCount = generatePoissonInt(1, true);
      int courtCaseLength = (int) randomGenerator.nextGaussian(180, 60);
      int daysSinceArrest = Days.daysBetween(date, baseDate).getDays();
      arrestingAgency = new Agency();
      arrestingAgency.name = getRandomCity(person.state).toUpperCase() + " PD";

      if (courtCaseLength < daysSinceArrest) {
        dispoDate = date.plusDays(courtCaseLength);
      }

      int maxDaysInJail = 0;
      int maxDaysOfProbation = 0;
      felonyConviction = false;

      for (int i = 0; i < chargeCount; i++) {
        ArrestCharge arrestCharge = new ArrestCharge(person);
        charges.add(arrestCharge);
        if (arrestCharge.offense != null) {
          maxDaysInJail = Math.max(maxDaysInJail, arrestCharge.offense.daysInJail);
          maxDaysOfProbation = Math.max(maxDaysOfProbation, arrestCharge.offense.daysOfProbation);
          if ("F".equals(arrestCharge.severity.substring(0, 1))) {
            felonyConviction = true;
          }
          if (arrestCharge.offense.daysOfProbation > 0) {
            probationSupervisionAgency = arrestCharge.offense.supervisionAgency;
          }
          if (arrestCharge.offense.daysInJail > 0) {
            custodySupervisionAgency = arrestCharge.offense.supervisionAgency;
          }
        }
      }

      if (maxDaysInJail > 0 && dispoDate != null) {
        custodyEndDate = dispoDate.plusDays(maxDaysInJail);
        custodySupervisionId = id + "SC";
      }

      if (maxDaysOfProbation > 0 && dispoDate != null) {
        probationEndDate = dispoDate.plusDays(maxDaysOfProbation);
        probationSupervisionId = id + "SP";
      }

      if (coinFlip(.15)) {
        arrestingAgency.name = "State Police";
      }
    }