Beispiel #1
0
 /** @return Stringa contenente l'orario corrente secondo il seguente formato: "hh:mm:ss" */
 @SuppressWarnings("deprecation")
 public String getCurrentTime() {
   int hh = calendar.getTime().getHours();
   int mm = calendar.getTime().getMinutes();
   int ss = calendar.getTime().getSeconds();
   return (hh + ":" + mm + ":" + ss);
 }
Beispiel #2
0
  protected static boolean isDay(ResultSet rs) throws Exception {
    GregorianCalendar current = new GregorianCalendar();

    Date begin = rs.getDate("begin");
    Date end = rs.getDate("end");

    if (current.getTime().after(begin) && current.getTime().before(end)) {
      CronSubExpression dom = new CronSubExpression(rs.getString("dom"), "dom");
      // Days of months are 1-31
      if (dom.isValid(current.get(Calendar.DAY_OF_MONTH))) {
        CronSubExpression mon = new CronSubExpression(rs.getString("mon"), "mon");
        // Months are 0-11
        if (mon.isValid(current.get(Calendar.MONTH) + 1)) {
          CronSubExpression dow = new CronSubExpression(rs.getString("dow"), "dow");
          // Sundays are 1, Saturdays 7
          if (dow.isValid(current.get(Calendar.DAY_OF_WEEK))) {
            CronSubExpression year = new CronSubExpression(rs.getString("year"), "year");
            // Year is exact
            if (year.isValid(current.get(Calendar.YEAR))) {
              return true;
            }
          }
        }
      }
    }

    return false;
  }
 /**
  * Metoda s³u¿y do obliczania iloœci dni, w których pracowa³ ankieter od pewnej ustalonej daty
  *
  * @param interviewer
  * @param from
  * @return
  */
 private float numberOfDaysInWork(Interviewer interviewer, GregorianCalendar from) {
   float days = 0;
   List<Pair<GregorianCalendar, GregorianCalendar>> outOfWork = interviewer.getOutOfWorkTime();
   if (interviewer.isActive()) {
     Date now = new Date();
     days += daysBetween(from.getTime(), now);
     for (Pair<GregorianCalendar, GregorianCalendar> entr : outOfWork) {
       if (from.compareTo(entr.getFirst()) <= 0) {
         days -= daysBetween(entr.getFirst().getTime(), entr.getSecond().getTime());
       }
       if (from.compareTo(entr.getFirst()) >= 0 && from.compareTo(entr.getSecond()) <= 0) {
         days -= daysBetween(from.getTime(), entr.getSecond().getTime());
       }
     }
   } else {
     days +=
         daysBetween(interviewer.getHiredDay().getTime(), interviewer.getRelieveDay().getTime());
     for (Pair<GregorianCalendar, GregorianCalendar> entr : outOfWork) {
       if (from.compareTo(entr.getFirst()) <= 0) {
         days -= daysBetween(entr.getFirst().getTime(), entr.getSecond().getTime());
       }
       if (from.compareTo(entr.getFirst()) >= 0 && from.compareTo(entr.getSecond()) <= 0) {
         days -= daysBetween(from.getTime(), entr.getSecond().getTime());
       }
     }
   }
   return days;
 }
