当前位置: 首页>>代码示例>>Java>>正文


Java Months类代码示例

本文整理汇总了Java中org.joda.time.Months的典型用法代码示例。如果您正苦于以下问题:Java Months类的具体用法?Java Months怎么用?Java Months使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


Months类属于org.joda.time包,在下文中一共展示了Months类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getAverageGlucoseReadingsByMonth

import org.joda.time.Months; //导入依赖的package包/类
public List<Integer> getAverageGlucoseReadingsByMonth() {
    JodaTimeAndroid.init(mContext);

    DateTime maxDateTime = new DateTime(realm.where(GlucoseReading.class).maximumDate("created").getTime());
    DateTime minDateTime = new DateTime(realm.where(GlucoseReading.class).minimumDate("created").getTime());

    DateTime currentDateTime = minDateTime;
    DateTime newDateTime = minDateTime;

    ArrayList<Integer> averageReadings = new ArrayList<Integer>();

    // The number of months is at least 1 since we do have average for the current week even if incomplete
    int monthsNumber = Months.monthsBetween(minDateTime, maxDateTime).getMonths() + 1;

    for (int i = 0; i < monthsNumber; i++) {
        newDateTime = currentDateTime.plusMonths(1);
        RealmResults<GlucoseReading> readings = realm.where(GlucoseReading.class)
                .between("created", currentDateTime.toDate(), newDateTime.toDate())
                .findAll();
        averageReadings.add(((int) readings.average("reading")));
        currentDateTime = newDateTime;
    }
    return averageReadings;
}
 
开发者ID:adithya321,项目名称:SOS-The-Healthcare-Companion,代码行数:25,代码来源:DatabaseHandler.java

示例2: getGlucoseDatetimesByMonth

import org.joda.time.Months; //导入依赖的package包/类
public List<String> getGlucoseDatetimesByMonth() {
    JodaTimeAndroid.init(mContext);

    DateTime maxDateTime = new DateTime(realm.where(GlucoseReading.class).maximumDate("created").getTime());
    DateTime minDateTime = new DateTime(realm.where(GlucoseReading.class).minimumDate("created").getTime());

    DateTime currentDateTime = minDateTime;
    DateTime newDateTime = minDateTime;

    ArrayList<String> finalMonths = new ArrayList<String>();

    // The number of months is at least 1 because current month is incomplete
    int monthsNumber = Months.monthsBetween(minDateTime, maxDateTime).getMonths() + 1;

    DateFormat inputFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm");
    for (int i = 0; i < monthsNumber; i++) {
        newDateTime = currentDateTime.plusMonths(1);
        finalMonths.add(inputFormat.format(newDateTime.toDate()));
        currentDateTime = newDateTime;
    }
    return finalMonths;
}
 
开发者ID:adithya321,项目名称:SOS-The-Healthcare-Companion,代码行数:23,代码来源:DatabaseHandler.java

示例3: getMonthsBetween

import org.joda.time.Months; //导入依赖的package包/类
public static int getMonthsBetween(final String date1, final String date2, String format){
    try {
    final DateTimeFormatter fmt =
            DateTimeFormat
                    .forPattern(format)
                    .withChronology(
                            LenientChronology.getInstance(
                                    GregorianChronology.getInstance()));
    return Months.monthsBetween(
            fmt.parseDateTime(date1),
            fmt.parseDateTime(date2)
    ).getMonths();
    } catch (Exception ex) {
        ex.printStackTrace();
        return 0;
    }
}
 
开发者ID:Suhas010,项目名称:Artificial-Intelligent-chat-bot-,代码行数:18,代码来源:IntervalUtils.java

示例4: Calendar

