@DwrPermission(admin = true)
  public ProcessResult getMaintenanceEvent(int id) {
    ProcessResult response = new ProcessResult();

    MaintenanceEventVO me;
    boolean activated = false;
    if (id == Common.NEW_ID) {
      DateTime dt = new DateTime();
      me = new MaintenanceEventVO();
      me.setXid(new MaintenanceEventDao().generateUniqueXid());
      me.setActiveYear(dt.getYear());
      me.setInactiveYear(dt.getYear());
      me.setActiveMonth(dt.getMonthOfYear());
      me.setInactiveMonth(dt.getMonthOfYear());
    } else {
      me = new MaintenanceEventDao().getMaintenanceEvent(id);

      MaintenanceEventRT rt = RTMDefinition.instance.getRunningMaintenanceEvent(me.getId());
      if (rt != null) activated = rt.isEventActive();
    }

    response.addData("me", me);
    response.addData("activated", activated);

    return response;
  }
Пример #2
0
 private DateTime ensureSameDate(
     DateTime date,
     int years,
     int monthsOfYear,
     int dayOfMonth,
     int hoursOfDay,
     int minutesOfHour,
     int secondsOfMinute,
     DateTimeZone timeZone) {
   if (date.getSecondOfMinute() != secondsOfMinute) {
     date = date.plusSeconds(secondsOfMinute - date.getSecondOfMinute());
   }
   if (date.getMinuteOfHour() != minutesOfHour) {
     date = date.plusMinutes(minutesOfHour - date.getMinuteOfHour());
   }
   if (date.getHourOfDay() != hoursOfDay) {
     date = date.plusHours(hoursOfDay - date.getHourOfDay());
   }
   if (date.getDayOfMonth() != dayOfMonth) {
     date = date.plusDays(dayOfMonth - date.getDayOfMonth());
   }
   if (date.getMonthOfYear() != monthsOfYear) {
     date = date.plusMonths(monthsOfYear - date.getMonthOfYear());
   }
   if (date.getYear() != years) {
     date = date.plusYears(years - date.getYear());
   }
   return date;
 }
  @Test
  @UseWithField(field = "boundaryDatesMode", valuesFrom = FROM_ENUM, value = "")
  @Templates("plain")
  public void testBoundaryDatesMode() {
    calendarAttributes.set(CalendarAttributes.boundaryDatesMode, boundaryDatesMode.value);
    DayPicker dayPicker = popupCalendar.openPopup().getDayPicker();
    MetamerPage.waitRequest(popupCalendar, WaitRequestType.XHR).setDateTime(firstOfNovember2012);
    PopupFooterControls footerControls = popupCalendar.openPopup().getFooterControls();
    HeaderControls headerControls = popupCalendar.openPopup().getHeaderControls();
    DateTime yearAndMonth;
    String firstOfNovember2012String = firstOfNovember2012.toString(dateTimeFormatter);
    switch (boundaryDatesMode) {
      case INACTIVE:
      case NULL:
        try {
          MetamerPage.waitRequest(dayPicker.getBoundaryDays().get(0), WaitRequestType.NONE)
              .select();
          fail("Item should not be selected.");
        } catch (TimeoutException ex) { // ok
        }
        // apply and check, that the date has not changed
        footerControls = popupCalendar.openPopup().getFooterControls();
        MetamerPage.waitRequest(footerControls, WaitRequestType.NONE).applyDate();
        assertEquals(popupCalendar.getInput().getStringValue(), firstOfNovember2012String);
        break;
      case SCROLL:
        // scroll to 28th of October 2012
        try {
          MetamerPage.waitRequest(dayPicker.getBoundaryDays().get(0), WaitRequestType.NONE)
              .select();
          fail("Item should not be selected.");
        } catch (TimeoutException ex) { // ok
        }
        yearAndMonth = headerControls.getYearAndMonth();
        assertEquals(yearAndMonth.getYear(), 2012);
        assertEquals(yearAndMonth.getMonthOfYear(), 10);
        // apply and check, that the date has not changed
        footerControls = popupCalendar.openPopup().getFooterControls();
        MetamerPage.waitRequest(footerControls, WaitRequestType.NONE).applyDate();
        assertEquals(popupCalendar.getInput().getStringValue(), firstOfNovember2012String);
        break;
      case SELECT:
        // select 28th of October 2012
        CalendarDay day = dayPicker.getBoundaryDays().get(0);
        MetamerPage.waitRequest(day.getDayElement(), WaitRequestType.NONE).click();
        yearAndMonth = headerControls.getYearAndMonth();
        assertEquals(yearAndMonth.getYear(), 2012);
        assertEquals(yearAndMonth.getMonthOfYear(), 10);

        MetamerPage.waitRequest(footerControls, WaitRequestType.XHR).applyDate();
        DateTime parsedDateTime =
            dateTimeFormatter.parseDateTime(popupCalendar.getInput().getStringValue());
        assertEquals(parsedDateTime.getYear(), 2012);
        assertEquals(parsedDateTime.getMonthOfYear(), 10);
        assertEquals(parsedDateTime.getDayOfMonth(), 28);
        break;
    }
  }