Beispiel #4
0
  // This gets called from /mcmmo command
  public static void anniversaryCheck(final CommandSender sender) {
    if (sender instanceof Player) {
      GregorianCalendar anniversaryStart = new GregorianCalendar(2013, Calendar.FEBRUARY, 3);
      GregorianCalendar anniversaryEnd = new GregorianCalendar(2013, Calendar.FEBRUARY, 6);
      GregorianCalendar day = new GregorianCalendar();

      if (hasCelebrated.contains(sender.getName())) {
        return;
      }

      if (getDateRange(day.getTime(), anniversaryStart.getTime(), anniversaryEnd.getTime())) {
        sender.sendMessage(ChatColor.BLUE + "Happy 2 Year Anniversary!  In honor of all of");
        sender.sendMessage(
            ChatColor.BLUE + "nossr50's work and all the devs, here's a firework show!");
        final int firework_amount = 10;
        for (int i = 0; i < firework_amount; i++) {
          int delay = (int) (Math.random() * 3) + 4;
          Bukkit.getScheduler()
              .scheduleSyncDelayedTask(
                  mcMMO.p,
                  new Runnable() {
                    @Override
                    public void run() {
                      spawnFireworks((Player) sender);
                    }
                  },
                  20 * delay);
        }
      }
      hasCelebrated.add(sender.getName());
    }
  }
  /**
   * Some test code.
   *
   * @param args ignored.
   */
  public static void main(String[] args) {
    GregorianCalendar c0 = new GregorianCalendar(2006, 10, 1, 0, 0, 0);
    GregorianCalendar c1 = new GregorianCalendar(2006, 10, 1, 11, 37, 43);
    c1.set(Calendar.MILLISECOND, 123);

    System.out.println("Default: ");
    RelativeDateFormat rdf = new RelativeDateFormat(c0.getTime().getTime());
    System.out.println(rdf.format(c1.getTime()));
    System.out.println();

    System.out.println("Hide milliseconds: ");
    rdf.setSecondFormatter(new DecimalFormat("0"));
    System.out.println(rdf.format(c1.getTime()));
    System.out.println();

    System.out.println("Show zero day output: ");
    rdf.setShowZeroDays(true);
    System.out.println(rdf.format(c1.getTime()));
    System.out.println();

    System.out.println("Alternative suffixes: ");
    rdf.setShowZeroDays(false);
    rdf.setDaySuffix(":");
    rdf.setHourSuffix(":");
    rdf.setMinuteSuffix(":");
    rdf.setSecondSuffix("");
    System.out.println(rdf.format(c1.getTime()));
    System.out.println();
  }
