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;
 }
Пример #2
0
  /**
   * Draws a time sync line on the plot at the specified time. We take the approach of plotting the
   * time sync line like another data series in preference to using Quinn-Curtis' line drawing
   * function.
   *
   * @param time at which to draw the time sync line.
   */
  void drawTimeSyncLineAtTime(GregorianCalendar time) {
    assert time != null;

    // Peg timesync line to the plot area by setting the time
    // parameter to be on the plot max or plot min.
    if (time.before(plot.getCurrentTimeAxisMin())) {
      time = plot.getCurrentTimeAxisMin();
    } else if (time.after(plot.getCurrentTimeAxisMax())) {
      time = plot.getCurrentTimeAxisMax();
    }

    syncTime = time;

    if (timeSyncLinePlot == null) {
      AbstractAxis timeAxis = plot.getTimeAxis();
      if (timeAxis instanceof XYAxis) { // Only decorate time-like axes; TODO: move to AbstractAxis?
        timeSyncLinePlot = new XYMarkerLine((XYAxis) timeAxis, time.getTimeInMillis());
        timeSyncLinePlot.setForeground(PlotConstants.TIME_SYNC_LINE_COLOR);
        XYPlotContents contents = plot.getPlotView().getContents();
        contents.add(timeSyncLinePlot);
        contents.revalidate();
      }
    } else {
      timeSyncLinePlot.setValue(time.getTimeInMillis());
    }
  }
  public void testGetLocalAllDayCalendarTime() {
    TimeZone utcTimeZone = TimeZone.getTimeZone("UTC");
    TimeZone localTimeZone = TimeZone.getTimeZone("GMT-0700");
    GregorianCalendar correctLocal = new GregorianCalendar(localTimeZone);
    correctLocal.set(2011, 2, 10, 0, 0, 0);
    long correctLocalTime = correctLocal.getTimeInMillis();

    GregorianCalendar utcCalendar = new GregorianCalendar(utcTimeZone);
    utcCalendar.set(2011, 2, 10, 12, 23, 34);
    long utcTimeMillis = utcCalendar.getTimeInMillis();
    long convertedLocalTime =
        CalendarUtilities.getLocalAllDayCalendarTime(utcTimeMillis, localTimeZone);
    // Milliseconds aren't zeroed out and may not be the same
    assertEquals(convertedLocalTime / 1000, correctLocalTime / 1000);

    localTimeZone = TimeZone.getTimeZone("GMT+0700");
    correctLocal = new GregorianCalendar(localTimeZone);
    correctLocal.set(2011, 2, 10, 0, 0, 0);
    correctLocalTime = correctLocal.getTimeInMillis();

    utcCalendar = new GregorianCalendar(utcTimeZone);
    utcCalendar.set(2011, 2, 10, 12, 23, 34);
    utcTimeMillis = utcCalendar.getTimeInMillis();
    convertedLocalTime = CalendarUtilities.getLocalAllDayCalendarTime(utcTimeMillis, localTimeZone);
    // Milliseconds aren't zeroed out and may not be the same
    assertEquals(convertedLocalTime / 1000, correctLocalTime / 1000);
  }
