Java Code Examples for org.joda.time.DateTime#getMonthOfYear()

The following examples show how to use org.joda.time.DateTime#getMonthOfYear() . These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
private static DateTime fixEndDate(DateTime endDate) {
    if(endDate==null) {
        return null;
    }
    int month = endDate.getMonthOfYear();
    if (month <= 3) {
        return endDate.withMonthOfYear(DateTimeConstants.MARCH).withDayOfMonth(
                endDate.dayOfMonth().getMaximumValue());
    } else if (month <= 6) {
        return endDate.withMonthOfYear(DateTimeConstants.JUNE).withDayOfMonth(
                endDate.dayOfMonth().getMaximumValue());
    } else if (month <= 9) {
        return endDate.withMonthOfYear(DateTimeConstants.SEPTEMBER).withDayOfMonth(
                endDate.dayOfMonth().getMaximumValue());
    } else if (month <= 12) {
        endDate = endDate.withYear(endDate.getYear()).withMonthOfYear(
                DateTimeConstants.JANUARY);
        return endDate.withDayOfYear(endDate.dayOfYear().getMaximumValue());
    }
    return endDate;
}
 
Example 2
private static DateTime fixStartDate(DateTime startDate) {
    if(startDate==null) {
        return null;
    }
    int month = startDate.getMonthOfYear();
    if (month <= 3) {
        return startDate.withMonthOfYear(DateTimeConstants.JANUARY).withDayOfMonth(1);
    } else if (month <= 6) {
        return startDate.withMonthOfYear(DateTimeConstants.APRIL).withDayOfMonth(1);
    } else if (month <= 9) {
        return startDate.withMonthOfYear(DateTimeConstants.JULY).withDayOfMonth(1);
    } else if (month <= 12) {
        return startDate.withMonthOfYear(DateTimeConstants.OCTOBER).withDayOfMonth(1);
    }
    return startDate;
}
 
Example 3
Source Project: chipster   File: BackupRotation.java    License: MIT License 6 votes vote down vote up
/**
 * Remove first map item (i.e. keep the file itself) of each month.
 * 
 * @param filesToDelete
 */
private void removeFirstOfEachMonth(TreeMap<DateTime, File> filesToDelete) {
	
	HashSet<DateTime> months = new HashSet<>();
	
	Iterator<DateTime> filesIter = filesToDelete.keySet().iterator();
	
	while (filesIter.hasNext()) {
		DateTime fileDate = filesIter.next();
		DateTime month = new DateTime(fileDate.getYear(), fileDate.getMonthOfYear(), 1, 0, 0);
		
		if (!months.contains(month)) {
			filesIter.remove();
			months.add(month);
		}
	}
}
 
Example 4
public PutTherapeuticLinkResponse mapXMLToPutTherapeuticLinkResponse(String xml) throws TechnicalConnectorException {
   be.fgov.ehealth.hubservices.core.v2.PutTherapeuticLinkResponse jaxbResponse = (be.fgov.ehealth.hubservices.core.v2.PutTherapeuticLinkResponse)this.generateJAXB(xml, be.fgov.ehealth.hubservices.core.v2.PutTherapeuticLinkResponse.class);
   ResponseType jaxbResponseType = jaxbResponse.getResponse();
   DateTime date = jaxbResponseType.getDate();
   DateTime time = jaxbResponseType.getTime();
   DateTime dateTime = new DateTime(date.getYear(), date.getMonthOfYear(), date.getDayOfMonth(), time.getHourOfDay(), time.getMinuteOfHour(), time.getSecondOfMinute(), time.getMillisOfSecond(), DateTimeZone.getDefault());
   PutTherapeuticLinkResponse response = new PutTherapeuticLinkResponse(dateTime, this.mapAuthor(jaxbResponseType.getAuthor()), jaxbResponseType.getId().getValue(), this.mapOriginalPutTherapeuticLinkRequest(jaxbResponseType.getRequest()), this.mapAcknowledge(jaxbResponse.getAcknowledge()));
   LOG.info("Output request object :" + response.toString());
   return response;
}
 