import org.joda.time.Months; //导入依赖的package包/类
public Calendar(DateTime firstMonth, DateTime lastMonth) {
    this.firstMonth = firstMonth;
    this.firstDayOfWeek = java.util.Calendar.getInstance(Locale.getDefault()).getFirstDayOfWeek();

    DateTime startMonth = firstMonth.plusMonths(1);
    int monthsBetweenCount = Months.monthsBetween(firstMonth, lastMonth).getMonths();

    months = new ArrayList<>();

    months.add(firstMonth);
    currentMonth = firstMonth;

    DateTime monthToAdd = new DateTime(startMonth.getYear(), startMonth.getMonthOfYear(), 1, 0, 0);
    for (int i = 0; i <= monthsBetweenCount; i++) {
        months.add(monthToAdd);
        monthToAdd = monthToAdd.plusMonths(1);
    }
}
 
开发者ID:MOLO17,项目名称:CustomizableCalendar,代码行数:19,代码来源:Calendar.java

示例5: get_interval

import org.joda.time.Months; //导入依赖的package包/类
private String get_interval(DateTime largerDatetime, DateTime smallerDateTime) throws HydraClientException{
	int year_diff  = Years.yearsBetween(smallerDateTime, largerDatetime).getYears();
	int month_diff  = Months.monthsBetween(smallerDateTime, largerDatetime).getMonths();
	int day_diff  = Days.daysBetween(smallerDateTime, largerDatetime).getDays();
	int hour_diff = Hours.hoursBetween(smallerDateTime, largerDatetime).getHours();
    int min_diff  = Minutes.minutesBetween(smallerDateTime, largerDatetime).getMinutes();
    
    if (year_diff > 0){return year_diff+"YEAR";}
    if (month_diff > 0){return month_diff+"MONTH";}
    if (day_diff > 0){return day_diff+"DAY";}
    if (hour_diff > 0){return hour_diff+"HOUR";}
    if (min_diff > 0){return min_diff+"MIN";}

    throw new HydraClientException("Could not compute interval between times " + smallerDateTime.toString() + "and" + largerDatetime.toString());
	
}
 
开发者ID:UMWRG,项目名称:DSSApp,代码行数:17,代码来源:DSSExport.java

示例6: MONTHS

import org.joda.time.Months; //导入依赖的package包/类
/**
 * Returns the number of months between two dates.
 */
@Function("MONTHS")
@FunctionParameters({
	@FunctionParameter("startDate"),
	@FunctionParameter("endDate")})
public Integer MONTHS(Object startDate, Object endDate){
	Date startDateObj = convertDateObject(startDate);
	if(startDateObj==null) {
		logCannotConvertToDate();
		return null;
	}
	Date endDateObj = convertDateObject(endDate);
	if(endDateObj==null){
		logCannotConvertToDate();
		return null;
	}
	else{
		LocalDate dt1=new LocalDate(startDateObj);
		LocalDate dt2=new LocalDate(endDateObj);
		return Months.monthsBetween(dt1, dt2).getMonths();
	}
}
 
开发者ID:TIBCOSoftware,项目名称:jasperreports,代码行数:25,代码来源:DateTimeFunctions.java

示例7: getCorrectRepeatingDates

import org.joda.time.Months; //导入依赖的package包/类
private ArrayList<DateTime> getCorrectRepeatingDates(RepeatingPayment payment, DateTime now)
{
	ArrayList<DateTime> dates = new ArrayList<>();
	DateTime startDate = DateTime.parse(payment.getDate());
	
	//repeat every x days
	if(payment.getRepeatInterval() != 0)
	{			
		int numberOfDays = Days.daysBetween(startDate, now).getDays();			
		int occurrences = numberOfDays / payment.getRepeatInterval();
		for(int i = 0; i <= occurrences; i++)
		{
			dates.add(startDate.plusDays(i * payment.getRepeatInterval()));
		}
	}
	//repeat every month on day x
	else
	{
		int numberOfMonths = Months.monthsBetween(startDate.withDayOfMonth(payment.getRepeatMonthDay()), now).getMonths();
		for(int i = 0; i <= numberOfMonths; i++)
		{
			dates.add(startDate.plusMonths(i));
		}				
	}
	return dates;
}
 
开发者ID:deadlocker8,项目名称:BudgetMaster,代码行数:27,代码来源:RepeatingPaymentUpdater.java

示例8: create