Пример #4
0
  /**
   * Create 12 Standard Periods from the specified start date. Creates also Period Control from
   * DocType.
   *
   * @see DocumentTypeVerify#createPeriodControls(Properties, int, SvrProcess, String)
   * @param locale locale
   * @param startDate first day of the calendar year
   * @param dateFormat SimpleDateFormat pattern for generating the period names.
   * @return true if created
   */
  public boolean createStdPeriods(Locale locale, Timestamp startDate, String dateFormat) {
    if (locale == null) {
      MClient client = MClient.get(getCtx());
      locale = client.getLocale();
    }

    if (locale == null && Language.getLoginLanguage() != null)
      locale = Language.getLoginLanguage().getLocale();
    if (locale == null) locale = Env.getLanguage(getCtx()).getLocale();
    //
    SimpleDateFormat formatter;
    if (dateFormat == null || dateFormat.equals("")) dateFormat = "MMM-yy";
    formatter = new SimpleDateFormat(dateFormat, locale);

    //
    int year = getYearAsInt();
    GregorianCalendar cal = new GregorianCalendar(locale);
    if (startDate != null) {
      cal.setTime(startDate);
      if (cal.get(Calendar.YEAR) != year) // specified start date takes precedence in setting year
      year = cal.get(Calendar.YEAR);

    } else {
      cal.set(Calendar.YEAR, year);
      cal.set(Calendar.MONTH, 0);
      cal.set(Calendar.DAY_OF_MONTH, 1);
    }
    cal.set(Calendar.HOUR_OF_DAY, 0);
    cal.set(Calendar.MINUTE, 0);
    cal.set(Calendar.SECOND, 0);
    cal.set(Calendar.MILLISECOND, 0);

    //
    for (int month = 0; month < 12; month++) {

      Timestamp start = new Timestamp(cal.getTimeInMillis());
      String name = formatter.format(start);
      // get last day of same month
      cal.add(Calendar.MONTH, 1);
      cal.add(Calendar.DAY_OF_YEAR, -1);
      Timestamp end = new Timestamp(cal.getTimeInMillis());
      //
      MPeriod period = MPeriod.findByCalendar(getCtx(), start, getC_Calendar_ID(), get_TrxName());
      if (period == null) {
        period = new MPeriod(this, month + 1, name, start, end);
      } else {
        period.setC_Year_ID(this.getC_Year_ID());
        period.setPeriodNo(month + 1);
        period.setName(name);
        period.setStartDate(start);
        period.setEndDate(end);
      }
      period.saveEx(get_TrxName()); // 	Creates Period Control
      // get first day of next month
      cal.add(Calendar.DAY_OF_YEAR, 1);
    }

    return true;
  } //	createStdPeriods
Пример #5
0
  private String getTimeStamp() {
    GregorianCalendar cal = new GregorianCalendar();
    TimeZone tz = TimeZone.getTimeZone("EST5EDT");
    TimeZone calTz = cal.getTimeZone();
    long millis = cal.getTimeInMillis();
    int differenceTz = calTz.getOffset(millis) - tz.getOffset(millis);

    millis = cal.getTimeInMillis() - (long) differenceTz;
    return DATE_FORMAT.format(new Date(millis));
  }
Пример #6
0
  public static void main(String args[]) throws ParseException {
    /*Random random = new Random();

    System.out.println("{");
    for( int i = 0 ; i<300 ; i++ )
    {
    	System.out.println("{"+i + ","+ (i+Math.abs(random.nextInt())%20+1)+"},");
    }
    System.out.println("}");
    */
    /*
    for( int i=0 ; i<300 ; ++i )
    {

    	for( int[] row : ranges )
    	{
    		if( row[0]<=i && row[1]-1>i )
    			System.out.print("#");
    		else
    			System.out.print(" ");
    	}
    	System.out.println();
    }*/

    Request requests[] = new Request[ranges.length];

    GregorianCalendar start = new GregorianCalendar();
    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
    start.setTime(sdf.parse("2000-01-01"));

    for (int i = 0; i < 300; ++i) {
      int row[] = ranges[i];

      Request req = new Request();
      req.setRecievedAt(start.getTimeInMillis() + ((long) row[0]) * 1000 * 60 * 60 * 24);
      req.setFinishedAt(start.getTimeInMillis() + ((long) row[1]) * 1000 * 60 * 60 * 24);
      requests[i] = req;
    }

    Object[] res =
        weekly(
            requests,
            start.getTimeInMillis(),
            start.getTimeInMillis() + (long) 300 * 1000 * 60 * 60 * 24);

    for (Object c : res) {
      Object[] row = (Object[]) c;
      for (Object o : row) {
        System.out.print(o + ", ");
      }
      System.out.println();
    }
  }
Пример #7
0
  private boolean indexTableFill() {
    M_DB db = app.getDb();
    if (!db.isOpen()) {
      db.open();
    }
    GregorianCalendar calendar = new GregorianCalendar();
    long time = calendar.getTimeInMillis() / 1000;

    Random rand = new Random(time);

    for (int i = 0; i < 10; i++) {
      ContentValues cv = new ContentValues(3);
      cv.put("index_name", "ММВБ");
      cv.put("date", time - i * 1000);
      cv.put("value", rand.nextInt(10000));
      db.addRec("Indexes", cv);
      ContentValues cv1 = new ContentValues(3);
      // cv.clear();
      cv1.put("index_name", "NASDAQ");
      cv1.put("date", time - i * 1000);
      cv1.put("value", rand.nextInt(10000));
      db.addRec("Indexes", cv1);
    }
    if (db.isOpen()) {
      db.close();
    }
    return true;
  }