Example 5
public String format(Date date) {
    DateTime dt = new DateTime(date);
    int month = dt.getMonthOfYear();
    int dayOfMonth = dt.getDayOfMonth();
    int year = dt.getYear();
    return format(year, month, dayOfMonth);
}
 
Example 6
public HasTherapeuticLinkResponse mapXMLToHasTherapeuticLinkResponse(String xml) throws TechnicalConnectorException {
   be.fgov.ehealth.hubservices.core.v2.HasTherapeuticLinkResponse jaxbResponse = (be.fgov.ehealth.hubservices.core.v2.HasTherapeuticLinkResponse)this.generateJAXB(xml, be.fgov.ehealth.hubservices.core.v2.HasTherapeuticLinkResponse.class);
   ResponseType jaxbResponseType = jaxbResponse.getResponse();
   DateTime date = jaxbResponseType.getDate();
   DateTime time = jaxbResponseType.getTime();
   DateTime dateTime = new DateTime(date.getYear(), date.getMonthOfYear(), date.getDayOfMonth(), time.getHourOfDay(), time.getMinuteOfHour(), time.getSecondOfMinute(), time.getMillisOfSecond());
   HasTherapeuticLinkResponse response = new HasTherapeuticLinkResponse(dateTime, this.mapAuthor(jaxbResponseType.getAuthor()), jaxbResponseType.getId().getValue(), this.mapOriginalHasTherapeuticLinkRequest(jaxbResponseType.getRequest()), this.mapAcknowledge(jaxbResponse.getAcknowledge()));
   LOG.info("Output request object :" + response.toString());
   return response;
}
 
Example 7
public static DateTime determineSunRiseTimes(DateTime StartTime, double latitude, double longitude,
		String timeZoneId) {
	// Because giving a date with a specific hour could result into getting the
	// sunrise of the previous day,
	// we adjust the date to the beginning of the day
	DateTime beginningOfDay = new DateTime(StartTime.getYear(), StartTime.getMonthOfYear(),
			StartTime.getDayOfMonth(), 0, 0, DateTimeZone.forTimeZone(TimeZone.getTimeZone(timeZoneId)));

	SunTimes times = SunTimes.compute().on(beginningOfDay.toDate()).at(latitude, longitude).execute();

	DateTime sunriseTime = new DateTime(times.getRise())
			.withZone(DateTimeZone.forTimeZone(TimeZone.getTimeZone(timeZoneId)));

	return sunriseTime;
}
 
Example 8
public PutTherapeuticLinkResponse mapXMLToPutTherapeuticLinkResponse(String xml) throws TechnicalConnectorException {
   be.fgov.ehealth.hubservices.core.v2.PutTherapeuticLinkResponse jaxbResponse = (be.fgov.ehealth.hubservices.core.v2.PutTherapeuticLinkResponse)this.generateJAXB(xml, be.fgov.ehealth.hubservices.core.v2.PutTherapeuticLinkResponse.class);
   ResponseType jaxbResponseType = jaxbResponse.getResponse();
   DateTime date = jaxbResponseType.getDate();
   DateTime time = jaxbResponseType.getTime();
   DateTime dateTime = new DateTime(date.getYear(), date.getMonthOfYear(), date.getDayOfMonth(), time.getHourOfDay(), time.getMinuteOfHour(), time.getSecondOfMinute(), time.getMillisOfSecond(), DateTimeZone.getDefault());
   PutTherapeuticLinkResponse response = new PutTherapeuticLinkResponse(dateTime, this.mapAuthor(jaxbResponseType.getAuthor()), jaxbResponseType.getId().getValue(), this.mapOriginalPutTherapeuticLinkRequest(jaxbResponseType.getRequest()), this.mapAcknowledge(jaxbResponse.getAcknowledge()));
   LOG.info("Output request object :" + response.toString());
   return response;
}
 