Пример #4
0
 public static boolean shouldShowSeasonsGreetings(final Context context) {
   DateTime now = DateTime.now();
   if (prefs(context).getInt(PREFS_SEASONS_GREETINGS, now.getYear() - 1) < now.getYear()
       && (now.getDayOfYear() >= 354 && now.getDayOfYear() <= 366)) {
     prefs(context).edit().putInt(PREFS_SEASONS_GREETINGS, now.getYear()).apply();
     return true;
   }
   return false;
 }
Пример #5
0
 private static DateTime parseDateNoTimeNoYear(String input, String dateFmt) {
   DateTime dateTime;
   int currentYear = current.getYear();
   try {
     DateTimeFormatter formatter = DateTimeFormat.forPattern(dateFmt);
     dateTime = formatter.parseDateTime(input.trim());
     dateTime = dateTime.plusYears(calculateYearDifference(currentYear, dateTime.getYear()));
   } catch (IllegalArgumentException e) {
     dateTime = null;
   }
   return dateTime;
 }
  private String buildURI(String product, DateTime start, DateTime end) {
    StringBuilder uri = new StringBuilder();
    DateTime actualstart = start;
    uri.append(YAHOO_URL);
    uri.append("?s=").append(product);
    uri.append("&a=").append(actualstart.getMonthOfYear() - 1);
    uri.append("&b=").append(actualstart.getDayOfMonth());
    uri.append("&c=").append(actualstart.getYear());
    uri.append("&d=").append(end.getMonthOfYear() - 1);
    uri.append("&e=").append(end.getDayOfMonth());
    uri.append("&f=").append(end.getYear());
    uri.append("&g=d");

    return uri.toString();
  }
Пример #7
0
  public DateTimeView(DateTime time) {
    super();
    this.time = time;
    Font f = new Font("Monospaced", Font.BOLD, 13);
    Color c = new Color(44, 68, 152);
    month = new JLabel(strMonth(time.getMonthOfYear()));
    month.setFont(f);
    month.setForeground(c);
    year = new JLabel("" + time.getYear());
    year.setFont(f);
    year.setForeground(c);
    day = new JLabel("" + time.getDayOfMonth());
    day.setFont(new Font("Calibri", Font.BOLD, 26));
    day.setForeground(new Color(126, 148, 227));
    t = new JLabel(formatTime(time.getHourOfDay(), time.getMinuteOfHour()));
    t.setFont(f);
    t.setForeground(c);

    JPanel topPanel = new JPanel();
    topPanel.setLayout(new FlowLayout());
    topPanel.add(month);
    topPanel.add(year);

    this.setLayout(new BoxLayout(this, BoxLayout.PAGE_AXIS));
    topPanel.setAlignmentX(Component.CENTER_ALIGNMENT);
    this.add(topPanel);
    this.add(Box.createVerticalStrut(3));
    day.setAlignmentX(Component.CENTER_ALIGNMENT);
    this.add(day);
    t.setAlignmentX(Component.CENTER_ALIGNMENT);
    this.add(Box.createVerticalStrut(3));
    this.add(t);
    this.setBorder(BorderFactory.createRaisedBevelBorder());
  }
  @Test
  @Templates("plain")
  public void testLocale() {
    String locale = "ru";
    calendarAttributes.set(CalendarAttributes.locale, locale);
    DayPicker dayPicker = popupCalendar.openPopup().getDayPicker();
    List<String> weekDayShortNames = dayPicker.getWeekDayShortNames();
    List<String> expectedShortNames = Arrays.asList("Вс", "Пн", "Вт", "Ср", "Чт", "Пт", "Сб");
    assertEquals(weekDayShortNames, expectedShortNames);

    setCurrentDateWithCalendarsTodayButtonAction.perform();
    DateTime parsedDateTime =
        dateTimeFormatter
            .withLocale(new Locale(locale))
            .parseDateTime(popupCalendar.getInput().getStringValue());

    assertEquals(
        parsedDateTime.getDayOfMonth(),
        todayMidday.getDayOfMonth(),
        "Input doesn't contain selected date.");
    assertEquals(
        parsedDateTime.getMonthOfYear(),
        todayMidday.getMonthOfYear(),
        "Input doesn't contain selected date.");
    assertEquals(
        parsedDateTime.getYear(), todayMidday.getYear(), "Input doesn't contain selected date.");
  }