Пример #8
0
  /**
   * Creates a {@code Lifetime} instance that specifies a range of time that starts at the current
   * GMT time and has the specified duration in milliseconds.
   *
   * @param tokenTimeout the token timeout value (in milliseconds).
   * @return the constructed {@code Lifetime} instance.
   */
  public static Lifetime createDefaultLifetime(long tokenTimeout) {
    GregorianCalendar created = new GregorianCalendar();
    GregorianCalendar expires = new GregorianCalendar();
    expires.setTimeInMillis(created.getTimeInMillis() + tokenTimeout);

    return new Lifetime(created, expires);
  }
  public boolean isDateAndTimeInPast() {
    // TODO Auto-generated method stub

    long enteredTimeInMillis = calendar.getTimeInMillis();

    return (enteredTimeInMillis < currentTimeInMillis);
  }
Пример #10
0
 public static int getNumeroExpulsiones(Alumno alumno, GregorianCalendar fecha) {
   int ret = 0;
   PreparedStatement st = null;
   ResultSet res = null;
   try {
     // Tenemos que ver si hay expulsiones para ese alumno
     st =
         (PreparedStatement)
             MaimonidesApp.getApplication()
                 .getConector()
                 .getConexion()
                 .prepareStatement(
                     "SELECT count(*) FROM expulsiones WHERE alumno_id=? AND fecha<=?");
     st.setInt(1, alumno.getId());
     st.setDate(2, new java.sql.Date(fecha.getTimeInMillis()));
     res = st.executeQuery();
     if (res.next()) {
       ret = res.getInt(1);
     }
   } catch (SQLException ex) {
     Logger.getLogger(Expulsion.class.getName()).log(Level.SEVERE, null, ex);
   }
   Obj.cerrar(st, res);
   return ret;
 }
Пример #11
0
 /**
  * Calcula si un alumno esta expulsado. Se sabe si un alumno está expulsado por el número de dias
  * escolares entre la fecha de expulsión y la de parte. Un día escolar es el numero de partes con
  * fecha distinta entre dos fechas.
  *
  * @param anoEscolar Año escola
  * @param alumno Alumno
  * @param fecha Fecha en la que se quiere saber si el alumno estça expulsado
  * @return true si está expulsado en la fecha del parte, false si no lo está
  */
 public static Boolean isAlumnoExpulsado(Alumno alumno, GregorianCalendar fecha) {
   boolean ret = false;
   try {
     // Tenemos que ver si hay expulsiones para ese alumno
     PreparedStatement st =
         (PreparedStatement)
             MaimonidesApp.getApplication()
                 .getConector()
                 .getConexion()
                 .prepareStatement("SELECT * FROM expulsiones WHERE alumno_id=? AND fecha<=?");
     st.setInt(1, alumno.getId());
     st.setDate(2, new java.sql.Date(fecha.getTimeInMillis()));
     ResultSet res = st.executeQuery();
     while (res.next() && !ret) {
       // Si hay expulsiones tenemos que ver si son válidas
       // Para eso tenemos que contar los partes desde la fecha de expulsión hasta ahora
       GregorianCalendar fechaExpulsion = Fechas.toGregorianCalendar(res.getDate("fecha"));
       if (fechaExpulsion != null) {
         // Como la fecha de expulsión esta incluida tenemos que quitarle un día
         fechaExpulsion.add(GregorianCalendar.DATE, -1);
         // Y vemos la diferencia en días
         int dias = res.getInt("dias");
         long diasTranscurridos =
             Fechas.getDiferenciaTiempoEn(fecha, fechaExpulsion, GregorianCalendar.DATE);
         ret = diasTranscurridos <= dias;
       }
     }
     Obj.cerrar(st, res);
   } catch (SQLException ex) {
     Logger.getLogger(Expulsion.class.getName()).log(Level.SEVERE, null, ex);
   }
   return ret;
 }
