/**
   * Metoda s³u¿y do obliczenia liczby dni przepracowanych przez ankietera w podanym okresie.
   * Rozwa¿amy cztery przypadki nak³adania siê dat.
   *
   * @param interviewer
   * @param from
   * @param to
   * @return
   */
  private float numberOfDaysInWork(
      Interviewer interviewer, GregorianCalendar from, GregorianCalendar to) {
    float days = 0;
    List<Pair<GregorianCalendar, GregorianCalendar>> outOfWork = interviewer.getOutOfWorkTime();
    days += daysBetween(from.getTime(), to.getTime());
    for (Pair<GregorianCalendar, GregorianCalendar> entr : outOfWork) {
      if (from.compareTo(entr.getFirst()) <= 0
          && to.compareTo(entr.getSecond()) >= 0) { // nie nak³adaja siê
        days -= daysBetween(entr.getFirst().getTime(), entr.getSecond().getTime());
      }
      if (from.compareTo(entr.getFirst()) >= 0
          && to.compareTo(entr.getSecond()) >= 0
          && from.compareTo(entr.getSecond()) <= 0) { // from jest w srodku okresu niepracuj¹cego
        days -= daysBetween(from.getTime(), entr.getSecond().getTime());
      }
      if (from.compareTo(entr.getFirst()) <= 0
          && to.compareTo(entr.getSecond()) <= 0
          && entr.getFirst().compareTo(to) <= 0) { // to jest w œrodku okresu niepracuj¹cego
        days -= daysBetween(entr.getFirst().getTime(), to.getTime());
      }
      if (from.compareTo(entr.getFirst()) >= 0
          && to.compareTo(entr.getSecond()) <= 0) { // obie daty sa w srodku okresu niepracuj¹cego
        days -= daysBetween(from.getTime(), to.getTime());
      }
    }

    return days;
  }