Пример #9
0
  private String calculateDayPath(String name, DateTime base) {
    StringBuilder builder = new StringBuilder();

    builder.append(getWritePath());
    builder.append(File.separatorChar);
    builder.append(name);
    builder.append(File.separatorChar);
    builder.append(base.getYear());
    builder.append(File.separatorChar);
    builder.append(base.getMonthOfYear());
    builder.append(File.separatorChar);
    builder.append(base.getDayOfMonth());
    builder.append(File.separatorChar);

    String path = builder.toString();

    (new File(path)).mkdirs();

    builder.append(base.getHourOfDay());
    builder.append(".txt");

    path = builder.toString();

    return path;
  }
Пример #10
0
    @Specialization
    public RubyBasicObject timeDecompose(VirtualFrame frame, RubyTime time) {
      CompilerDirectives.transferToInterpreter();
      final DateTime dateTime = time.getDateTime();
      final int sec = dateTime.getSecondOfMinute();
      final int min = dateTime.getMinuteOfHour();
      final int hour = dateTime.getHourOfDay();
      final int day = dateTime.getDayOfMonth();
      final int month = dateTime.getMonthOfYear();
      final int year = dateTime.getYear();

      int wday = dateTime.getDayOfWeek();

      if (wday == 7) {
        wday = 0;
      }

      final int yday = dateTime.getDayOfYear();
      final boolean isdst = false;

      final String envTimeZoneString = readTimeZoneNode.executeRubyString(frame).toString();
      String zoneString = org.jruby.RubyTime.zoneHelper(envTimeZoneString, dateTime, false);
      Object zone;
      if (zoneString.matches(".*-\\d+")) {
        zone = nil();
      } else {
        zone = createString(zoneString);
      }

      final Object[] decomposed =
          new Object[] {sec, min, hour, day, month, year, wday, yday, isdst, zone};
      return createArray(decomposed, decomposed.length);
    }
Пример #11
0
 public String getLabelForStatement(final Statement statement) {
   DateTime date = new DateTime(statement.getStartDate());
   Calendar cal = Calendar.getInstance();
   cal.set(Calendar.MONTH, date.getMonthOfYear() - 1);
   String month = cal.getDisplayName(Calendar.MONTH, Calendar.SHORT, new Locale("nl"));
   return month + " " + date.getYear();
 }