Пример #12
0
 /** Alarmのデータを計算して、直近のAlarmの値をセットする */
 public void calcAlarm() {
   mAlarm = 0;
   if (mAlarmMap == null) {
     return;
   }
   long now = Calendar.getInstance().getTimeInMillis();
   long start = mStart.getTimeInMillis();
   if (start < now) {
     return;
   }
   long min = start;
   Set<String> keys = mAlarmMap.keySet();
   for (String k : keys) {
     if (k.equals(CalendarParser.VAL_ALERT)) {
       List<String> values = mAlarmMap.get(k);
       for (String v : values) {
         long alarm = start - Integer.valueOf(v) * MINUTE_BY_MILLI;
         if (now < alarm && alarm < min) {
           min = alarm;
         }
       }
     }
   }
   if (min < start) {
     mAlarm = min;
   }
 }
  public void testFindTransitionDate() {
    // We'll find some transitions and make sure that we're properly in or out of daylight time
    // on either side of the transition.
    // Use CST for testing (any other will do as well, as long as it has DST)
    TimeZone tz = TimeZone.getTimeZone("US/Central");
    // Get a calendar at January 1st of the current year
    GregorianCalendar calendar = new GregorianCalendar(tz);
    calendar.set(CalendarUtilities.sCurrentYear, Calendar.JANUARY, 1);
    // Get start and end times at start and end of year
    long startTime = calendar.getTimeInMillis();
    long endTime = startTime + (365 * CalendarUtilities.DAYS);
    // Find the first transition
    GregorianCalendar transitionCalendar =
        CalendarUtilities.findTransitionDate(tz, startTime, endTime, false);
    long transitionTime = transitionCalendar.getTimeInMillis();
    // Before should be in standard time; after in daylight time
    Date beforeDate = new Date(transitionTime - CalendarUtilities.HOURS);
    Date afterDate = new Date(transitionTime + CalendarUtilities.HOURS);
    assertFalse(tz.inDaylightTime(beforeDate));
    assertTrue(tz.inDaylightTime(afterDate));

    // Find the next one...
    transitionCalendar =
        CalendarUtilities.findTransitionDate(
            tz, transitionTime + CalendarUtilities.DAYS, endTime, true);
    transitionTime = transitionCalendar.getTimeInMillis();
    // This time, Before should be in daylight time; after in standard time
    beforeDate = new Date(transitionTime - CalendarUtilities.HOURS);
    afterDate = new Date(transitionTime + CalendarUtilities.HOURS);
    assertTrue(tz.inDaylightTime(beforeDate));
    assertFalse(tz.inDaylightTime(afterDate));

    // Captain Renault: What in heaven's name brought you to Casablanca?
    // Rick: My health. I came to Casablanca for the waters.
    // Also, they have no daylight savings time
    tz = TimeZone.getTimeZone("Africa/Casablanca");
    // Get a calendar at January 1st of the current year
    calendar = new GregorianCalendar(tz);
    calendar.set(CalendarUtilities.sCurrentYear, Calendar.JANUARY, 1);
    // Get start and end times at start and end of year
    startTime = calendar.getTimeInMillis();
    endTime = startTime + (365 * CalendarUtilities.DAYS);
    // Find the first transition
    transitionCalendar = CalendarUtilities.findTransitionDate(tz, startTime, endTime, false);
    // There had better not be one
    assertNull(transitionCalendar);
  }
Пример #14
0
  /**
   * Converts a {@link GregorianCalendar} into a {@link XMLGregorianCalendar}
   *
   * @param calendar
   * @return
   */
  public static XMLGregorianCalendar convertToXmlDate(final GregorianCalendar calendar) {
    final GregorianCalendar zuluDate = new GregorianCalendar();
    zuluDate.setTimeZone(TimeZone.getTimeZone("UTC"));
    zuluDate.setTimeInMillis(calendar.getTimeInMillis());

    final XMLGregorianCalendar xmlDate = XML_DATATYPE_FACTORY.newXMLGregorianCalendar(zuluDate);
    return xmlDate;
  }
Пример #15
0
 public List findMessagesBeforeTime(int time_period) throws DAOException {
   GregorianCalendar calendar = new GregorianCalendar();
   calendar.add(GregorianCalendar.MONTH, -time_period);
   long cutOffDate = calendar.getTimeInMillis();
   Timestamp time = new Timestamp(cutOffDate);
   Object[] param = {time};
   return super.find("get_all_before_time", param);
 }
Пример #16
0
 // -----------------------------------------------------------------------
 public void test_setInstant() {
   for (int i = -1100; i < 1100; i++) {
     Instant instant = Instant.ofEpochMilli(i);
     GregorianCalendar test = new GregorianCalendar();
     test.setInstant(instant);
     assertEquals(test.getTimeInMillis(), i);
   }
 }