Beispiel #6
0
  @Override
  public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) {
    super.onUpdate(context, appWidgetManager, appWidgetIds);

    for (int i = 0; i < appWidgetIds.length; i++) {
      GregorianCalendar cal = new GregorianCalendar();

      SimpleDateFormat weekFormat = new SimpleDateFormat("EEE");
      String strWeek = weekFormat.format(cal.getTime());

      SimpleDateFormat dateFormat = new SimpleDateFormat("MMMM dd");
      String strDate = dateFormat.format(cal.getTime());

      RemoteViews remote = new RemoteViews(context.getPackageName(), R.layout.myapp_widget);
      remote.setTextViewText(R.id.tvDate, strDate);
      remote.setTextViewText(R.id.tvWeekDay, strWeek);

      Intent intent = new Intent(context, MyAppWidget.class);
      intent.setAction(ACTION_MYAPPWIDGET_DISPLAY);
      intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetIds[i]);

      PendingIntent pIntent = PendingIntent.getBroadcast(context, 0, intent, 0);
      remote.setOnClickPendingIntent(R.id.btnWidget, pIntent);

      appWidgetManager.updateAppWidget(appWidgetIds[i], remote);
    }
  }
  private void updateCalendarLocale(Locale l) {
    int oldFirstDayOfWeek = calendar.getFirstDayOfWeek();
    setLocale(l);
    calendarComponent.setLocale(l);
    calendar = new GregorianCalendar(l);
    int newFirstDayOfWeek = calendar.getFirstDayOfWeek();

    // we are showing 1 week, and the first day of the week has changed
    // update start and end dates so that the same week is showing
    if (viewMode == Mode.WEEK && oldFirstDayOfWeek != newFirstDayOfWeek) {
      calendar.setTime(calendarComponent.getStartDate());
      calendar.add(java.util.Calendar.DAY_OF_WEEK, 2);
      // starting at the beginning of the week
      calendar.set(GregorianCalendar.DAY_OF_WEEK, newFirstDayOfWeek);
      Date start = calendar.getTime();

      // ending at the end of the week
      calendar.add(GregorianCalendar.DATE, 6);
      Date end = calendar.getTime();

      calendarComponent.setStartDate(start);
      calendarComponent.setEndDate(end);

      // Week days depend on locale so this must be refreshed
      setWeekendsHidden(hideWeekendsButton.getValue());
    }
  }
  public static DateDifference getDateDifference(GregorianCalendar d1, GregorianCalendar d2) {
    DateDifference d = new DateDifference();
    // Flip Start and End if required
    if (d1.getTime().after(d2.getTime())) {
      d.end = d1;
      d.srt = d2;
    } else {
      d.end = d2;
      d.srt = d1;
    }

    // Inital Year
    int srty = d.srt.get(Calendar.YEAR);
    int endy = d.end.get(Calendar.YEAR);
    d.years = endy - srty;
    int srtm = d.srt.get(Calendar.MONTH);
    int endm = d.end.get(Calendar.MONTH);
    int srtd = d.srt.get(Calendar.DAY_OF_MONTH);
    int endd = d.end.get(Calendar.DAY_OF_MONTH);

    if (srtm > endm) {
      // A Whole years had not yet pass.
      d.years--;

      d.months = (12 - srtm) + endm;

      if (srtd > endd) {
        d.months--;

        int sdim = getDaysInMonth(srtm, srty);
        d.days = sdim - srtd + endd;
      } else {
        d.days = endd - srtd;
      }

    } else if (srtm == endm) {

      if (srtd > endd) {
        d.years--;
        d.months = 11;
        int sdim = getDaysInMonth(srtm, srty);
        d.days = sdim - srtd + endd;
      } else {
        d.months = 0;
        d.days = endd - srtd;
      }
    } else {
      d.months = 12 - endm + srtm;
      if (srtd > endd) {
        d.months--;
      }

      int sdim = getDaysInMonth(srtm, srty);
      d.days = sdim - srtd + endd;
    }

    d.absDays = (int) ((d.end.getTimeInMillis() - d.srt.getTimeInMillis()) / (86400000L)) + 1;

    return d;
  }
 /**
  * give a list of two Integer : the smallest build to use and the biggest.
  *
  * @param request
  * @param builds
  * @return outList
  */
 private List<Integer> getFirstAndLastBuild(StaplerRequest request, List<?> builds) {
   List<Integer> outList = new ArrayList<Integer>(2);
   GraphConfigurationDetail graphConf =
       (GraphConfigurationDetail) createUserConfiguration(request);
   String configType = graphConf.getConfigType();
   if (configType.compareToIgnoreCase(GraphConfigurationDetail.BUILD_CONFIG) == 0) {
     if (graphConf.getBuildCount() <= 0) {
       configType = GraphConfigurationDetail.NONE_CONFIG;
     } else {
       if (builds.size() - graphConf.getBuildCount() > 0) {
         outList.add(builds.size() - graphConf.getBuildCount() + 1);
       } else {
         outList.add(1);
       }
       outList.add(builds.size());
     }
   } else if (configType.compareToIgnoreCase(GraphConfigurationDetail.DATE_CONFIG) == 0) {
     if (GraphConfigurationDetail.DEFAULT_DATE.compareTo(graphConf.getFirstDayCount()) == 0
         && GraphConfigurationDetail.DEFAULT_DATE.compareTo(graphConf.getLastDayCount()) == 0) {
       configType = GraphConfigurationDetail.NONE_CONFIG;
     } else {
       int firstBuild = -1;
       int lastBuild = -1;
       int var = builds.size();
       GregorianCalendar firstDate = null;
       GregorianCalendar lastDate = null;
       try {
         firstDate =
             GraphConfigurationDetail.getGregorianCalendarFromString(graphConf.getFirstDayCount());
         lastDate =
             GraphConfigurationDetail.getGregorianCalendarFromString(graphConf.getLastDayCount());
         lastDate.set(GregorianCalendar.HOUR_OF_DAY, 23);
         lastDate.set(GregorianCalendar.MINUTE, 59);
         lastDate.set(GregorianCalendar.SECOND, 59);
       } catch (ParseException e) {
         LOGGER.log(Level.SEVERE, "Error during the manage of the Calendar", e);
       }
       for (Iterator<?> iterator = builds.iterator(); iterator.hasNext(); ) {
         AbstractBuild<?, ?> currentBuild = (AbstractBuild<?, ?>) iterator.next();
         GregorianCalendar buildDate = new GregorianCalendar();
         buildDate.setTime(currentBuild.getTimestamp().getTime());
         if (firstDate.getTime().before(buildDate.getTime())) {
           firstBuild = var;
         }
         if (lastBuild < 0 && lastDate.getTime().after(buildDate.getTime())) {
           lastBuild = var;
         }
         var--;
       }
       outList.add(firstBuild);
       outList.add(lastBuild);
     }
   }
   if (configType.compareToIgnoreCase(GraphConfigurationDetail.NONE_CONFIG) == 0) {
     outList.add(1);
     outList.add(builds.size());
   }
   return outList;
 }
 private void resetCalendarTime(boolean resetEndTime) {
   resetTime(resetEndTime);
   if (resetEndTime) {
     calendarComponent.setEndDate(calendar.getTime());
   } else {
     calendarComponent.setStartDate(calendar.getTime());
     updateCaptionLabel();
   }
 }