Ejemplo n.º 2
0
  /* ========================================
   * 		Comparable's implemented methods
   * ========================================
   */
  @Override
  public int compareTo(Object o) {

    int comparison = 0;
    if (o instanceof Event) {
      Event ve = (Event) o;
      comparison = dateStart.compareTo(ve.dateStart);
      if (comparison == 0) {
        comparison = dateEnd.compareTo(ve.dateEnd);
      }
    } else {
      comparison = -1;
    }
    return comparison;
  } // ---------------------------------------- compareTo()
 public static int[] getTimeDifference(GregorianCalendar start, GregorianCalendar stop) {
   if (start.compareTo(stop) > 0) {
     GregorianCalendar temp = start;
     start = stop;
     stop = temp;
   }
   double diff_seconds = (stop.getTimeInMillis() - start.getTimeInMillis()) / 1000.0;
   int days = 0;
   int hours = 0;
   int minutes = 0;
   int seconds = 0;
   while (diff_seconds >= 86400) {
     days++;
     diff_seconds -= 86400;
   }
   while (diff_seconds >= 3600) {
     hours++;
     diff_seconds -= 3600;
   }
   while (diff_seconds >= 60) {
     minutes++;
     diff_seconds -= 60;
   }
   seconds = (int) diff_seconds;
   int[] ret = {days, hours, minutes, seconds};
   return ret;
 }
 /**
  * Metoda zwraca mapê, która zawiera jako klucze poszczególne dni zadanego okresu (od from do
  * to),w których ankieter zebra³ jakieœ ankiety, zaœ wartoœciami s¹ liczby zebranych ankiet w tym
  * dniu.
  *
  * @param surveys
  * @param interviewer
  * @param from
  * @param to
  * @return
  */
 public HashMap<GregorianCalendar, Integer> getAmountOfFilledSurveysInDays(
     List<Survey> surveys, Interviewer interviewer, GregorianCalendar from, GregorianCalendar to) {
   HashMap<GregorianCalendar, Integer> filledSurveysInDays =
       new HashMap<GregorianCalendar, Integer>();
   for (Survey survey : surveys) {
     GregorianCalendar data = survey.getFinishTime();
     int year = data.get(Calendar.YEAR);
     int month = data.get(Calendar.MONTH);
     int day = data.get(Calendar.DAY_OF_MONTH);
     GregorianCalendar date = new GregorianCalendar(year, month, day);
     if (date.compareTo(from) >= 0 && to.compareTo(date) >= 0) {
       if (!filledSurveysInDays.containsKey(date)) {
         filledSurveysInDays.put(date, 1);
       } else {
         filledSurveysInDays.put(date, filledSurveysInDays.get(date) + 1);
       }
     }
   }
   return filledSurveysInDays;
 }
 /**
  * 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;
 }
Ejemplo n.º 6
0
 /** EventInfoのメンバ変数に基づいてデータベースを更新する */
 public void updateDB() {
   // mRecurrenceが存在するデータについてはこのアプリでは無視する
   if (mRecurrence != null) {
     return;
   }
   Log.d("CALENDAR", "UpdateDB" + mTitle + ":" + getStartTimeString());
   // タイトルと更新日時を取得する
   String[] projection = {TITLE, UPDATED};
   String selection = EVENT_ID + " = ?";
   String[] selectionArgs = {mEventId};
   // 読み込まれたデータのID情報をもとにデータベースを検索
   Cursor c =
       mContentResolver.query(
           EventCalendarActivity.RESOLVER_URI, projection, selection, selectionArgs, null);
   if (c.moveToNext()) {
     // すでに存在しているデータの場合は更新処理
     String dbUpdated = c.getString(c.getColumnIndex(UPDATED));
     c.close();
     GregorianCalendar cal = DateStrCls.toCalendar(dbUpdated);
     // 更新日時を比較する(Calendar#compareTo)
     //  等しければ、0
     //  Googleカレンダーの更新日時(mUpdated) が新しい場合は 1
     //  データベースの更新日時(cal)が新しい場合は -1
     int comp = mUpdated.compareTo(cal);
     if (comp == 0) {
       // アップデートの日時が等しい
     } else if (comp > 0) {
       // Googleカレンダー側が新しいので更新する。
       if (isCanceled()) {
         // Googleカレンダーで削除されたものなら、データベースから削除
         mContentResolver.delete(EventCalendarActivity.RESOLVER_URI, selection, selectionArgs);
       } else {
         mContentResolver.update(
             EventCalendarActivity.RESOLVER_URI, getValues(), selection, selectionArgs);
       }
     } else if (comp < 0) {
       // DB側が新しければ後でGoogleカレンダーにアップロードするためにrecordにMODIFIEDフラグをセット
       ContentValues cv = new ContentValues();
       cv.put(MODIFIED, 1);
       mContentResolver.update(EventCalendarActivity.RESOLVER_URI, cv, selection, selectionArgs);
     }
   } else {
     // DBに同じデータが見つからなかったとき
     c.close();
     if (isCanceled()) {
       // Googleカレンダー側で削除されていれば何もしない
       return;
     }
     // 新規データとしてInsert
     mContentResolver.insert(EventCalendarActivity.RESOLVER_URI, getValues());
   }
 }
Ejemplo n.º 7
0
  @Override
  boolean sjekkPin(int kode) {
    if (isSperret()) return false;

    GregorianCalendar date = new GregorianCalendar();
    int result = date.compareTo(expires);

    if (result > 0) return false;

    if (kode == getPinkode()) return true;

    return false;
  }
  public void actionPerformed(ActionEvent e) {
    Object source = e.getSource();

    if (source == anul) {
      dispose();
    }

    if (source == save) {

      Date now;
      GregorianCalendar cal = new GregorianCalendar();
      now = (Date) jdate.getValue();
      cal.setTime(now);
      if (cal.compareTo(interviewer.getRelieveDay()) >= 0) {
        interviewer.setOutOfWorkTime(interviewer.getRelieveDay(), cal);
        int y1 = interviewer.getRelieveDay().get(Calendar.YEAR); // .toString();
        int m1 = interviewer.getRelieveDay().get(Calendar.MONTH);
        int d1 = interviewer.getRelieveDay().get(Calendar.DAY_OF_MONTH);
        int y2 = cal.get(Calendar.YEAR);
        int m2 = cal.get(Calendar.MONTH);
        int d2 = cal.get(Calendar.DAY_OF_MONTH);
        String s =
            Integer.toString(d1)
                + "."
                + Integer.toString(m1 + 1)
                + "."
                + Integer.toString(y1)
                + " - "
                + Integer.toString(d2)
                + "."
                + Integer.toString(m2 + 1)
                + "."
                + Integer.toString(y2);
        interviewer.setRelieveDay(null);
        JOptionPane.showMessageDialog(this, "Przywrócono ankietera");
        active.setText("Ankieter jest aktywny");
        listModel.addElement(s);
        // JList newJlist = new JList(getTimeOutWork(interviewer));
        // workOutTime = newJlist;
        // SwingUtilities.updateComponentTreeUI(this);
        // System.out.println("dzien zwolnienia ankietera "+ interviewer.getRelieveDay().getTime());
        dispose();
      } else {
        JOptionPane.showMessageDialog(this, "Data nieprawid³owa");
      }
    }
  }