Example 9
public PutTherapeuticLinkResponse mapXMLToPutTherapeuticLinkResponse(String xml) throws TechnicalConnectorException {
   be.fgov.ehealth.hubservices.core.v2.PutTherapeuticLinkResponse jaxbResponse = (be.fgov.ehealth.hubservices.core.v2.PutTherapeuticLinkResponse)this.generateJAXB(xml, be.fgov.ehealth.hubservices.core.v2.PutTherapeuticLinkResponse.class);
   ResponseType jaxbResponseType = jaxbResponse.getResponse();
   DateTime date = jaxbResponseType.getDate();
   DateTime time = jaxbResponseType.getTime();
   DateTime dateTime = new DateTime(date.getYear(), date.getMonthOfYear(), date.getDayOfMonth(), time.getHourOfDay(), time.getMinuteOfHour(), time.getSecondOfMinute(), time.getMillisOfSecond(), DateTimeZone.getDefault());
   PutTherapeuticLinkResponse response = new PutTherapeuticLinkResponse(dateTime, this.mapAuthor(jaxbResponseType.getAuthor()), jaxbResponseType.getId().getValue(), this.mapOriginalPutTherapeuticLinkRequest(jaxbResponseType.getRequest()), this.mapAcknowledge(jaxbResponse.getAcknowledge()));
   LOG.info("Output request object :" + response.toString());
   return response;
}
 
Example 10
Source Project: jfixture   File: PartialRelay.java    License: MIT License 5 votes vote down vote up
@Override
public Object create(Object request, SpecimenContext context) {
    if (!request.equals(Partial.class))
        return new NoSpecimen();

    DateTime date = (DateTime) context.resolve(DateTime.class);

    return new Partial(fieldTypes, new int[]{
            date.getYear(),
            date.getMonthOfYear(),
            date.getDayOfMonth(),
            date.getHourOfDay(),
            date.getMinuteOfHour(),
            date.getSecondOfMinute()});
}
 
Example 11
/**
 * Creates FeedItems with the values to use in ad customizations for each ad group in
 * <code>adGroupIds</code>.
 */
private static void createCustomizerFeedItems(AdWordsServicesInterface adWordsServices,
    AdWordsSession session, List<Long> adGroupIds, AdCustomizerFeed adCustomizerFeed)
    throws RemoteException {
  // Get the FeedItemService.
  FeedItemServiceInterface feedItemService =
      adWordsServices.get(session, FeedItemServiceInterface.class);

  List<FeedItemOperation> feedItemOperations = new ArrayList<>();

  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"), adCustomizerFeed));

  DateTime venusDate = new DateTime(now.getYear(), now.getMonthOfYear(), 15, 0, 0);
  feedItemOperations.add(
      createFeedItemAddOperation(
          "Venus", "$1450.00", venusDate.toString("yyyyMMdd HHmmss"), 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());
  }

  // Add feed item targeting to restrict the feed item to specific ad groups.
  restrictFeedItemToAdGroup(
      adWordsServices, session, feedItemReturnValue.getValue(0), adGroupIds.get(0));
  restrictFeedItemToAdGroup(
      adWordsServices, session, feedItemReturnValue.getValue(1), adGroupIds.get(1));
}
 