Beispiel #11
0
  public static Date yearMonthDayNow() {
    final GregorianCalendar dateCalendar = new GregorianCalendar();
    dateCalendar.setTime(now());

    dateCalendar.set(Calendar.HOUR_OF_DAY, 12);
    dateCalendar.set(Calendar.MINUTE, 0);
    dateCalendar.set(Calendar.SECOND, 0);
    dateCalendar.set(Calendar.MILLISECOND, 0);

    LOG.debug("yearMonthDayNow() - yearMonthDayNow: " + dateCalendar.getTime());

    return dateCalendar.getTime();
  }
Beispiel #12
0
 private String[] getTimeSpan(GregorianCalendar dateTime, int increment) {
   SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'");
   sdf.setTimeZone(TimeZone.getTimeZone("UTC"));
   String sTime = sdf.format(dateTime.getTime());
   String eTime = null;
   if (increment != -1) {
     /** Add the increment and then subtract 1 second so that the timespans do not overlap. */
     dateTime.add(GregorianCalendar.MILLISECOND, increment);
     dateTime.add(GregorianCalendar.SECOND, -1);
     eTime = sdf.format(dateTime.getTime());
   }
   return new String[] {sTime, eTime};
 }
  private void handleActivityMetadata(byte[] value) {

    if (value.length != activityMetadataLength) {
      return;
    }

    // byte 0 is the data type: 1 means that each minute is represented by a triplet of bytes
    int dataType = value[0];
    // byte 1 to 6 represent a timestamp
    GregorianCalendar timestamp = MiBandDateConverter.rawBytesToCalendar(value, 1);

    // counter of all data held by the band
    int totalDataToRead = (value[7] & 0xff) | ((value[8] & 0xff) << 8);
    totalDataToRead *= (dataType == MiBandService.MODE_REGULAR_DATA_LEN_MINUTE) ? 3 : 1;

    // counter of this data block
    int dataUntilNextHeader = (value[9] & 0xff) | ((value[10] & 0xff) << 8);
    dataUntilNextHeader *= (dataType == MiBandService.MODE_REGULAR_DATA_LEN_MINUTE) ? 3 : 1;

    // there is a total of totalDataToRead that will come in chunks (3 bytes per minute if dataType
    // == 1 (MiBandService.MODE_REGULAR_DATA_LEN_MINUTE)),
    // these chunks are usually 20 bytes long and grouped in blocks
    // after dataUntilNextHeader bytes we will get a new packet of 11 bytes that should be parsed
    // as we just did

    if (activityStruct.isFirstChunk() && dataUntilNextHeader != 0) {
      GB.toast(
          getContext()
              .getString(
                  R.string.user_feedback_miband_activity_data_transfer,
                  DateTimeUtils.formatDurationHoursMinutes((totalDataToRead / 3), TimeUnit.MINUTES),
                  DateFormat.getDateTimeInstance().format(timestamp.getTime())),
          Toast.LENGTH_LONG,
          GB.INFO);
    }
    LOG.info(
        "total data to read: " + totalDataToRead + " len: " + (totalDataToRead / 3) + " minute(s)");
    LOG.info(
        "data to read until next header: "
            + dataUntilNextHeader
            + " len: "
            + (dataUntilNextHeader / 3)
            + " minute(s)");
    LOG.info(
        "TIMESTAMP: "
            + DateFormat.getDateTimeInstance().format(timestamp.getTime())
            + " magic byte: "
            + dataUntilNextHeader);

    activityStruct.startNewBlock(timestamp, dataUntilNextHeader);
  }