Пример #12
0
  public RubyObject mdump() {
    RubyTime obj = this;
    DateTime dateTime = obj.dt.toDateTime(DateTimeZone.UTC);
    byte dumpValue[] = new byte[8];

    int pe =
        0x1 << 31
            | ((obj.gmt().isTrue()) ? 0x1 : 0x0) << 30
            | (dateTime.getYear() - 1900) << 14
            | (dateTime.getMonthOfYear() - 1) << 10
            | dateTime.getDayOfMonth() << 5
            | dateTime.getHourOfDay();
    int se =
        dateTime.getMinuteOfHour() << 26
            | dateTime.getSecondOfMinute() << 20
            | (dateTime.getMillisOfSecond() * 1000 + (int) usec); // dump usec, not msec

    for (int i = 0; i < 4; i++) {
      dumpValue[i] = (byte) (pe & 0xFF);
      pe >>>= 8;
    }
    for (int i = 4; i < 8; i++) {
      dumpValue[i] = (byte) (se & 0xFF);
      se >>>= 8;
    }
    return RubyString.newString(obj.getRuntime(), new ByteList(dumpValue));
  }
 public SUTime.Temporal apply(String text) {
   // TODO: TIMEZONE?
   DateTime dateTime = null;
   try {
     dateTime = formatter.parseDateTime(text);
   } catch (org.joda.time.IllegalFieldValueException e) {
     logger.warning(
         "WARNING: Invalid temporal \""
             + text
             + "\" ("
             + e.getMessage()
             + "). Skipping and continuing...");
     return null;
   }
   assert (dateTime != null);
   if (hasDate && hasTime) {
     return new SUTime.GroundedTime(dateTime);
     //        return new SUTime.IsoDateTime( new SUTime.IsoTime(dateTime.getHourOfDay(),
     // dateTime.getMinuteOfHour(), dateTime.getSecondOfMinute());
     //        Date d = new SUTime.IsoDate(dateTime.getYear(), dateTime.getMonthOfYear(),
     // dateTime.getDayOfMonth()) );
   } else if (hasTime) {
     // TODO: Millisecs?
     return new SUTime.IsoTime(
         dateTime.getHourOfDay(), dateTime.getMinuteOfHour(), dateTime.getSecondOfMinute());
   } else if (hasDate) {
     return new SUTime.IsoDate(
         dateTime.getYear(), dateTime.getMonthOfYear(), dateTime.getDayOfMonth());
   } else {
     return null;
   }
 }
Пример #14
0
 public void setDateTime(DateTime time) {
   month.setText(strMonth(time.getMonthOfYear()));
   year.setText("" + time.getYear());
   day.setText("" + time.getDayOfMonth());
   day.setFont(new Font("Calibri", Font.BOLD, 22));
   t.setText(formatTime(time.getHourOfDay(), time.getMinuteOfHour()));
 }
  private void printStat(LiveStatistics ls) {
    long ms = ls.getTimeperiod() * 15000;
    DateTime time = new DateTime(ms);

    StringBuilder sb = new StringBuilder();
    sb.append(time.getDayOfMonth())
        .append(".")
        .append(time.getMonthOfYear())
        .append(".")
        .append(time.getYear());
    sb.append(" ")
        .append(time.getHourOfDay())
        .append(":")
        .append(time.getMinuteOfHour())
        .append(":")
        .append(time.getSecondOfMinute());

    System.out.println(
        ls.getTimeperiod()
            + ";"
            + ls.getAccountName()
            + "; date: "
            + sb.toString()
            + " value: "
            + ls.getValue()
            + " unitType: "
            + ls.getUnitType()
            + " valueType: "
            + ls.getValueType());
  }