Example 12
public PutTherapeuticLinkResponse mapXMLToPutTherapeuticLinkResponse(String xml) throws TechnicalConnectorException {
   be.fgov.ehealth.hubservices.core.v2.PutTherapeuticLinkResponse jaxbResponse = (be.fgov.ehealth.hubservices.core.v2.PutTherapeuticLinkResponse)this.generateJAXB(xml, be.fgov.ehealth.hubservices.core.v2.PutTherapeuticLinkResponse.class);
   ResponseType jaxbResponseType = jaxbResponse.getResponse();
   DateTime date = jaxbResponseType.getDate();
   DateTime time = jaxbResponseType.getTime();
   DateTime dateTime = new DateTime(date.getYear(), date.getMonthOfYear(), date.getDayOfMonth(), time.getHourOfDay(), time.getMinuteOfHour(), time.getSecondOfMinute(), time.getMillisOfSecond(), DateTimeZone.getDefault());
   PutTherapeuticLinkResponse response = new PutTherapeuticLinkResponse(dateTime, this.mapAuthor(jaxbResponseType.getAuthor()), jaxbResponseType.getId().getValue(), this.mapOriginalPutTherapeuticLinkRequest(jaxbResponseType.getRequest()), this.mapAcknowledge(jaxbResponse.getAcknowledge()));
   LOG.info("Output request object :" + response.toString());
   return response;
}
 
Example 13
Source Project: supl-client   File: SuplLppClientHelper.java    License: Apache License 2.0 4 votes vote down vote up
/**
 * Builds a {@link GloEphemeris} instance for the GLONASS satellite from the {@link
 * GNSS_NavModelSatelliteElement} instance containing ephemeris parameters, the reference date
 * {@code DateTime} in Moscow time, and a map with svid as keys and frequency number as values.
 */
private static GloEphemeris buildGloEphemeris(
    GNSS_NavModelSatelliteElement element,
    DateTime moscowDate,
    Map<Integer, Integer> svidToFreqNumMap) {
  GLONASS_ClockModel clock = element.getGnss_ClockModel().getGlonass_ClockModel();
  NavModel_GLONASS_ECEF orbit = element.getGnss_OrbitModel().getGlonass_ECEF();

  // Gets the time of ephemeris, and converts it to UTC time zone.
  // Time of day (minutes) in UTC(SU)
  int iodMin =
      convertBitSetToInt(element.getIod().getValue()) * LppConstants.LPP_GLO_IOD_SCALE_FACTOR;
  DateTime moscowTimeOfEph =
      new DateTime(
          moscowDate.getYear(),
          moscowDate.getMonthOfYear(),
          moscowDate.getDayOfMonth(),
          iodMin / 60,
          iodMin % 60,
          DateTimeZone.UTC);
  DateTime utcTimeOfEph = moscowTimeOfEph.minusHours(TimeConstants.MOSCOW_UTC_TIME_OFFSET_HOURS);

  int svid = element.getSvID().getSatellite_id().getInteger().intValue() + 1;
  int carrierFreqNum = svidToFreqNumMap.get(svid);

  return GloEphemeris.newBuilder()
      .setFreqNum(carrierFreqNum)
      .setSvid(svid)
      .setUtcTime(utcTimeOfEph)
      .setHealth(element.getSvHealth().getValue().get(1) ? 1 : 0)
      .setBiasS(clock.getGloTau().getInteger().intValue() * ScaleFactors.GLO_CLK_TAU)
      .setRelFreqBias(clock.getGloGamma().getInteger().intValue() * ScaleFactors.GLO_CLK_GAMMA)
      .setAgeDays(orbit.getGloEn().getInteger().intValue())
      .setXSatPosM(
          orbit.getGloX().getInteger().intValue()
              * ScaleFactors.GLO_ORB_POS_KM
              * GnssConstants.METERS_PER_KM)
      .setYSatPosM(
          orbit.getGloY().getInteger().intValue()
              * ScaleFactors.GLO_ORB_POS_KM
              * GnssConstants.METERS_PER_KM)
      .setZSatPosM(
          orbit.getGloZ().getInteger().intValue()
              * ScaleFactors.GLO_ORB_POS_KM
              * GnssConstants.METERS_PER_KM)
      .setXSatVelMps(
          orbit.getGloXdot().getInteger().intValue()
              * ScaleFactors.GLO_ORB_VEL_KMPS
              * GnssConstants.METERS_PER_KM)
      .setYSatVelMps(
          orbit.getGloYdot().getInteger().intValue()
              * ScaleFactors.GLO_ORB_VEL_KMPS
              * GnssConstants.METERS_PER_KM)
      .setZSatVelMps(
          orbit.getGloZdot().getInteger().intValue()
              * ScaleFactors.GLO_ORB_VEL_KMPS
              * GnssConstants.METERS_PER_KM)
      .setXMoonSunAccMps2(
          orbit.getGloXdotdot().getInteger().intValue()
              * ScaleFactors.GLO_ORB_ACCELERATION_KMPS2
              * GnssConstants.METERS_PER_KM)
      .setYMoonSunAccMps2(
          orbit.getGloYdotdot().getInteger().intValue()
              * ScaleFactors.GLO_ORB_ACCELERATION_KMPS2
              * GnssConstants.METERS_PER_KM)
      .setZMoonSunAccMps2(
          orbit.getGloZdotdot().getInteger().intValue()
              * ScaleFactors.GLO_ORB_ACCELERATION_KMPS2
              * GnssConstants.METERS_PER_KM)
      .build();
}
 