Beispiel #14
0
  public static Date yearMonthNow() {
    final GregorianCalendar dateCalendar = new GregorianCalendar();
    dateCalendar.setTime(now());

    final int lastDay = dateCalendar.getActualMaximum(Calendar.DAY_OF_MONTH);
    dateCalendar.set(Calendar.DAY_OF_MONTH, lastDay);
    dateCalendar.set(Calendar.HOUR_OF_DAY, 12);
    dateCalendar.set(Calendar.MINUTE, 0);
    dateCalendar.set(Calendar.SECOND, 0);
    dateCalendar.set(Calendar.MILLISECOND, 0);

    LOG.debug("yearMonthNow() - yearMonthNow: " + dateCalendar.getTime());
    return dateCalendar.getTime();
  }
Beispiel #15
0
  @Test
  public void testCreate() {
    Flight f = new Flight();

    GregorianCalendar gcCreated = new GregorianCalendar(2013, Calendar.DECEMBER, 22, 9, 44, 0);
    Timestamp dtCreated = new java.sql.Timestamp(gcCreated.getTime().getTime());

    String flightNumber = "PF-143";

    String departure = "Kyiv";

    String arrival = "London";

    GregorianCalendar gcDeparture = new GregorianCalendar(2013, Calendar.DECEMBER, 25, 10, 50, 0);
    Timestamp dtDeparture = new java.sql.Timestamp(gcDeparture.getTime().getTime());

    GregorianCalendar gcArrival = new GregorianCalendar(2013, Calendar.DECEMBER, 25, 12, 5, 0);
    Timestamp dtArrival = new java.sql.Timestamp(gcArrival.getTime().getTime());

    int ticketAmount = 3;

    double ticketPrice = 3000;
    f.setDateCreated(dtCreated);
    f.setFlightNumber(flightNumber);
    f.setDeparture(departure);
    f.setArrival(arrival);
    f.setDateDeparture(dtDeparture);
    f.setDateArrival(dtArrival);
    f.setTicketAmount(ticketAmount);
    f.setTicketPrice(ticketPrice);

    flightDao.getEntityManager().getTransaction().begin();
    flightDao.create(f);
    flightDao.getEntityManager().getTransaction().commit();

    int id = f.getId();
    Flight fReaded = flightDao.read(id);
    assertTrue(id == fReaded.getId());
    assertTrue(flightNumber.equals(fReaded.getFlightNumber()));
    assertTrue(departure.equals(fReaded.getDeparture()));
    assertTrue(arrival.equals(fReaded.getArrival()));
    assertTrue(dtDeparture.equals(fReaded.getDateDeparture()));
    assertTrue(dtArrival.equals(fReaded.getDateArrival()));
    assertTrue(ticketAmount == fReaded.getTicketAmount());
    assertTrue(ticketPrice == fReaded.getTicketPrice());

    flightDao.getEntityManager().getTransaction().begin();
    flightDao.delete(id);
    flightDao.getEntityManager().getTransaction().commit();
  }
  public static JobDescription example5() {
    GregorianCalendar calendar = new GregorianCalendar();

    JobDescription newJob = new JobDescription();

    newJob.setTitle("Janitor");
    newJob.setDescription("Clean the office");
    newJob.setSalary((float) 5000.0);
    newJob.setStartDate(calendar.getTime());
    calendar.add(Calendar.DATE, 365); // advance the date by one year
    newJob.setEndDate(calendar.getTime());

    return newJob;
  }
  public static JobDescription example3() {
    GregorianCalendar calendar = new GregorianCalendar();

    JobDescription newJob = new JobDescription();

    newJob.setTitle("Systems Administrator");
    newJob.setDescription("Maintain existing networks and upkeep of workstations");
    newJob.setSalary((float) 40000.0);
    newJob.setStartDate(calendar.getTime());
    calendar.add(Calendar.DATE, 365); // advance the date by one year
    newJob.setEndDate(calendar.getTime());

    return newJob;
  }
  public static JobDescription example4() {
    GregorianCalendar calendar = new GregorianCalendar();

    JobDescription newJob = new JobDescription();

    newJob.setTitle("Receptionist");
    newJob.setDescription("Answer any incoming calls and other administrative tasks");
    newJob.setSalary((float) 25000.0);
    newJob.setStartDate(calendar.getTime());
    calendar.add(Calendar.DATE, 365); // advance the date by one year
    newJob.setEndDate(calendar.getTime());

    return newJob;
  }