Пример #16
0
  @Test
  @Use(field = "boundaryDatesMode", enumeration = true)
  public void testBoundaryDatesMode() {
    calendarAttributes.set(CalendarAttributes.boundaryDatesMode, boundaryDatesMode.value);
    DayPicker proxiedDayPicker = calendar.openPopup().getProxiedDayPicker();
    MetamerPage.waitRequest(calendar, WaitRequestType.XHR).setDateTime(firstOfNovember2012);
    PopupFooterControls proxiedFooterControls = calendar.openPopup().getProxiedFooterControls();
    HeaderControls proxiedHeaderControls = calendar.openPopup().getProxiedHeaderControls();
    DateTime yearAndMonth;
    String firstOfNovember2012String = firstOfNovember2012.toString(dateTimeFormatter);
    switch (boundaryDatesMode) {
      case INACTIVE:
      case NULL:
        MetamerPage.waitRequest(proxiedDayPicker.getBoundaryDays().get(0), WaitRequestType.NONE)
            .select();
        // apply and check, that the date has not changed
        MetamerPage.waitRequest(proxiedFooterControls, WaitRequestType.NONE).applyDate();
        assertEquals(calendar.getInputValue(), firstOfNovember2012String);
        break;
      case SCROLL:
        // scroll to 28th of October 2012
        MetamerPage.waitRequest(proxiedDayPicker.getBoundaryDays().get(0), WaitRequestType.NONE)
            .select();
        yearAndMonth = proxiedHeaderControls.getYearAndMonth();
        assertEquals(yearAndMonth.getYear(), 2012);
        assertEquals(yearAndMonth.getMonthOfYear(), 10);
        // apply and check, that the date has not changed
        MetamerPage.waitRequest(proxiedFooterControls, WaitRequestType.NONE).applyDate();
        assertEquals(calendar.getInputValue(), firstOfNovember2012String);
        break;
      case SELECT:
        // select 28th of October 2012
        MetamerPage.waitRequest(proxiedDayPicker.getBoundaryDays().get(0), WaitRequestType.NONE)
            .select();
        yearAndMonth = proxiedHeaderControls.getYearAndMonth();
        assertEquals(yearAndMonth.getYear(), 2012);
        assertEquals(yearAndMonth.getMonthOfYear(), 10);

        MetamerPage.waitRequest(proxiedFooterControls, WaitRequestType.XHR).applyDate();
        DateTime parsedDateTime = dateTimeFormatter.parseDateTime(calendar.getInputValue());
        assertEquals(parsedDateTime.getYear(), 2012);
        assertEquals(parsedDateTime.getMonthOfYear(), 10);
        assertEquals(parsedDateTime.getDayOfMonth(), 28);
        break;
    }
  }
Пример #17
0
 public static String getFullDate(long createdTime) {
   DateTime dateTime = new DateTime(createdTime * 1000);
   StringBuilder sb = new StringBuilder("");
   sb.append(getYear(dateTime.getYear()));
   sb.append(getMonth(dateTime.getMonthOfYear()));
   sb.append(getDay(dateTime.getDayOfMonth()));
   return sb.toString();
 }
  private int getYear(Date d) {
    if (d != null) {
      DateTime date = new DateTime(d);
      return date.getYear();
    }

    return 0;
  }
 private DateTime truncateToSeconds(DateTime dateTime) {
   return new DateTime(
       dateTime.getYear(),
       dateTime.getMonthOfYear(),
       dateTime.getDayOfMonth(),
       dateTime.getHourOfDay(),
       dateTime.getMinuteOfHour(),
       dateTime.getSecondOfMinute());
 }
Пример #20
0
  @Atomic
  public static void run(
      List<VigilantWrapper> vigilants,
      WrittenEvaluation writtenEvaluation,
      VigilantGroup group,
      ExamCoordinator coordinator,
      String emailMessage) {
    group.convokeVigilants(vigilants, writtenEvaluation);

    Set<Person> recievers = new HashSet<Person>();
    Set<String> bccs = new HashSet<String>();

    if (emailMessage.length() != 0) {
      Person person = coordinator.getPerson();
      for (VigilantWrapper vigilant : vigilants) {
        recievers.add(vigilant.getPerson());
      }

      String groupEmail = group.getContactEmail();
      String replyTo;

      recievers.addAll(writtenEvaluation.getTeachers());

      if (groupEmail != null) {
        bccs.add(groupEmail);
        replyTo = groupEmail;
      } else {
        replyTo = person.getEmail();
      }

      DateTime date = writtenEvaluation.getBeginningDateTime();
      String beginDateString =
          date.getDayOfMonth() + "/" + date.getMonthOfYear() + "/" + date.getYear();

      String subject =
          BundleUtil.getString(
              "resources.VigilancyResources",
              "email.convoke.subject",
              new String[] {
                group.getEmailSubjectPrefix(),
                writtenEvaluation.getName(),
                group.getName(),
                beginDateString
              });

      new Message(
          PersonSender.newInstance(person),
          new ConcreteReplyTo(replyTo).asCollection(),
          new Recipient(UserGroup.of(Person.convertToUsers(recievers))).asCollection(),
          Collections.EMPTY_LIST,
          Collections.EMPTY_LIST,
          subject,
          emailMessage,
          bccs);
    }
  }