Пример #17
0
 public static String format(Date paramDate, boolean paramBoolean, TimeZone paramTimeZone)
 {
   GregorianCalendar localGregorianCalendar = new GregorianCalendar(paramTimeZone, Locale.US);
   localGregorianCalendar.setTime(paramDate);
   int i = "yyyy-MM-ddThh:mm:ss".length();
   int j;
   int m;
   label56: StringBuilder localStringBuilder;
   char c;
   if (paramBoolean)
   {
     j = ".sss".length();
     int k = i + j;
     if (paramTimeZone.getRawOffset() != 0)
       break label335;
     m = "Z".length();
     localStringBuilder = new StringBuilder(k + m);
     padInt(localStringBuilder, localGregorianCalendar.get(1), "yyyy".length());
     localStringBuilder.append('-');
     padInt(localStringBuilder, 1 + localGregorianCalendar.get(2), "MM".length());
     localStringBuilder.append('-');
     padInt(localStringBuilder, localGregorianCalendar.get(5), "dd".length());
     localStringBuilder.append('T');
     padInt(localStringBuilder, localGregorianCalendar.get(11), "hh".length());
     localStringBuilder.append(':');
     padInt(localStringBuilder, localGregorianCalendar.get(12), "mm".length());
     localStringBuilder.append(':');
     padInt(localStringBuilder, localGregorianCalendar.get(13), "ss".length());
     if (paramBoolean)
     {
       localStringBuilder.append('.');
       padInt(localStringBuilder, localGregorianCalendar.get(14), "sss".length());
     }
     int n = paramTimeZone.getOffset(localGregorianCalendar.getTimeInMillis());
     if (n == 0)
       break label352;
     int i1 = Math.abs(n / 60000 / 60);
     int i2 = Math.abs(n / 60000 % 60);
     if (n >= 0)
       break label345;
     c = '-';
     label283: localStringBuilder.append(c);
     padInt(localStringBuilder, i1, "hh".length());
     localStringBuilder.append(':');
     padInt(localStringBuilder, i2, "mm".length());
   }
   while (true)
   {
     return localStringBuilder.toString();
     j = 0;
     break;
     label335: m = "+hh:mm".length();
     break label56;
     label345: c = '+';
     break label283;
     label352: localStringBuilder.append('Z');
   }
 }
Пример #18
0
  public void InsertInCalendar(String title, String description, String place, Date date) {
    Intent calIntent = new Intent(Intent.ACTION_INSERT);
    calIntent.setType("vnd.android.cursor.item/event");
    calIntent.setData(CalendarContract.Events.CONTENT_URI);
    calIntent.putExtra(CalendarContract.Events.TITLE, title);
    calIntent.putExtra(CalendarContract.Events.EVENT_LOCATION, place);
    calIntent.putExtra(CalendarContract.Events.DESCRIPTION, description);

    GregorianCalendar calDate = new GregorianCalendar();
    calDate.setTime(date);

    calIntent.putExtra(CalendarContract.EXTRA_EVENT_ALL_DAY, true);
    calIntent.putExtra(CalendarContract.EXTRA_EVENT_BEGIN_TIME, calDate.getTimeInMillis());

    calIntent.putExtra(CalendarContract.EXTRA_EVENT_END_TIME, calDate.getTimeInMillis());

    startActivity(calIntent);
  }
  public void onDateSet(DatePicker view, int year, int month, int day) {

    Button dueDateText = (Button) findViewById(R.id.btCalendar);
    dueDateText.setText((month + 1) + "/" + day + "/" + year);
    GregorianCalendar gc = new GregorianCalendar();
    gc.clear();
    gc.set(year, month, day);
    dueDate = gc.getTimeInMillis();
  }