Ejemplo n.º 9
0
  private void nextRaid(Info info) {
    GregorianCalendar nextRaid = raids.get(info.getChannel());
    GregorianCalendar now = Utils.getRealDate(info);
    int diffMins = (int) ((nextRaid.getTimeInMillis() - now.getTimeInMillis()) / 1000 / 60);
    if (nextRaid.compareTo(now) < 0) {
      info.sendMessage("There is no future raid set.");
      return;
    }
    String tz = info.getMessage().substring(9).trim();
    tz = substituteTimeZone(tz);
    TimeZone timeZone;
    if (tz.length() == 0) timeZone = tZF("GMT");
    else timeZone = tZF(tz);
    formatter.setTimeZone(timeZone);

    String ret = "The next raid is scheduled for " + formatter.format(nextRaid.getTime());
    ret = ret + getTimeDifference(diffMins);
    info.sendMessage(ret);
  }
Ejemplo n.º 10
0
  public boolean checkLate(GregorianCalendar g) {
    boolean late = false;
    GregorianCalendar current = new GregorianCalendar();
    current.set(GregorianCalendar.HOUR, 0);
    current.set(GregorianCalendar.HOUR_OF_DAY, 0);
    current.set(GregorianCalendar.MINUTE, 0);
    current.set(GregorianCalendar.SECOND, 0);
    current.set(GregorianCalendar.MILLISECOND, 0);
    g.set(GregorianCalendar.HOUR, 0);
    g.set(GregorianCalendar.HOUR_OF_DAY, 0);
    g.set(GregorianCalendar.MINUTE, 0);
    g.set(GregorianCalendar.SECOND, 0);
    g.set(GregorianCalendar.MILLISECOND, 0);

    if (current.compareTo(g) > 0) {
      late = true;
    }

    return late;
  }