Пример #21
0
 /**
  * Creates {@code DateTime} instance with time stored in this object.
  *
  * @param dateTime the {@code DateTime} to be used as base for the new {@code DateTime}
  * @return the {@code DateTime} with stored time
  */
 public DateTime toDateTime(DateTime dateTime) {
   return new DateTime(
       dateTime.getYear(),
       dateTime.getMonthOfYear(),
       dateTime.getDayOfMonth(),
       hour,
       minute,
       0,
       0);
 }
  private ArrayList<AbstractFacet> extractStepFacets(final ApiData apiData) {
    ArrayList<AbstractFacet> facets = new ArrayList<AbstractFacet>();
    /* burnJson is a JSONArray that contains a seperate JSONArray and calorie counts for each day
     */
    JSONObject bodymediaResponse = JSONObject.fromObject(apiData.json);
    JSONArray daysArray = bodymediaResponse.getJSONArray("days");
    if (bodymediaResponse.has("lastSync")) {
      DateTime d =
          form.parseDateTime(bodymediaResponse.getJSONObject("lastSync").getString("dateTime"));

      // Get timezone map from UpdateInfo context
      TimezoneMap tzMap = (TimezoneMap) updateInfo.getContext("tzMap");

      // Insert lastSync into the updateInfo context so it's accessible to the updater
      updateInfo.setContext("lastSync", d);

      for (Object o : daysArray) {
        if (o instanceof JSONObject) {
          JSONObject day = (JSONObject) o;
          BodymediaStepsFacet steps = new BodymediaStepsFacet(apiData.updateInfo.apiKey.getId());
          super.extractCommonFacetData(steps, apiData);
          steps.totalSteps = day.getInt("totalSteps");
          steps.date = day.getString("date");
          steps.json = day.getString("hours");
          steps.lastSync = d.getMillis();

          DateTime date = formatter.parseDateTime(day.getString("date"));
          steps.date = dateFormatter.print(date.getMillis());
          if (tzMap != null) {
            // Create a LocalDate object which just captures the date without any
            // timezone assumptions
            LocalDate ld =
                new LocalDate(date.getYear(), date.getMonthOfYear(), date.getDayOfMonth());
            // Use tzMap to convert date into a datetime with timezone information
            DateTime realDateStart = tzMap.getStartOfDate(ld);
            // Set the start and end times for the facet.  The start time is the leading midnight
            // of date according to BodyMedia's idea of what timezone you were in then.
            // Need to figure out what end should be...
            steps.start = realDateStart.getMillis();
            int minutesLength = 1440;
            steps.end = steps.start + DateTimeConstants.MILLIS_PER_MINUTE * minutesLength;
          } else {
            TimeZone timeZone =
                metadataService.getTimeZone(apiData.updateInfo.getGuestId(), date.getMillis());
            long fromMidnight = TimeUtils.fromMidnight(date.getMillis(), timeZone);
            long toMidnight = TimeUtils.toMidnight(date.getMillis(), timeZone);
            steps.start = fromMidnight;
            steps.end = toMidnight;
          }
          facets.add(steps);
        } else throw new JSONException("Days array is not a proper JSONObject");
      }
    }
    return facets;
  }