Example 14
private TherapeuticLinkRequestType mapOriginalPutTherapeuticLinkRequest(RequestType request) {
   DateTime date = request.getDate();
   DateTime time = request.getTime();
   DateTime dateTime = new DateTime(date.getYear(), date.getMonthOfYear(), date.getDayOfMonth(), time.getHourOfDay(), time.getMinuteOfHour(), time.getSecondOfMinute(), time.getMillisOfSecond());
   return new PutTherapeuticLinkRequest(dateTime, request.getId().getValue(), this.mapAuthor(request.getAuthor()));
}
 
Example 15
/**
 * Output the overallStats to logger
 * @throws AdeException 
 */
private void generateReportIfNeeded(long inputTime) throws AdeException {
    final DateTime inputDateTimeStartOfDay = new DateTime(inputTime).withZone(s_outTimeZone).withTimeAtStartOfDay();
    final int daysSinceLastReported = Days.daysBetween(m_lastReportDateTimeBegin, inputDateTimeStartOfDay).getDays();
    if (daysSinceLastReported < 1) {
        /* Do not need report if the days is less than 1 day */
        return;
    }

    boolean createReport = false;
    boolean resetData = false;

    switch (m_reportFrequency) {
        case MONTHLY: {
            final boolean monthChangedSinceLastReported = m_lastReportDateTimeBegin.getMonthOfYear() != inputDateTimeStartOfDay.getMonthOfYear()
                    || m_lastReportDateTimeBegin.getYear() != inputDateTimeStartOfDay.getYear();

            if (monthChangedSinceLastReported) {
                createReport = true;
                resetData = true;
            } else {
                resetData = false;

                /* If this processing is within the same month as processing start, 
                 * output every day */
                final boolean monthChangedSinceProcessingStarted = m_processingStartDateTime.getMonthOfYear() != inputDateTimeStartOfDay.getMonthOfYear()
                        || m_processingStartDateTime.getYear() != inputDateTimeStartOfDay.getYear();
                if (!monthChangedSinceProcessingStarted) {
                    createReport = true;
                }
            }
            break;
        }
        case DAYS: {
            if (daysSinceLastReported >= m_reportFrequency.getDays()) {
                createReport = true;
                resetData = true;
            } else {
                resetData = false;

                /* If this processing just started less than or equal to 10 days, output every day */
                final int daysSinceStarted = Days.daysBetween(m_processingStartDateTime, inputDateTimeStartOfDay).getDays();
                if (daysSinceStarted <= m_reportFrequency.getDays()) {
                    createReport = true;
                }
            }
            break;
        }
        default:
            break;
    }

    /* Write out the report */
    if (createReport) {
        generateReport(getYesterdayEndOfDay(inputDateTimeStartOfDay));
        m_lastReportDateTimeBegin = inputDateTimeStartOfDay;

        /* Reset all the data */
        if (resetData) {
            initOverallStatsForAllIntervals();
        }
    }
}
 