Beispiel #19
0
  public static void main(String[] args) {
    Logger logger = Logger.getLogger(Main.class);
    Date fTime = new Date();
    Date tTime = new Date();
    if (args.length == 2) {
      fTime = MyUtil.StringToDate(args[0]);
      tTime = MyUtil.StringToDate(args[1]);
    }
    if (args.length == 0) {
      Calendar fromWhen = Calendar.getInstance();
      fromWhen.setTime(fTime);
      GregorianCalendar gc =
          new GregorianCalendar(
              fromWhen.get(Calendar.YEAR),
              fromWhen.get(Calendar.MONTH),
              fromWhen.get(Calendar.DAY_OF_MONTH));
      tTime = (Date) gc.getTime();
      gc.add(Calendar.DATE, -1);
      fTime = (Date) gc.getTime();
    }
    logger.info("Stats process start " + new Date());

    long flag = (tTime.getTime() - fTime.getTime()) / 1000 / 3600 / 24;
    for (long temp = 0; temp < flag; temp++) {
      Calendar fromWhen = Calendar.getInstance();
      fromWhen.setTime(fTime);
      GregorianCalendar gc =
          new GregorianCalendar(
              fromWhen.get(Calendar.YEAR),
              fromWhen.get(Calendar.MONTH),
              fromWhen.get(Calendar.DAY_OF_MONTH));
      gc.add(Calendar.DATE, 1);
      tTime = (Date) gc.getTime();

      System.out.print(fTime);
      System.out.print("----");
      System.out.println(tTime);

      GoldStats.setAllGold(fTime);
      GoldStats.setAllPearl(fTime);
      GoldStats.setAllCredit(fTime);
      StockStats.StartStats(fTime);
      // 家族等级分布
      TribeStats.setAllTribeLevel(fTime);

      fTime = tTime;
    }
    logger.info("Stats process end " + new Date());
  }
  public static JobDescription example2() {
    GregorianCalendar calendar = new GregorianCalendar();

    JobDescription newJob = new JobDescription();

    newJob.setTitle("Software Developer");
    newJob.setDescription(
        "Participate in the design and development of the Data Integrator product");
    newJob.setSalary((float) 50000.0);
    newJob.setStartDate(calendar.getTime());
    calendar.add(Calendar.DATE, 365); // advance the date by one year
    newJob.setEndDate(calendar.getTime());

    return newJob;
  }
  public static JobDescription example1() {
    GregorianCalendar calendar = new GregorianCalendar();

    JobDescription newJob = new JobDescription();

    newJob.setTitle("Instructor");
    newJob.setDescription(
        "Deliver course materials to clients and assist with any hands on sessions");
    newJob.setSalary((float) 45000.0);
    newJob.setStartDate(calendar.getTime());
    calendar.add(Calendar.DATE, 365); // advance the date by one year
    newJob.setEndDate(calendar.getTime());

    return newJob;
  }
Beispiel #22
0
  public static void getMaxes(String table) throws Throwable {

    // create some good default dates

    GregorianCalendar gc = new GregorianCalendar();
    gc.set(Calendar.YEAR, 1989);

    long begin = gc.getTime().getTime();

    gc.set(Calendar.YEAR, 2002);

    long end = gc.getTime().getTime();

    getMaxes(table, begin, end);
  }
Beispiel #23
0
 public Employee(String n, String work, int salary, int year, int month, int day) {
   super(n);
   this.work = work;
   this.salary = salary;
   GregorianCalendar calendar = new GregorianCalendar(year, month - 1, day);
   hireday = calendar.getTime();
 }
Beispiel #24
0
 private Date getNextYearFor(Date date) {
   GregorianCalendar previousYearToDate = new GregorianCalendar();
   previousYearToDate.setTime(date);
   int prevYear = previousYearToDate.get(Calendar.YEAR) + 1;
   previousYearToDate.set(Calendar.YEAR, prevYear);
   return previousYearToDate.getTime();
 }
  @RequestMapping(
      value = "/form",
      method = RequestMethod.POST,
      consumes = "application/x-www-form-urlencoded")
  @ResponseBody
  public Event addEventForm(
      @RequestParam String keyword,
      @RequestParam String theDay,
      @RequestParam String startDate,
      @RequestParam String duration,
      @RequestParam String initialEvent) {
    if (diaryHelper.md5(keyword).equals(password)) {
      Event event = new Event();
      event.setDescription(initialEvent);
      event.setDuration(diaryHelper.getDuration(duration));
      GregorianCalendar startDateCal = diaryHelper.getStartDateCal(startDate);
      event.setStartTime(startDateCal.getTime());

      event.setId(
          diaryService.addEvent(DateUtil.resetHMS(diaryHelper.getDayCal(theDay).getTime()), event));

      return event;
    }
    return new Event();
  }