Ejemplo n.º 11
0
 public ArrayList<Reminder> getActiveReminders() {
   ArrayList<Reminder> reminders = new ArrayList<Reminder>();
   try {
     SQLiteDatabase dataBase = dbHelper.getReadableDatabase();
     Cursor cursor =
         dataBase.query(Reminder.ReminderEntry.TABLE_NAME, null, null, null, null, null, null);
     if (cursor.moveToFirst()) {
       while (cursor.isAfterLast() == false) {
         Reminder reminder = new Reminder();
         String date = cursor.getString(Reminder.ReminderEntry.INDEX_DATE);
         GregorianCalendar gregorianCalendar = DateUtils.parserStringDate(date);
         reminder.setDate(gregorianCalendar);
         GregorianCalendar currentDate = new GregorianCalendar();
         String state = cursor.getString(Reminder.ReminderEntry.INDEX_ESTADO);
         /*if(state.compareTo("RESOLVED") == 0 ||state.compareTo("resolved") == 0){
             continue;
         }*/
         if (gregorianCalendar.compareTo(currentDate) == 1) {
           reminder.setIdReminder(cursor.getInt(Reminder.ReminderEntry.INDEX_ENTRY_ID));
           reminder.setTitle(cursor.getString(Reminder.ReminderEntry.INDEX_TITLE));
           reminder.setNotes(cursor.getString(Reminder.ReminderEntry.INDEX_NOTES));
           reminder.setDaysAfter(cursor.getInt(Reminder.ReminderEntry.INDEX_DAYS_AFTER));
           reminder.setHourRange(cursor.getInt(Reminder.ReminderEntry.INDEX_HOUR_RANGE));
           String photoPath = cursor.getString(Reminder.ReminderEntry.INDEX_PHOTO_PATH);
           String voiceNotePath = cursor.getString(Reminder.ReminderEntry.INDEX_VOICE_NOTE_PATH);
           reminder.setPhotoPath(photoPath);
           reminder.setVoiceNotePath(voiceNotePath);
           reminder.defineDatesOfNotifications();
           reminders.add(reminder);
         }
         cursor.moveToNext();
       }
     }
   } catch (Exception e) {
     e.printStackTrace();
   }
   Collections.sort(reminders);
   // Collections.reverse(reminders);
   return reminders;
 }
  @Transactional
  @Scheduled(fixedDelay = 15 * 60 * 1000) // Every 15 minutes
  public void onSchedule() {
    final GregorianCalendar now = new GregorianCalendar();

    for (final UserDetails userDetails : this.userDetailsService.loadUsersWithMissingActivation()) {
      final CustomUserDetails user = (CustomUserDetails) userDetails;
      if (!user.isEnabled() && null != user.getRegistrationToken()) {
        final GregorianCalendar registeredSince = new GregorianCalendar();
        registeredSince.setTime(user.getRegisteredSince());

        registeredSince.add(Calendar.HOUR_OF_DAY, ACTIVATION_TIMEOUT_HOURS);
        if (registeredSince.compareTo(now) < 0) {
          log.info(
              "User {} hasn't been activated for too long {} h, deleting user",
              user.getUsername(),
              ACTIVATION_TIMEOUT_HOURS);
          this.userDetailsService.deleteUser(user.getUsername());
        }
      }
    }
  }
 @Override
 public boolean erSperret() {
   GregorianCalendar tid = new GregorianCalendar();
   if (tid.compareTo(utgår) >= 0) return true;
   return false;
 }
  /**
   * Returns the most recent Movement record related to a CollectionObject.
   *
   * <p>This method currently returns the related Movement record with the latest (i.e. most recent
   * in time) Location Date field value.
   *
   * @param session a repository session.
   * @param collectionObjectCsid a CollectionObject identifier (CSID)
   * @throws ClientException
   * @return the most recent Movement record related to the CollectionObject identified by the
   *     supplied CSID.
   */
  protected static DocumentModel getMostRecentMovement(
      CoreSession session, String collectionObjectCsid) throws ClientException {
    DocumentModel mostRecentMovementDocModel = null;
    // Get Relation records for Movements related to this CollectionObject.
    //
    // Some values below are hard-coded for readability, rather than
    // being obtained from constants.
    String query =
        String.format(
            "SELECT * FROM %1$s WHERE " // collectionspace_core:tenantId = 1 "
                + "("
                + "  (%2$s:subjectCsid = '%3$s' "
                + "  AND %2$s:objectDocumentType = '%4$s') "
                + " OR "
                + "  (%2$s:objectCsid = '%3$s' "
                + "  AND %2$s:subjectDocumentType = '%4$s') "
                + ")"
                + ACTIVE_DOCUMENT_WHERE_CLAUSE_FRAGMENT,
            RELATION_DOCTYPE,
            RELATIONS_COMMON_SCHEMA,
            collectionObjectCsid,
            MOVEMENT_DOCTYPE);
    if (logger.isTraceEnabled()) {
      logger.trace("query=" + query);
    }
    DocumentModelList relationDocModels = session.query(query);
    if (relationDocModels == null || relationDocModels.isEmpty()) {
      logger.warn(
          "Unexpectedly found no relations to Movement records to/from to this CollectionObject record.");
      return mostRecentMovementDocModel;
    } else {
      if (logger.isTraceEnabled()) {
        logger.trace(
            "Found "
                + relationDocModels.size()
                + " relations to Movement records to/from this CollectionObject record.");
      }
    }
    // Iterate through related movement records, to find the related
    // Movement record with the most recent location date.
    GregorianCalendar mostRecentLocationDate = EARLIEST_COMPARISON_DATE;
    // Note: the following value is used to compare any two records, rather
    // than to identify the most recent value so far encountered. Thus, it may
    // occasionally be set backward or forward in time, within the loop below.
    GregorianCalendar comparisonCreationDate = EARLIEST_COMPARISON_DATE;
    DocumentModel movementDocModel;
    Set<String> alreadyProcessedMovementCsids = new HashSet<>();
    String relatedMovementCsid;
    for (DocumentModel relationDocModel : relationDocModels) {
      // Due to the 'OR' operator in the query above, related Movement
      // record CSIDs may reside in either the subject or object CSID fields
      // of the relation record. Whichever CSID value doesn't match the
      // CollectionObject's CSID is inferred to be the related Movement record's CSID.
      relatedMovementCsid =
          (String) relationDocModel.getProperty(RELATIONS_COMMON_SCHEMA, SUBJECT_CSID_PROPERTY);
      if (relatedMovementCsid.equals(collectionObjectCsid)) {
        relatedMovementCsid =
            (String) relationDocModel.getProperty(RELATIONS_COMMON_SCHEMA, OBJECT_CSID_PROPERTY);
      }
      if (Tools.isBlank(relatedMovementCsid)) {
        continue;
      }
      // Because of the OR clause used in the query above, there may be
      // two or more Relation records returned in the query results that
      // reference the same Movement record, as either the subject
      // or object of a relation to the same CollectionObject record;
      // we need to filter out those duplicates.
      if (alreadyProcessedMovementCsids.contains(relatedMovementCsid)) {
        continue;
      } else {
        alreadyProcessedMovementCsids.add(relatedMovementCsid);
      }
      if (logger.isTraceEnabled()) {
        logger.trace("Related movement CSID=" + relatedMovementCsid);
      }
      movementDocModel = getDocModelFromCsid(session, relatedMovementCsid);
      if (movementDocModel == null) {
        continue;
      }

      // Verify that the Movement record is active. This will also exclude
      // versioned Movement records from the computation of the current
      // location, for tenants that are versioning such records.
      if (!isActiveDocument(movementDocModel)) {
        if (logger.isTraceEnabled()) {
          logger.trace("Skipping this inactive Movement record ...");
        }
        continue;
      }
      GregorianCalendar locationDate =
          (GregorianCalendar)
              movementDocModel.getProperty(MOVEMENTS_COMMON_SCHEMA, LOCATION_DATE_PROPERTY);
      // If the current Movement record lacks a location date, it cannot
      // be established as the most recent Movement record; skip over it.
      if (locationDate == null) {
        continue;
      }
      GregorianCalendar creationDate =
          (GregorianCalendar)
              movementDocModel.getProperty(COLLECTIONSPACE_CORE_SCHEMA, CREATED_AT_PROPERTY);
      if (locationDate.after(mostRecentLocationDate)) {
        mostRecentLocationDate = locationDate;
        if (creationDate != null) {
          comparisonCreationDate = creationDate;
        }
        mostRecentMovementDocModel = movementDocModel;
        // If the current Movement record's location date is identical
        // to that of the (at this time) most recent Movement record, then
        // instead compare the two records using their creation date values
      } else if (locationDate.compareTo(mostRecentLocationDate) == 0) {
        if (creationDate != null && creationDate.after(comparisonCreationDate)) {
          // The most recent location date value doesn't need to be
          // updated here, as the two records' values are identical
          comparisonCreationDate = creationDate;
          mostRecentMovementDocModel = movementDocModel;
        }
      }
    }
    return mostRecentMovementDocModel;
  }
Ejemplo n.º 15
0
 public boolean isTokenDateValid(GregorianCalendar token_date) {
   return (token_date.compareTo(new GregorianCalendar()) > 0);
 }