Example 16
private void submitWorkflowJob(String workFlowRoot)
		throws OozieClientException, InterruptedException {
	String oozieURL = System.getProperty("oozie.base.url");
	LOG.debug("Oozie BaseURL is: {} ", oozieURL);
	OozieClient client = new OozieClient(oozieURL);

	DateTime now = new DateTime();
	int monthOfYear = now.getMonthOfYear();
	int dayOfMonth = now.getDayOfMonth();
	int hourOfDay = now.getHourOfDay();
	String year = String.valueOf(now.getYear());
	String month = monthOfYear < 10 ? "0" + String.valueOf(monthOfYear)
			: String.valueOf(monthOfYear);
	String day = dayOfMonth < 10 ? "0" + String.valueOf(dayOfMonth)
			: String.valueOf(dayOfMonth);
	String hour = hourOfDay < 10 ? "0" + String.valueOf(hourOfDay) : String
			.valueOf(hourOfDay);

	Properties conf = client.createConfiguration();
	conf.setProperty(OozieClient.APP_PATH, workFlowRoot
			+ "/hive-action-add-partition.xml");
	conf.setProperty("nameNode", hadoopClusterService.getHDFSUri());
	conf.setProperty("jobTracker", hadoopClusterService.getJobTRackerUri());
	conf.setProperty("workflowRoot", workFlowRoot);
	conf.setProperty("YEAR", year);
	conf.setProperty("MONTH", month);
	conf.setProperty("DAY", day);
	conf.setProperty("HOUR", hour);
	conf.setProperty("oozie.use.system.libpath", "true");

	// submit and start the workflow job
	client.setDebugMode(1);
	// client.dryrun(conf);
	String jobId = client.run(conf);// submit(conf);

	LOG.debug("Workflow job submitted");
	// wait until the workflow job finishes printing the status every 10
	// seconds
	int retries = 3;
	for (int i = 1; i <= retries; i++) {
		// Sleep 60 sec./ 3 mins
		Thread.sleep(60 * 1000);

		WorkflowJob jobInfo = client.getJobInfo(jobId);
		Status jobStatus = jobInfo.getStatus();
		LOG.debug("Workflow job running ...");
		LOG.debug("HiveActionWorkflowJob Status Try: {}", i);
		LOG.debug("HiveActionWorkflowJob Id: {}", jobInfo.getId());
		LOG.debug("HiveActionWorkflowJob StartTime: {}",
				jobInfo.getStartTime());
		LOG.debug("HiveActionWorkflowJob EndTime: {}", jobInfo.getEndTime());
		LOG.debug("HiveActionWorkflowJob ConsoleURL: {}",
				jobInfo.getConsoleUrl());
		LOG.debug("HiveActionWorkflowJob Status: {}", jobInfo.getStatus());

		WorkflowAction workflowAction = jobInfo.getActions().get(0);

		LOG.debug("HiveActionWorkflowJob Action consoleURL: {}",
				workflowAction.getConsoleUrl());
		LOG.debug("HiveActionWorkflowJob Action Name: {}",
				workflowAction.getName());
		LOG.debug("HiveActionWorkflowJob Action error message: {}",
				workflowAction.getErrorMessage());
		LOG.debug("HiveActionWorkflowJob Action Status: {}",
				workflowAction.getStats());
		LOG.debug("HiveActionWorkflowJob Action data: {}",
				workflowAction.getData());
		LOG.debug("HiveActionWorkflowJob Action conf: {}",
				workflowAction.getConf());
		LOG.debug("HiveActionWorkflowJob Action retries: {}",
				workflowAction.getRetries());
		LOG.debug("HiveActionWorkflowJob Action id: {}",
				workflowAction.getId());
		LOG.debug("HiveActionWorkflowJob Action start time: {}",
				workflowAction.getStartTime());
		LOG.debug("HiveActionWorkflowJob Action end time: {}",
				workflowAction.getEndTime());
		LOG.debug("HiveActionWorkflowJob Oozie Url: {}",
				client.getOozieUrl());

		if (jobStatus == WorkflowJob.Status.SUCCEEDED) {
			LOG.info("Oozie workflow job was successful!" + jobStatus);
			break;
		} else if (jobStatus == WorkflowJob.Status.PREP
				|| jobStatus == WorkflowJob.Status.RUNNING) {
			if (i == retries) {
				throw new RuntimeException("Error executing workflow job!"
						+ jobStatus);
			} else {
				continue;
			}
		} else {
			throw new RuntimeException("Error executing workflow job!"
					+ jobStatus);
		}
	}
}
 