Пример #23
0
 @Test
 @Ignore
 public void testRead() {
   Patient patient = entityManager.find(Patient.class, 3);
   assertTrue(patient.getAppointments().size() > 0);
   DateTime st = patient.getAppointments().iterator().next().getStart();
   assertEquals(2013, st.getYear());
   assertEquals(2, st.getMonthOfYear());
   assertEquals(18, st.getDayOfMonth());
   assertEquals(8, st.getHourOfDay());
 }
    @Override
    public Dialog onCreateDialog(Bundle savedInstanceState) {
      // Use the current date as the default date in the picker
      DateTime date = new DateTime();
      int year = date.getYear();
      int month = date.getMonthOfYear();
      int day = date.getDayOfMonth();

      // Create a new instance of DatePickerDialog and return it
      return new DatePickerDialog(getActivity(), this, year, month, day);
    }
  private boolean validate() {
    if (creator.getInvite() == null) {
      return false;
    } else {
      if (creator.getInvite().date == 0l) {
        String message = "";
        if (creator.getInvite().time == 0l || TextUtils.isEmpty(inviteTitle.getText())) {
          message = getString(R.string.all_fields_error);
        } else {
          message = String.format(getString(R.string.one_field_error), "date");
        }
        Snackbar.make(inviteDetailsCard, message, Snackbar.LENGTH_LONG).show();
        return false;
      }
      if (creator.getInvite().time == 0l) {
        String message = "";
        if (creator.getInvite().date == 0l || TextUtils.isEmpty(inviteTitle.getText())) {
          message = getString(R.string.all_fields_error);
        } else {
          message = String.format(getString(R.string.one_field_error), "time");
        }
        Snackbar.make(inviteDetailsCard, message, Snackbar.LENGTH_LONG).show();
        return false;
      }
      if (TextUtils.isEmpty(inviteTitle.getText())) {
        String message = "";
        if (creator.getInvite().time == 0l || creator.getInvite().date == 0l) {
          message = getString(R.string.all_fields_error);
        } else {
          message = String.format(getString(R.string.one_field_error), "title");
        }
        Snackbar.make(inviteDetailsCard, message, Snackbar.LENGTH_LONG).show();
        return false;
      }

      DateTime time = new DateTime().withMillis(creator.getInvite().time);
      DateTime date = new DateTime().withMillis(creator.getInvite().date);
      DateTime when =
          new DateTime()
              .withYear(date.getYear())
              .withMonthOfYear(date.getMonthOfYear())
              .withDayOfMonth(date.getDayOfMonth())
              .withHourOfDay(time.getHourOfDay())
              .withMinuteOfHour(time.getMinuteOfHour());

      if (when.isBeforeNow()) {
        Snackbar.make(inviteDetailsCard, getString(R.string.wrong_datetime), Snackbar.LENGTH_LONG)
            .show();
        return false;
      }
    }
    return true;
  }
Пример #26
0
  private Element createBrandElem(
      Brand brand,
      DateTime originalPublicationDate,
      DateTime brandEndDate,
      String lastModified,
      LakeviewContentGroup contentGroup,
      int addedSeasons) {

    Element element = createElement("TVSeries", LAKEVIEW);
    addIdElements(element, brandId(brand), providerMediaId(brand));
    addTitleElements(
        element, Strings.isNullOrEmpty(brand.getTitle()) ? "EMPTY BRAND TITLE" : brand.getTitle());

    appendCommonElements(
        element,
        brand,
        originalPublicationDate,
        lastModified,
        brandAtomUri(findTagAlias(brand)),
        brand.getGenres(),
        null);
    if (addedSeasons > 0) {
      element.appendChild(
          stringElement("TotalNumberOfSeasons", LAKEVIEW, String.valueOf(addedSeasons)));
    }

    element.appendChild(
        stringElement(
            "TotalNumberOfEpisodes", LAKEVIEW, String.valueOf(countEpisodes(contentGroup))));

    if (brand.getPresentationChannel() != null
        && channelResolver.fromKey(brand.getPresentationChannel()).hasValue()) {
      element.appendChild(
          stringElement(
              "Network",
              LAKEVIEW,
              channelResolver.fromKey(brand.getPresentationChannel()).requireValue().getTitle()));
    } else {
      List<Broadcast> broadcasts = extractBroadcasts(contentGroup.episodes());
      if (!broadcasts.isEmpty()) {
        element.appendChild(stringElement("Network", LAKEVIEW, extractNetwork(broadcasts)));
      } else {
        return null;
      }
    }

    if (brandEndDate != null) {
      element.appendChild(
          stringElement("EndYear", LAKEVIEW, String.valueOf(brandEndDate.getYear())));
    }

    return element;
  }