import org.joda.time.Months; //导入依赖的package包/类
@Override
public Object create(Object request, SpecimenContext context) {

    if (!(request instanceof SpecimenType)) {
        return new NoSpecimen();
    }

    SpecimenType type = (SpecimenType) request;
    if (!BaseSingleFieldPeriod.class.isAssignableFrom(type.getRawType())) {
        return new NoSpecimen();
    }

    Duration duration = (Duration) context.resolve(Duration.class);
    if (type.equals(Seconds.class)) return Seconds.seconds(Math.max(1, (int) duration.getStandardSeconds()));
    if (type.equals(Minutes.class)) return Minutes.minutes(Math.max(1, (int) duration.getStandardMinutes()));
    if (type.equals(Hours.class)) return Hours.hours(Math.max(1, (int) duration.getStandardHours()));

    if (type.equals(Days.class)) return Days.days(Math.max(1, (int) duration.getStandardDays()));
    if (type.equals(Weeks.class)) return Weeks.weeks(Math.max(1, (int) duration.getStandardDays() / 7));
    if (type.equals(Months.class)) return Months.months(Math.max(1, (int) duration.getStandardDays() / 30));
    if (type.equals(Years.class)) return Years.years(Math.max(1, (int) duration.getStandardDays() / 365));

    return new NoSpecimen();
}
 
开发者ID:FlexTradeUKLtd,项目名称:jfixture,代码行数:25,代码来源:BaseSingleFieldPeriodRelay.java

示例9: exec

import org.joda.time.Months; //导入依赖的package包/类
@Override
public Long exec(Tuple input) throws IOException
{
    if (input == null || input.size() < 2) {
        return null;
    }

    DateTime startDate = (DateTime) input.get(0);
    DateTime endDate = (DateTime) input.get(1);

    // Larger value first
    Months m = Months.monthsBetween(endDate, startDate);
    // joda limitation, only integer range, at the risk of overflow, need to be improved
    return (long) m.getMonths();

}
 
开发者ID:sigmoidanalytics,项目名称:spork-streaming,代码行数:17,代码来源:MonthsBetween.java

示例10: exec

import org.joda.time.Months; //导入依赖的package包/类
@Override
public Long exec(Tuple input) throws IOException
{
    if (input == null || input.size() < 2) {
        return null;
    }
    
    // Set the time to default or the output is in UTC
    DateTimeZone.setDefault(DateTimeZone.UTC);

    DateTime startDate = new DateTime(input.get(0).toString());
    DateTime endDate = new DateTime(input.get(1).toString());

    // Larger value first
    Months m = Months.monthsBetween(endDate, startDate);
    long months = m.getMonths();

    return months;

}
 
开发者ID:sigmoidanalytics,项目名称:spork-streaming,代码行数:21,代码来源:ISOMonthsBetween.java

示例11: storeAllMeasures

import org.joda.time.Months; //导入依赖的package包/类
/**
 * Obtain the indicators from the statistics and stores them into the im
 * 
 * @param im indicatorMap to store the indicators
 * @param statistics statistics of the git.
 */
private void storeAllMeasures(IndicatorsMap im, GitLogStatistics statistics)
{
    DateTime dt = new DateTime(statistics.firstCommitDate);
    Months months = Months.monthsBetween(dt, new DateTime());
    Weeks weeks = Weeks.weeksBetween(dt, new DateTime());

    im.add("git average-commits-per-month", (double) statistics.totalCommits / months.getMonths());
    im.add("git average-commits-per-week", (double) statistics.totalCommits / weeks.getWeeks());
    im.add("git average-commits-per-committer", (double) statistics.totalCommits / statistics.totalCommitters);
    im.add("git average-files-changed-per-committer", (double) statistics.totalFilesChanged
        / statistics.totalCommitters);
    im.add("git average-lines-added-per-commmit", (double) statistics.totalLinesAdded / statistics.totalCommits);
    im.add("git average-lines-removed-per-commit", (double) statistics.totalLinesRemoved / statistics.totalCommits);
    im.add("git average-files-changed-per-commit", (double) statistics.totalFilesChanged / statistics.totalCommits);

    im.add("git distribution-commits-by-hour", RiskDataType.DISTRIBUTION,
        getDistribution(statistics.commitsByHour, statistics.totalCommits));

    im.add("git distribution-commits-by-weekday", RiskDataType.DISTRIBUTION,
        getDistribution(statistics.commitsByWeekday, statistics.totalCommits));

}
 