Example 17
Source Project: jianshi   File: MainActivity.java    License: Apache License 2.0 4 votes vote down vote up
private void setDate(DateTime date) {
  year = date.getYear();
  month = date.getMonthOfYear();
  day = date.getDayOfMonth();
}
 
Example 18
public void setDate(View view, boolean completed, String due_on, long id) {
    TextView dueOn = (TextView) view.findViewById(R.id.due_on);
    Log.i(TAG, "due_on:" + due_on);

    Date date = new Date();
    Date now = new Date();

    try {
        date = sdf.parse(due_on);
    } catch (ParseException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

    DateTime dt = new DateTime(date);
    int month = dt.getMonthOfYear();
    int dayOfMonth = dt.getDayOfMonth();
    int year = dt.getYear();
    String localizedMonth = months[month - 1];
    due_on = String.format("%02d %s %04d", dayOfMonth, localizedMonth, year);

    Log.i(TAG, "due_on(formatted):" + due_on);
    dueOn.setText(due_on);
    if (completed) {
        dueOn.setTextColor(getResources().getColor(R.color.complete));
    } else if (now.getDay() == date.getDay()
            && now.getMonth() == date.getMonth()
            && now.getYear() == date.getYear()) {
        if (now.after(date)) {
            dueOn.setTextColor(getResources().getColor(R.color.past_due));
            Log.w(TAG, "DUE TODAY-PAST DUE:" + id);
        } else {
            Log.w(TAG, "DUE TODAY:" + id);
            dueOn.setTextColor(getResources().getColor(R.color.due_today));
        }
    } else if (now.after(date)) {
        dueOn.setTextColor(getResources().getColor(R.color.past_due));
        Log.w(TAG, "PAST DUE DATE:" + id);
    } else {
        Log.i(TAG, "due date ok:" + id);
        dueOn.setTextColor(getResources().getColor(android.R.color.white));
    }
}
 
Example 19
/**
 * Null-safe method that returns a new instance of a DateTime object rounded
 * downwards to the nearest second. The time zone of the returned DateTime
 * instance will be the same as the argument. Similar to a floor() function
 * on a float.<br>
 * Examples:
 * <ul>
 *      <li>null -> null
 *      <li>"2009-06-24 13:24:51.476 -8:00" -> "2009-06-24 13:24:51.000 -8:00"
 * </ul>
 * @param value The DateTime value to round downward
 * @return Null if the argument is null or a new instance of the DateTime
 *      value rounded downwards to the nearest second.
 */
public static DateTime floorToSecond(DateTime value) {
    if (value == null) {
        return null;
    }
    return new DateTime(value.getYear(), value.getMonthOfYear(), value.getDayOfMonth(), value.getHourOfDay(), value.getMinuteOfHour(), value.getSecondOfMinute(), 0, value.getZone());
}
 
Example 20
Source Project: Mycat2   File: DateUtil.java    License: GNU General Public License v3.0 2 votes vote down vote up
/**
 * 获取date对象月份
 * @param date
 * @return
 */
public static int getMonth(Date date) {
	DateTime dt = new DateTime(date);
	return dt.getMonthOfYear();
}