Пример #27
0
 public void testCreateNewUtcDate() {
   DateTime utc = now.toDateTime(DateTimeZone.UTC);
   Date actual =
       newDateUtc(
           utc.getYear(),
           utc.getMonthOfYear(),
           utc.getDayOfMonth(),
           utc.getHourOfDay(),
           utc.getMinuteOfHour(),
           utc.getSecondOfMinute());
   assertEquals(utc.getMillis(), actual.getTime());
 }
Пример #28
0
 private static LocalDateTime parseJavaLocalDateTimeUI(String str) {
   // First parse to Joda DateTime for timezone calculation
   DateTime dateTime = DTF.parseDateTime(str);
   // Then create LocalDateTime from Joda DateTime and return it
   return LocalDateTime.of(
       dateTime.getYear(),
       dateTime.getMonthOfYear(),
       dateTime.getDayOfMonth(),
       dateTime.getHourOfDay(),
       dateTime.getMinuteOfHour(),
       dateTime.getSecondOfMinute());
 }
Пример #29
0
 /**
  * Parse one of Pepco's times. Normally, this would be as easy as just calling
  * pepcoDateFormatter.parseDateTime, but there's some special case stuff that needs to happen on
  * the first scrape of a new year. Since Pepco doesn't include the year, on the first day of the
  * year, we might accidentally assume we are scraping data from January. So we have to do some
  * stuff to adjust for that. See the comment inside this method for what exactly we do.
  *
  * @param date The date to parse.
  * @param now What time it is right now.
  */
 public static DateTime parsePepcoDateTime(final String date, final DateTime now) {
   final DateTime ret = PEPCO_DATE_FORMATTER.parseDateTime(date);
   /*
    * Check whether it is January and we are parsing a date in December.
    *
    * Pepco's dates don't include the year. So at the turn of the year (Jan
    * 1), we'll probably read something like "Dec 31 12:58 PM". It is very
    * unlikely that this actually represents December 31 of this year. More
    * likely, this is December 31 of last year (either that or some poor
    * group of customers is going to have to wait more than a year for
    * their power to get fixed).
    */
   if (now.getMonthOfYear() == 1
       && now.getDayOfMonth() == 1
       && ret.getMonthOfYear() == 12
       && ret.getDayOfMonth() == 31) {
     return ret.withYear(now.getYear() - 1);
   } else {
     return ret.withYear(now.getYear());
   }
 }
  /**
   * Creates FeedItems with the values to use in ad customizations for each ad group in <code>
   * adGroupIds</code>.
   */
  private static void createCustomizerFeedItems(
      AdWordsServices adWordsServices,
      AdWordsSession session,
      List<Long> adGroupIds,
      AdCustomizerFeed adCustomizerFeed)
      throws Exception {
    // Get the FeedItemService.
    FeedItemServiceInterface feedItemService =
        adWordsServices.get(session, FeedItemServiceInterface.class);

    List<FeedItemOperation> feedItemOperations = Lists.newArrayList();

    DateTime now = new DateTime();

    DateTime marsDate = new DateTime(now.getYear(), now.getMonthOfYear(), 1, 0, 0);
    feedItemOperations.add(
        createFeedItemAddOperation(
            "Mars",
            "$1234.56",
            marsDate.toString("yyyyMMdd HHmmss"),
            adGroupIds.get(0),
            adCustomizerFeed));

    DateTime venusDate = new DateTime(now.getYear(), now.getMonthOfYear(), 15, 0, 0);
    feedItemOperations.add(
        createFeedItemAddOperation(
            "Venus",
            "$1450.00",
            venusDate.toString("yyyyMMdd HHmmss"),
            adGroupIds.get(1),
            adCustomizerFeed));

    FeedItemReturnValue feedItemReturnValue =
        feedItemService.mutate(
            feedItemOperations.toArray(new FeedItemOperation[feedItemOperations.size()]));

    for (FeedItem addedFeedItem : feedItemReturnValue.getValue()) {
      System.out.printf("Added feed item with ID %d.%n", addedFeedItem.getFeedItemId());
    }
  }