Пример #20
0
  @Test
  public void testGenerateServiceInfo() {
    TestHelper.INSTANCE.initialize();
    GregorianCalendar start = new GregorianCalendar(2010, 0, 1, 15, 0, 0);
    GregorianCalendar end = new GregorianCalendar(2010, 2, 3, 15, 0, 0);
    RecurrenceType r = new RecurrenceType(RecurrenceFreq.FREQ_DAILY, 1, 0, null);

    Schedule s =
        new Schedule(
            ACTIVATION_TYPE.RESERVATION_AUTOMATIC,
            "unknown",
            "unAssigned",
            State.SCHEDULE.EXECUTION_PENDING,
            start.getTimeInMillis(),
            Long.valueOf(end.getTimeInMillis()),
            60 * 60 * 1000,
            new UserType(null, null, null, null, null, null, null),
            null,
            true,
            r,
            null);

    log.debug("Created serviceInfo from " + s.toDebugString());
    try {
      long[][] res = LpcpAdminManager.INSTANCE.generateServiceInfo(s);
      assertEquals(62, res.length);

      for (long[] r1 : res) {
        log.debug(
            "Schedule starts "
                + r1[0]
                + "("
                + new Date(r1[0]).toString()
                + ") and ends at "
                + r1[1]
                + "("
                + new Date(r1[1]).toString()
                + ")");
      }
    } catch (NrbException e) {
      log.error("Error: ", e);
      fail("See previous stack trace");
    }
  }
Пример #21
0
  public void updatePastJobs() {
    GregorianCalendar currentDate = new GregorianCalendar();
    long currentTime = currentDate.getTimeInMillis() + 2670040009l;

    for (Job job : myJobList.getJobList()) {
      if (currentTime > job.getStartDate().getTimeInMillis()) {
        job.setInPast(true);
      }
    }
  }
  public static int fechasDiferenciaEnDias(String fechaFinal, String fechaActual) {
    int yearAc = Integer.parseInt(fechaActual.substring(0, 4));
    int monthAc = Integer.parseInt(fechaActual.substring(5, 7)) - 1;
    int dayAc = Integer.parseInt(fechaActual.substring(8));
    int yearVenc = Integer.parseInt(fechaFinal.substring(0, 4));
    int monthVenc = Integer.parseInt(fechaFinal.substring(5, 7)) - 1;
    int dayVenc = Integer.parseInt(fechaFinal.substring(8));

    GregorianCalendar t1 = new GregorianCalendar(yearAc, monthAc, dayAc);
    GregorianCalendar t2 = new GregorianCalendar(yearVenc, monthVenc, dayVenc);

    // int dias = t1.get(Calendar.DAY_OF_YEAR) -
    // t2.get(Calendar.DAY_OF_YEAR);

    long dif = t1.getTimeInMillis() - t2.getTimeInMillis();
    int dias = (int) (dif / (1000 * 60 * 60 * 24));

    return dias;
  }
Пример #23
0
  public void scrollTo(GregorianCalendar date) {
    int left = painter.millisecondsToPixels(date.getTimeInMillis()) - 30;
    //		left = painter.toPixels( date.getTimeInMillis() );
    int top = 0;
    Rectangle r = new Rectangle(left, top, events.getWidth(), 10);
    log("ScrollTo: " + date.getTime() + " " + r.toString());
    //		scrollRectToVisible( r );

    events.scrollRectToVisible(r);
  }
Пример #24
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);
  }
  public RideValidator(int year, int month, int day, int hourOfDay, int minute) {

    calendar =
        new GregorianCalendar(
            currentYear, currentMonth, currentDay, currentHourOfDay, currentMinute, 0);

    currentTimeInMillis = calendar.getTimeInMillis();

    calendar = new GregorianCalendar(year, month, day, hourOfDay, minute, 0);
  }