开发者ID:rbenjacob,项目名称:riscoss-platform,代码行数:29,代码来源:GitRiskDataCollector.java

示例12: exec

import org.joda.time.Months; //导入依赖的package包/类
@Override
public Long exec(Tuple input) throws IOException
{
    if (input == null || input.size() < 2 || input.get(0) == null || input.get(1) == null) {
        return null;
    }

    DateTime startDate = (DateTime) input.get(0);
    DateTime endDate = (DateTime) input.get(1);

    // Larger value first
    Months m = Months.monthsBetween(endDate, startDate);
    // joda limitation, only integer range, at the risk of overflow, need to be improved
    return (long) m.getMonths();

}
 
开发者ID:sigmoidanalytics,项目名称:spork,代码行数:17,代码来源:MonthsBetween.java

示例13: exec

import org.joda.time.Months; //导入依赖的package包/类
@Override
public Long exec(Tuple input) throws IOException
{
    if (input == null || input.size() < 2) {
        return null;
    }

    if (input.get(0) == null || input.get(1) == null) {
        return null;
    }

    DateTime startDate = new DateTime(input.get(0).toString());
    DateTime endDate = new DateTime(input.get(1).toString());

    // Larger value first
    Months m = Months.monthsBetween(endDate, startDate);
    long months = m.getMonths();

    return months;

}
 
开发者ID:sigmoidanalytics,项目名称:spork,代码行数:22,代码来源:ISOMonthsBetween.java

示例14: BackupAccessService

import org.joda.time.Months; //导入依赖的package包/类
@Autowired
public BackupAccessService(DataConfigService config, BackupFileService service) {
	this.config = config;
	this.fileService = service;
	
	// timed backups
	monthlyBackup = new ConditionalBackupExecutor("monthly", 6, (now, last) -> {
			final Months duration = Months.monthsBetween(last, now);
			return duration.getMonths() >= 1;
		}
	);
	daylyBackup = new ConditionalBackupExecutor("dayly", 7, (now, last) -> {
			final Days duration = Days.daysBetween(last, now);
			return duration.getDays() >= 1;
		}
	);
	hourlyBackup = new ConditionalBackupExecutor("hourly", 24, (now, last) -> {
			final Hours duration = Hours.hoursBetween(last, now);
			return duration.getHours() >= 1;
		}
	);
	// triggered backups
	triggeredBackup = new BackupExecutor("triggered", 100);
}
 
开发者ID:Katharsas,项目名称:GMM,代码行数:25,代码来源:BackupAccessService.java

示例15: areContactsRecent

import org.joda.time.Months; //导入依赖的package包/类
public boolean areContactsRecent(final Class<? extends PartyContact> contactClass, final int daysNotUpdated) {
    final List<? extends PartyContact> partyContacts = getPartyContacts(contactClass);
    boolean isUpdated = false;
    for (final PartyContact partyContact : partyContacts) {
        if (partyContact.getLastModifiedDate() == null) {
            isUpdated = isUpdated || false;
        } else {
            final DateTime lastModifiedDate = partyContact.getLastModifiedDate();
            final DateTime now = new DateTime();
            final Months months = Months.monthsBetween(lastModifiedDate, now);
            if (months.getMonths() > daysNotUpdated) {
                isUpdated = isUpdated || false;
            } else {
                isUpdated = isUpdated || true;
            }
        }
    }
    return isUpdated;
}
 
开发者ID:FenixEdu,项目名称:fenixedu-academic,代码行数:20,代码来源:Person.java


注:本文中的org.joda.time.Months类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。