Beispiel #26
0
 public Employee(String n, double s, int year, int month, int day) {
   name = n;
   salary = s;
   GregorianCalendar calendar = new GregorianCalendar(year, month - 1, day);
   // GregorianCalendar uses 0 for January
   hireDay = calendar.getTime();
 }
Beispiel #27
0
 /**
  * @param days=n n为-,则取n天前,n为+,则取n天后的日期
  * @param date
  * @param days
  * @return
  */
 public Date getSomeDaysBeforeAfter(Date date, int days) {
   GregorianCalendar gc = new GregorianCalendar();
   gc.setTime(date);
   gc.add(5, days);
   gc.set(gc.get(Calendar.YEAR), gc.get(Calendar.MONTH), gc.get(Calendar.DATE));
   return gc.getTime();
 }
 public Axis xAxis() {
   Axis xAxis = new Axis();
   xAxis.setAutoGenerated(false);
   List<AxisValue> xAxisValues = new ArrayList<AxisValue>();
   GregorianCalendar now = new GregorianCalendar();
   GregorianCalendar today =
       new GregorianCalendar(
           now.get(Calendar.YEAR), now.get(Calendar.MONTH), now.get(Calendar.DAY_OF_MONTH));
   final java.text.DateFormat timeFormat = hourFormat();
   timeFormat.setTimeZone(TimeZone.getDefault());
   double start_hour_block = today.getTime().getTime();
   double timeNow = new Date().getTime();
   for (int l = 0; l <= 24; l++) {
     if ((start_hour_block + (60000 * 60 * (l))) < timeNow) {
       if ((start_hour_block + (60000 * 60 * (l + 1))) >= timeNow) {
         endHour = start_hour_block + (60000 * 60 * (l));
         l = 25;
       }
     }
   }
   for (int l = 0; l <= 24; l++) {
     double timestamp = (endHour - (60000 * 60 * l));
     xAxisValues.add(
         new AxisValue((long) (timestamp / FUZZER), (timeFormat.format(timestamp)).toCharArray()));
   }
   xAxis.setValues(xAxisValues);
   xAxis.setHasLines(true);
   xAxis.setTextSize(axisTextSize);
   return xAxis;
 }
Beispiel #29
0
 /** @tests java.util.Date#Date() */
 public void test_Constructor() {
   // Test for method java.util.Date()
   GregorianCalendar gc = new GregorianCalendar(1998, Calendar.OCTOBER, 13, 19, 9);
   long oldTime = gc.getTime().getTime();
   long now = new Date().getTime();
   assertTrue("Created incorrect date: " + oldTime + " now: " + now, oldTime < now);
 }
  public static void main(String[] args) {
    // Creates a GregorianCalendar object for the quizDay, outputs
    // information about the day, and modifies the day using class
    // methods
    // Creates the quizday object to store the day of the quiz

    GregorianCalendar quizDay = new GregorianCalendar(2014, Calendar.OCTOBER, 10);

    int month, day; // store date attributes
    // Get integer value for the characteristics
    day = quizDay.get(Calendar.DAY_OF_MONTH);
    System.out.println("Day: " + day);
    month = quizDay.get(Calendar.MONTH);
    System.out.println("Month: " + month);

    // Make the quiz 4 days earlier
    // Get the new date
    quizDay.add(Calendar.DAY_OF_MONTH, -4);
    day = quizDay.get(Calendar.DAY_OF_MONTH);
    System.out.println("Day of the quiz: " + day);
    month = quizDay.get(Calendar.MONTH);
    System.out.println("Month of the quiz: " + month);

    // Format the output of the date using DateFormat
    DateFormat fmt = DateFormat.getInstance();
    System.out.println("Formatted Date: " + fmt.format(quizDay.getTime()));
  }