Пример #26
0
  @Override
  public Dialog onCreateDialog(Bundle savedInstanceState) {
    //

    GregorianCalendar GC = (GregorianCalendar) GregorianCalendar.getInstance();
    GC.add(GregorianCalendar.DAY_OF_MONTH, 1);
    int year = GC.get(Calendar.YEAR);
    int month = GC.get(Calendar.MONTH);
    int day = GC.get(Calendar.DAY_OF_MONTH);
    long min = GC.getTimeInMillis();
    GC.add(GregorianCalendar.YEAR, 1);
    long max = GC.getTimeInMillis();
    DatePickerDialog d = new DatePickerDialog(getActivity(), this, year, month, day);
    DatePicker dp = d.getDatePicker();
    dp.setMinDate(min);
    dp.setMaxDate(max);
    return d;
    // Create a new instance of DatePickerDialog and return it

  }
 private long getMidnightMs() {
   GregorianCalendar midnight = new GregorianCalendar();
   midnight.set(
       midnight.get(Calendar.YEAR),
       midnight.get(Calendar.MONTH),
       midnight.get(Calendar.DATE),
       23,
       59,
       59);
   return midnight.getTimeInMillis();
 }
 @Test
 public void test2() throws Throwable {
   LavaLogger lavaLogger0 = new LavaLogger();
   Locale locale0 = Locale.CANADA_FRENCH;
   GregorianCalendar gregorianCalendar0 = (GregorianCalendar) Calendar.getInstance(locale0);
   lavaLogger0.error((Calendar) gregorianCalendar0, "#f)4uJB1guS3Qc~*]V");
   assertEquals(1372799549460L, gregorianCalendar0.getTimeInMillis());
   assertEquals(
       "java.util.GregorianCalendar[time=1372799549460,areFieldsSet=true,areAllFieldsSet=true,lenient=true,zone=sun.util.calendar.ZoneInfo[id=\"Europe/Belfast\",offset=0,dstSavings=3600000,useDaylight=true,transitions=242,lastRule=java.util.SimpleTimeZone[id=Europe/Belfast,offset=0,dstSavings=3600000,useDaylight=true,startYear=0,startMode=2,startMonth=2,startDay=-1,startDayOfWeek=1,startTime=3600000,startTimeMode=2,endMode=2,endMonth=9,endDay=-1,endDayOfWeek=1,endTime=3600000,endTimeMode=2]],firstDayOfWeek=1,minimalDaysInFirstWeek=1,ERA=1,YEAR=2013,MONTH=6,WEEK_OF_YEAR=27,WEEK_OF_MONTH=1,DAY_OF_MONTH=2,DAY_OF_YEAR=183,DAY_OF_WEEK=3,DAY_OF_WEEK_IN_MONTH=1,AM_PM=1,HOUR=10,HOUR_OF_DAY=22,MINUTE=12,SECOND=29,MILLISECOND=460,ZONE_OFFSET=0,DST_OFFSET=3600000]",
       gregorianCalendar0.toString());
 }
Пример #29
0
 /**
  * @param years [1960-20xx]
  * @param months [1-12]
  * @param days [1-31]
  * @param hours [0-23]
  * @param minutes [0-59]
  * @param seconds [0-59]
  * @param millis [0-99]
  * @param micros [0-99]
  * @param nanos [0-99]
  * @return Timestamp
  */
 public static TimestampValue from(
     final int years,
     final int months,
     final int days,
     final int hours,
     final int minutes,
     final int seconds,
     final int millis,
     final int micros,
     final int nanos) {
   final GregorianCalendar cal =
       new GregorianCalendar(years, months - 1, days, hours, minutes, seconds);
   final long offset = cal.getTimeZone().getOffset(cal.getTimeInMillis());
   final Timestamp timestamp = new Timestamp(cal.getTimeInMillis() + offset);
   timestamp.setNanos(
       (millis * TimestampValue.MILLIS_TO_NANOS)
           + (micros * TimestampValue.MICROS_TO_NANOS)
           + nanos);
   return TimestampValue.from(timestamp);
 }
Пример #30
0
  public void deleteOrReschedule(final Context context) {
    if (isLocationRepeat()) {
      return;
    }

    if (repeats == 0 || time == null) {
      delete(context);
    } else {
      // Need to set the correct time, but using today as the date
      // Because no sense in setting reminders in the past
      GregorianCalendar gcOrgTime = new GregorianCalendar();
      gcOrgTime.setTimeInMillis(time);
      // Use today's date
      GregorianCalendar gc = new GregorianCalendar();
      final long now = gc.getTimeInMillis();
      // With original time
      gc.set(GregorianCalendar.HOUR_OF_DAY, gcOrgTime.get(GregorianCalendar.HOUR_OF_DAY));
      gc.set(GregorianCalendar.MINUTE, gcOrgTime.get(GregorianCalendar.MINUTE));
      // Save as base
      final long base = gc.getTimeInMillis();

      // Check today if the time is actually in the future
      final int start = now < base ? 0 : 1;
      final long oneDay = 24 * 60 * 60 * 1000;
      boolean done = false;
      for (int i = start; i <= 7; i++) {
        gc.setTimeInMillis(base + i * oneDay);

        if (repeatsOn(gc.get(GregorianCalendar.DAY_OF_WEEK))) {
          done = true;
          time = gc.getTimeInMillis();
          save(context);
          break;
        }
      }
      // Just in case of faulty repeat codes
      if (!done) {
        delete(context);
      }
    }
  }