Java 类org.apache.commons.lang3.time.DateUtils 实例源码

项目:uroborosql    文件:ParameterTest.java   
@Test
public void testSetInParameter_mapperForLocalDate() throws ParseException, SQLException {

    LocalDate localDate = LocalDate.of(2002, Month.JANUARY, 1);
    Date date = DateUtils.parseDate("2002-01-01", new String[] { "yyyy-MM-dd" });
    try (SqlAgent agent = config.agent()) {
        SqlContext ctx = agent.contextFrom("test/PARAM_MAPPING1").param("targetDate", localDate);

        try (ResultSet rs = agent.query(ctx)) {
            assertThat("結果が0件です。", rs.next(), is(true));
            assertThat(rs.getDate("TARGET_DATE"), is(new java.sql.Date(date.getTime())));

            assertThat("取得データが多すぎます", rs.next(), is(false));
        }

    }
}
项目:plugin-bt    文件:ComputationContext.java   
/**
 * Advance the cursor with the given duration.
 * 
 * @param duration
 *            Duration to add to current date. Business hours are considered.
 * @return The new date.
 */
public Date moveForward(final long duration) {
    long remainingDuration = duration;
    while (remainingDuration > 0) {
        this.delta = 0;

        // We need to move the cursors
        if (cursorTime + remainingDuration < DateUtils.MILLIS_PER_DAY) {
            // We need to compute the elapsed ranges and hours within the same day
            computeDelayTodayToTime(cursorTime + remainingDuration);
        } else {
            // Move to the end of this day
            computeDelayTodayToTime(DateUtils.MILLIS_PER_DAY);
        }
        remainingDuration -= delta;
    }

    // Return the new date
    return new Date(cursor.getTime() + getCursorTime());
}
项目:plugin-bt    文件:BugTrackerResource.java   
private void linkOrCreate(final int subscription) {
    // Add Configuration
    final BugTrackerConfiguration configuration = new BugTrackerConfiguration();
    configuration.setSubscription(subscriptionRepository.findOne(subscription));
    configuration.setCalendar(getDefaultCalendar());
    repository.saveAndFlush(configuration);

    // 9h to 18h
    final BusinessHours businessRange1 = new BusinessHours();
    businessRange1.setStart(8 * DateUtils.MILLIS_PER_HOUR);
    businessRange1.setEnd(18 * DateUtils.MILLIS_PER_HOUR);
    businessRange1.setConfiguration(configuration);
    businessHoursRepository.saveAndFlush(businessRange1);

    // Set a new SLA
    final Sla sla = new Sla();
    sla.setConfiguration(configuration);
    sla.setDescription("Closing : Open->Closed");
    sla.setStart("OPEN");
    sla.setStop("CLOSED");
    sla.setName("Closing");
    slaRepository.saveAndFlush(sla);
}
项目:OfficeAutomation    文件:CellConvert.java   
public static Date getDate(Cell cell, String format) throws ParseException {
    if (isNullCell(cell)) {
        return null;
    }
    switch (cell.getCellType()) {
        case Cell.CELL_TYPE_NUMERIC:// 数字类型
            return getCellDate(cell);
        case Cell.CELL_TYPE_STRING:
            if(StringUtils.isNotEmpty(cell.getStringCellValue())){
                return DateUtils.parseDate(cell.getStringCellValue(), format);
            }else{
                return null;
            }
        default:
            throw new RuntimeException("can not convertWithConstructor cell value to Date!");
    }
}
项目:plugin-bt    文件:BugTrackerResourceTest.java   
@Test
public void addBusinessHoursOverlapsEnd() {
    thrown.expect(ValidationJsonException.class);
    thrown.expect(MatcherUtil.validationMatcher("stop", "Overlap"));

    final BusinessHoursEditionVo vo = new BusinessHoursEditionVo();
    vo.setStart(2 * DateUtils.MILLIS_PER_HOUR);
    vo.setEnd(1 * DateUtils.MILLIS_PER_HOUR);
    vo.setSubscription(subscription);
    em.flush();
    em.clear();
    resource.addBusinessHours(vo);
}
项目:plugin-sso-salt    文件:SaltedAuthenticationResourceTest.java   
/**
 * Return SSO token to use in cross site parameters valid for 30 minutes.
 * 
 * @param login
 *            The login of the user
 * @param userKey
 *            The key of the user
 * @return SSO token to use as cross site parameter.
 */
private String getOldSsoToken(final String login, final String userKey) throws Exception {
    // Uses a secure Random not a simple Random
    final SecureRandom random = SecureRandom.getInstance("SHA1PRNG");
    // Salt generation 64 bits long
    final byte[] bSalt = new byte[8];
    random.nextBytes(bSalt);
    // Digest computation
    final byte[] bDigest = resource.getHash(1000, login + userKey, bSalt);
    final String sDigest = resource.byteToBase64(bDigest);
    final String sSalt = resource.byteToBase64(bSalt);
    final long expire = System.currentTimeMillis() - DateUtils.MILLIS_PER_MINUTE * 31;

    // Generated an encrypted key, valid for 30 minutes
    return resource.encrypt(login + "|" + sDigest + "|" + sSalt + "|"
            + new String(Base64.encodeInteger(new BigInteger(String.valueOf(expire)))), "secret");
}
项目:bootstrap    文件:DecimalDateProcessor.java   
@Override
public Date getValue(final String context) {
    final String data = (String) super.getValue(context);

    try {
        final double date = Double.parseDouble(data.replace(',', '.'));
        final Calendar calendar = new GregorianCalendar(); // using default time-zone
        final int wholeDays = (int) Math.floor(date);
        final int millisecondsInDay = (int) Math.round((date - wholeDays) * DateUtils.MILLIS_PER_DAY);

        // Excel thinks 2/29/1900 is a valid date, which it isn't
        calendar.set(1900, 0, wholeDays - 1, 0, 0, 0);
        calendar.set(Calendar.MILLISECOND, millisecondsInDay);
        calendar.add(Calendar.MILLISECOND, 500);
        calendar.clear(Calendar.MILLISECOND);
        return calendar.getTime();
    } catch (final NumberFormatException e) {
        // Invalid format of String
        throw new IllegalArgumentException("Invalid string '" + data + "' for decimal Excel date", e);
    }
}
项目:bootstrap    文件:RbacUserDetailsServiceTest.java   
/**
 * Loading with a well known user and connected yesterday.
 */
@Test
public void testWellKnownUserYesterday() {
    SystemUser user = em.find(SystemUser.class, DEFAULT_USER);
    user.setLastConnection(new Date(new Date().getTime() - DateUtils.MILLIS_PER_DAY * 2));
    em.persist(user);
    em.flush();
    em.clear();
    final UserDetails userDetails = userDetailsService.loadUserByUsername(DEFAULT_USER);
    Assert.assertEquals(1, userDetails.getAuthorities().size());
    Assert.assertEquals(SystemRole.DEFAULT_ROLE, userDetails.getAuthorities().iterator().next().getAuthority());
    Assert.assertEquals(DEFAULT_USER, userDetails.getUsername());
    user = em.find(SystemUser.class, DEFAULT_USER);
    Assert.assertNotNull(user.getLastConnection());
    Assert.assertTrue(Math.abs(new Date().getTime() - user.getLastConnection().getTime()) < DateUtils.MILLIS_PER_MINUTE);
}
项目:osoon    文件:MeetingAttendServiceTest.java   
@Test(expected = HttpClientErrorException.class)
@Transactional
public void attendFailCauseRegistClose() {
    Meeting meeting = meetingService.findById(user1MeetingId).get();
    meeting.setMeetingStatus(Meeting.MeetingStatus.PUBLISHED);
    Date minPlusOpenTime = DateUtils.addMinutes(Date.from(ZonedDateTime.now(ZoneOffset.UTC).toInstant()), -10);
    meeting.setRegistCloseAt(minPlusOpenTime);

    meetingAttendService.attend(meeting, baseDataTestHelper.getUser2());
}
项目:take    文件:ParseFenHong.java   
private Date parse(String d) {
        Date date = null;
        try {
            date = DateUtils.parseDate(d.substring(0, 8), "yyyyMMdd");
        } catch (Exception e) {
//            e.printStackTrace();
        }
        return date;
    }
项目:plugin-bt    文件:ComputationContext.java   
/**
 * initialize the computation context.
 * 
 * @param holidays
 *            the holiday list. Each day must be set to start of the day position.
 * @param businessHours
 *            The business hour ranges. May be empty or must be sorted, and first range must start with 0:00
 *            00.000.
 */
public ComputationContext(final List<Date> holidays, final List<BusinessHours> businessHours) {
    this.holidays = holidays;
    if (businessHours.isEmpty()) {
        // Whole day is a working day
        final BusinessHours businessHour = new BusinessHours();
        businessHour.setStart(0);
        businessHour.setEnd(DateUtils.MILLIS_PER_DAY);
        this.businessHours = Collections.singletonList(businessHour);
    } else {
        this.businessHours = businessHours;
    }
}
项目:plugin-bt    文件:ComputationContext.java   
/**
 * Move the date to the next business day of week. No updated delta.
 */
private void moveToNextBusinessDayOfWeek() {
    final int dow = DateUtils.toCalendar(cursor).get(Calendar.DAY_OF_WEEK);
    if (dow == Calendar.SUNDAY || dow == Calendar.SATURDAY) {
        // Sunday/Saturday --> Monday 00:00 00.000
        moveToTomorrow();
    }
}
项目:dooo    文件:StatisticsCacheServiceAbstract.java   
public void put(final RequestInfo requestInfo) {
    final AppInfo appInfo = requestInfo.getAppInfo();
    final InterfaceInfo interfaceInfo = requestInfo.getInterfaceInfo();
    Date now = new Date();
    Calendar calendar = DateUtils.toCalendar(now);
    final String minuteIndex = getCurrentMinuteIndex(calendar);
    final String currentDay = getCurrentDay(calendar);

    final long cost = requestInfo.getEndTime() - requestInfo.getStartTime();

    final String interfaceCostKey = KeyRole.INTERFACE_COST.getRedisKey(appInfo, interfaceInfo, currentDay);
    final String interfaceKey = KeyRole.INTERFACE.getRedisKey(appInfo, interfaceInfo, currentDay);
    final String appInterfaceKey = KeyRole.APP_INTERFACE.getRedisKey(appInfo, interfaceInfo, currentDay);
    this.redisConfig.execute(new RedisCallback<Object>() {
        @Override
        public Object call(Jedis jedis) {
            Pipeline pipeline = jedis.pipelined();
            // 只有成功的,才有必要统计请求延迟
            if (requestInfo.isSuccessed()) {
                pipeline.hincrBy(interfaceCostKey, minuteIndex, cost);
            }
            final String filed = requestInfo.isSuccessed() ? minuteIndex + "s" : minuteIndex + "f";
            pipeline.hincrBy(interfaceKey, filed, 1);
            pipeline.hincrBy(appInterfaceKey, filed, 1);
            pipeline.sync();

            if (requestInfo.isSuccessed()) {
                expire(jedis, interfaceCostKey);
            }
            expire(jedis, interfaceKey);
            expire(jedis, appInterfaceKey);
            return null;
        }
    });

}
项目:plugin-bt    文件:ComputationContext.java   
/**
 * Compute time duration in milliseconds between last known (or initial date) and the given date.
 * 
 * @param end
 *            The end date for delta computation. This date should be after the last known one or will return
 *            <code>0</code>.
 * @return time duration in milliseconds between start and end date. The returned value is a positive number.
 */
public long moveForward(final Date end) {
    this.delta = 0;
    while (cursor.getTime() + cursorTime < end.getTime()) {
        // We need to move the cursors
        if (DateUtils.isSameDay(cursor, end)) {
            // We need to compute the elapsed ranges and hours within the same day
            computeDelayTodayToTime(getTime(end));
        } else {
            // Move to the end of this day
            computeDelayTodayToTime(DateUtils.MILLIS_PER_DAY);
        }
    }
    return delta;
}
项目:plugin-bt    文件:ComputationContextTest.java   
@Test
public void moveForwardMidnightLessOne() {
    final ComputationContext context = new ComputationContext(new ArrayList<>(), new ArrayList<>());
    context.reset(getDate(2014, 03, 03));
    final Date end = new Date(getDate(2014, 03, 04).getTime() - 1);
    Assert.assertEquals(DateUtils.MILLIS_PER_DAY - 1, context.moveForward(end));
    Assert.assertEquals(getDate(2014, 03, 03), context.getCursor());
    Assert.assertEquals(DateUtils.MILLIS_PER_DAY - 1, context.getCursorTime());
}
项目:bootstrap    文件:FormatProcessorTest.java   
/**
 * Simple date format of static context.
 */
@Test
public void testGetValue() throws ParseException {
    final Deque<Object> contextData = new LinkedList<>();
    final SystemUser systemUser = new SystemUser();
    contextData.add(systemUser);
    final FastDateFormat df = FastDateFormat.getInstance("yyyy/MM/dd", null, null);
    Assert.assertEquals("2014/05/30", new FormatProcessor<>(df, DateUtils.parseDate("2014/05/30", "yyyy/MM/dd")).getValue(contextData));
}
项目:plugin-bt    文件:ComputationContextTest.java   
@Test
public void moveForwardPlusOnePartialWeek() {
    final ComputationContext context = new ComputationContext(new ArrayList<>(), new ArrayList<>());
    context.reset(getDate(2014, 03, 03));
    Assert.assertEquals(5 * DateUtils.MILLIS_PER_DAY, context.moveForward(getDate(2014, 03, 8)));
    Assert.assertEquals(getDate(2014, 03, 10), context.getCursor());
}
项目:plugin-bt    文件:ComputationContextTest.java   
@Test
public void resetBusinessHoursFromNonBusinessHour() {
    final ComputationContext context = new ComputationContext(new ArrayList<>(), newRanges(9, 12, 14, 18));
    context.reset(getDate(2014, 03, 03, 13, 59, 59));
    Assert.assertEquals(getDate(2014, 03, 03), context.getCursor());
    Assert.assertEquals(14 * DateUtils.MILLIS_PER_HOUR, context.getCursorTime());
}
项目:sbc-qsystem    文件:RatioServices.java   
@Override
public String validate(String driverClassName, String url, String username, String password,
    HttpRequest request, HashMap<String, String> params) {
    //sd=20.01.2009&ed=28.01.2009
    // проверка на корректность введенных параметров
    QLog.l().logger().trace("Принятые параметры \"" + params.toString() + "\".");
    if (params.size() == 2) {
        Date sd;
        Date fd;
        Date fd1;
        try {
            sd = Uses.FORMAT_DD_MM_YYYY.parse(params.get("sd"));
            fd = Uses.FORMAT_DD_MM_YYYY.parse(params.get("ed"));
            fd1 = DateUtils.addDays(Uses.FORMAT_DD_MM_YYYY.parse(params.get("ed")), 1);
        } catch (ParseException ex) {
            return "<br>Ошибка ввода параметров! Не все параметры введены корректно(дд.мм.гггг).";
        }
        if (!sd.after(fd)) {
            paramMap.put("sd", sd);
            paramMap.put("ed", fd);
            paramMap.put("ed1", fd1);
        } else {
            return "<br>Ошибка ввода параметров! Дата начала больше даты завершения.";
        }

    } else {
        return "<br>Ошибка ввода параметров!";
    }
    return null;// все нормально
}
项目:springboot-training    文件:DateEditor.java   
public void setAsText(String text) {
    if (text == null) {
        setValue(null);
    } else {
        String str = text.trim();
        if ((this.emptyAsNull) && ("".equals(str)))
            setValue(null);
        else
            try {
                setValue(DateUtils.parseDate(str, DATE_PATTERNS));
            } catch (ParseException e) {
                setValue(null);
            }
    }
}
项目:plugin-bt    文件:ComputationContextTest.java   
@Test
public void moveForwardToSameDayBusinessHour() {
    final ComputationContext context = new ComputationContext(new ArrayList<>(), newRanges(9, 12, 14, 18));
    context.reset(getDate(2014, 03, 03));
    Assert.assertEquals(0, context.moveForward(getDate(2014, 03, 03)));
    Assert.assertEquals(getDate(2014, 03, 03), context.getCursor());
    Assert.assertEquals(9 * DateUtils.MILLIS_PER_HOUR, context.getCursorTime());
}
项目:bootstrap    文件:FormatProcessorTest.java   
/**
 * Simple date format of dynamic context.
 */
@Test
public void testGetItemValue() throws ParseException {
    final Deque<Object> contextData = new LinkedList<>();
    contextData.add(DateUtils.parseDate("2014/05/30", "yyyy/MM/dd"));
    final FastDateFormat df = FastDateFormat.getInstance("yyyy/MM/dd", null, null);
    Assert.assertEquals("2014/05/30", new FormatProcessor<>(df).getValue(contextData));
}
项目:plugin-bt    文件:ComputationContextTest.java   
@Test
public void moveForwardToNextDayBusinessHourMidnight() {
    final ComputationContext context = new ComputationContext(new ArrayList<>(), newRanges(9, 12, 14, 18));
    context.reset(getDate(2014, 03, 03));
    Assert.assertEquals(7 * DateUtils.MILLIS_PER_HOUR, context.moveForward(getDate(2014, 03, 04)));
    Assert.assertEquals(getDate(2014, 03, 04), context.getCursor());
    Assert.assertEquals(9 * DateUtils.MILLIS_PER_HOUR, context.getCursorTime());
}
项目:plugin-bt-jira    文件:BugTrackerResourceTest.java   
@Test
public void addBusinessHoursOverlapsStart() {
    thrown.expect(ValidationJsonException.class);
    thrown.expect(MatcherUtil.validationMatcher("start", "Overlap"));

    final BusinessHoursEditionVo vo = new BusinessHoursEditionVo();
    vo.setStart(10 * DateUtils.MILLIS_PER_HOUR);
    vo.setEnd(23 * DateUtils.MILLIS_PER_HOUR);
    vo.setSubscription(subscription);
    em.flush();
    em.clear();
    resource.addBusinessHours(vo);
}
项目:plugin-bt    文件:ComputationContextTest.java   
@Test
public void moveForwardToNextDayNonBusinessHour() {
    final ComputationContext context = new ComputationContext(new ArrayList<>(), newRanges(9, 12, 14, 18));
    context.reset(getDate(2014, 03, 03));
    Assert.assertEquals(7 * DateUtils.MILLIS_PER_HOUR, context.moveForward(getDate(2014, 03, 04, 8, 0, 0)));
    Assert.assertEquals(getDate(2014, 03, 04), context.getCursor());
    Assert.assertEquals(9 * DateUtils.MILLIS_PER_HOUR, context.getCursorTime());
}
项目:plugin-bt    文件:ComputationContextTest.java   
@Test
public void moveForwardToNext2DayNonBusinessHour() {
    final ComputationContext context = new ComputationContext(new ArrayList<>(), newRanges(9, 12, 14, 18));
    context.reset(getDate(2014, 03, 03));
    Assert.assertEquals(7 * 2 * DateUtils.MILLIS_PER_HOUR, context.moveForward(getDate(2014, 03, 05, 8, 0, 0)));
    Assert.assertEquals(getDate(2014, 03, 05), context.getCursor());
    Assert.assertEquals(9 * DateUtils.MILLIS_PER_HOUR, context.getCursorTime());
}
项目:plugin-bt    文件:ComputationContextTest.java   
@Test
public void moveForwardDurationToNext2DayNonBusinessHour() {
    final ComputationContext context = new ComputationContext(new ArrayList<>(), newRanges(9, 12, 14, 18));
    context.reset(getDate(2014, 03, 03));
    Assert.assertEquals(getDate(2014, 03, 05, 9, 0, 0), context.moveForward(7 * 2 * DateUtils.MILLIS_PER_HOUR));
    Assert.assertEquals(getDate(2014, 03, 05), context.getCursor());
    Assert.assertEquals(9 * DateUtils.MILLIS_PER_HOUR, context.getCursorTime());
}
项目:plugin-bt    文件:ComputationContextTest.java   
@Test
public void moveForwardToNextDayBusinessHour() {
    final ComputationContext context = new ComputationContext(new ArrayList<>(), newRanges(9, 12, 14, 18));
    context.reset(getDate(2014, 03, 03));
    Assert.assertEquals(11 * DateUtils.MILLIS_PER_HOUR, context.moveForward(getDate(2014, 03, 04, 15, 0, 0)));
    Assert.assertEquals(getDate(2014, 03, 04), context.getCursor());
    Assert.assertEquals(15 * DateUtils.MILLIS_PER_HOUR, context.getCursorTime());
}
项目:plugin-bt    文件:ComputationContextTest.java   
@Test
public void resetNightBusinessHour() {
    final ComputationContext context = new ComputationContext(new ArrayList<>(), newRanges(0, 10, 22, 24));
    context.reset(getDate(2014, 03, 03, 23, 00, 00));
    Assert.assertEquals(getDate(2014, 03, 03), context.getCursor());
    Assert.assertEquals(23 * DateUtils.MILLIS_PER_HOUR, context.getCursorTime());
    context.reset(getDate(2014, 03, 03, 8, 00, 00));
    Assert.assertEquals(getDate(2014, 03, 03), context.getCursor());
    Assert.assertEquals(8 * DateUtils.MILLIS_PER_HOUR, context.getCursorTime());
}
项目:plugin-bt    文件:ComputationContextTest.java   
@Test
public void resetNightBusinessHourFromNotBusinessHour() {
    final ComputationContext context = new ComputationContext(new ArrayList<>(), newRanges(0, 10, 22, 24));
    context.reset(getDate(2014, 03, 03, 10, 00, 00));
    Assert.assertEquals(getDate(2014, 03, 03), context.getCursor());
    Assert.assertEquals(22 * DateUtils.MILLIS_PER_HOUR, context.getCursorTime());
}
项目:plugin-bt    文件:ComputationContextTest.java   
@Test
public void moveForwardNightBusinessHourSameDayNonBusinessHour() {
    final ComputationContext context = new ComputationContext(new ArrayList<>(), newRanges(0, 10, 22, 24));
    context.reset(getDate(2014, 03, 03));
    Assert.assertEquals(10 * DateUtils.MILLIS_PER_HOUR, context.moveForward(getDate(2014, 03, 03, 15, 0, 0)));
    Assert.assertEquals(getDate(2014, 03, 03), context.getCursor());
    Assert.assertEquals(22 * DateUtils.MILLIS_PER_HOUR, context.getCursorTime());
}
项目:plugin-bt    文件:ComputationContextTest.java   
@Test
public void moveForwardNightBusinessHourNextDay() {
    final ComputationContext context = new ComputationContext(new ArrayList<>(), newRanges(0, 10, 12, 14, 22, 24));
    context.reset(getDate(2014, 03, 03));
    Assert.assertEquals(26 * DateUtils.MILLIS_PER_HOUR, context.moveForward(getDate(2014, 03, 04, 15, 0, 0)));
    Assert.assertEquals(getDate(2014, 03, 04), context.getCursor());
    Assert.assertEquals(22 * DateUtils.MILLIS_PER_HOUR, context.getCursorTime());
}
项目:plugin-bt    文件:ComputationContextTest.java   
@Test
public void moveForwardInsideNonBusinessHoursAndDays() {
    final List<Date> holidays = new ArrayList<>();
    holidays.add(getDate(2014, 03, 06));
    holidays.add(getDate(2014, 03, 07));
    final ComputationContext context = new ComputationContext(holidays, newRanges(9, 12, 14, 18));
    context.reset(getDate(2014, 03, 05, 19, 0, 0));
    Assert.assertEquals(0, context.moveForward(getDate(2014, 03, 8, 8, 0, 0)));

    // 2014/03/09 is Sunday --> 2014/03/10
    Assert.assertEquals(getDate(2014, 03, 10), context.getCursor());
    Assert.assertEquals(9 * DateUtils.MILLIS_PER_HOUR, context.getCursorTime());
}
项目:plugin-bt    文件:ComputationContextTest.java   
/**
 * Return a list of business hours ranges.
 */
private List<BusinessHours> newRanges(final int... businessHoursCouples) {
    final List<BusinessHours> ranges = new ArrayList<>();
    for (int i = 0; i < businessHoursCouples.length; i += 2) {
        final BusinessHours range = new BusinessHours();
        range.setStart(businessHoursCouples[i] * DateUtils.MILLIS_PER_HOUR);
        range.setEnd(businessHoursCouples[i + 1] * DateUtils.MILLIS_PER_HOUR);
        ranges.add(range);
    }
    return ranges;
}
项目:plugin-bt    文件:BugTrackerResourceTest.java   
public void createOrLink(final Consumer<Subscription> function) {

        final Project project = new Project();
        project.setName("TEST");
        project.setPkey("test");
        em.persist(project);
        em.flush();

        final Subscription subscription = new Subscription();
        subscription.setProject(project);
        subscription.setNode(nodeRepository.findOneExpected("service:bt"));
        em.persist(subscription);
        em.flush();
        em.clear();

        function.accept(subscription);
        em.flush();
        em.clear();

        // Check SLA
        final BugTrackerConfiguration configuration = repository.findBySubscriptionFetch(subscription.getId());
        checkSla(configuration);

        // Check calendar
        final Calendar calendar = configuration.getCalendar();
        Assert.assertNotNull(calendar);
        Assert.assertEquals(66, calendar.getHolidays().size());
        Assert.assertEquals("France", calendar.getName());
        Assert.assertEquals("Jour de l'an", calendar.getHolidays().get(0).getName());
        Assert.assertNotNull(calendar.getHolidays().get(0).getDate());

        // Check default business hours
        Assert.assertEquals(1, configuration.getBusinessHours().size());
        Assert.assertEquals(8 * DateUtils.MILLIS_PER_HOUR, configuration.getBusinessHours().get(0).getStart());
        Assert.assertEquals(18 * DateUtils.MILLIS_PER_HOUR, configuration.getBusinessHours().get(0).getEnd());

        em.flush();
        em.clear();
        Assert.assertEquals(1, subscriptionRepository.findAllByProject(project.getId()).size());
    }
项目:plugin-bt    文件:BugTrackerResourceTest.java   
@Test
public void addBusinessHoursOverlapsStart() {
    thrown.expect(ValidationJsonException.class);
    thrown.expect(MatcherUtil.validationMatcher("start", "Overlap"));

    final BusinessHoursEditionVo vo = new BusinessHoursEditionVo();
    vo.setStart(10 * DateUtils.MILLIS_PER_HOUR);
    vo.setEnd(23 * DateUtils.MILLIS_PER_HOUR);
    vo.setSubscription(subscription);
    em.flush();
    em.clear();
    resource.addBusinessHours(vo);
}
项目:plugin-bt    文件:SlaProcessorTest.java   
/**
 * The due date is before the end of the first pause but after its start.
 */
@Test
public void processRevisedDueDateMiddle() {
    final List<ChangeItem> changes = new ArrayList<>();
    final Date dueDate = getDate(2014, 07, 21, 0, 0, 5);
    changes.add(newChangeItem(1, 3, 0, dueDate)); // Ignored pause since timer is not started
    changes.add(newChangeItem(3, 2, 1, dueDate)); // Start [2s]
    changes.add(newChangeItem(2, 3, 2, dueDate)); // Pause
    changes.add(newChangeItem(3, 4, 3, dueDate)); // Restart [2s]
    changes.add(newChangeItem(4, 5, 4, dueDate)); // Pause
    changes.add(newChangeItem(5, 7, 5, dueDate)); // Ignored, continue pause
    changes.add(newChangeItem(7, 8, 6, dueDate)); // Ignored, continue pause
    changes.add(newChangeItem(8, 3, 7, dueDate)); // Pause, same state
    changes.add(newChangeItem(3, 4, 8, dueDate)); // Restart [2s]
    changes.add(newChangeItem(4, 7, 9, dueDate)); // Ignored, continue timer [2s]
    changes.add(newChangeItem(7, 6, 10, dueDate)); // Stopped
    changes.add(newChangeItem(6, 7, 11, dueDate)); // Ignored
    changes.add(newChangeItem(7, 5, 12, dueDate)); // Ignored pause since timer is not started

    final List<Sla> slas = newSla();
    final SlaComputations process = processor.process(new ArrayList<>(), changes, new ArrayList<>(), slas);
    Assert.assertEquals(1, process.getIssues().size());
    Assert.assertEquals(1, process.getSlaConfigurations().size());
    final IssueSla issueSla = process.getIssues().get(0);
    Assert.assertEquals(1, issueSla.getData().size());
    final SlaData slaData = issueSla.getData().get(0);
    Assert.assertEquals(8000, slaData.getDuration());
    Assert.assertEquals(dueDate, issueSla.getDueDate());

    // Due date shift : 4 seconds
    Assert.assertEquals(getDate(2014, 07, 21, 0, 0, 7), slaData.getRevisedDueDate());
    Assert.assertEquals(getDate(2014, 07, 21, 0, 0, 2), slaData.getStart());
    Assert.assertEquals(getDate(2014, 07, 21, 0, 0, 20), slaData.getStop());
    Assert.assertEquals(-(20 - 7) * DateUtils.MILLIS_PER_SECOND, slaData.getRevisedDueDateDistance().longValue());
}
项目:metanome-algorithms    文件:TypeInferrer.java   
private boolean isDate(final String value) {
  try {
    DateUtils.parseDate(value, TypeInferrer.dateFormats);
  } catch (final ParseException e) {
    // none of the date format patterns in dateFormats could be matched
    return false;
  }
  return true;
}
项目:metanome-algorithms    文件:ORDER.java   
private void storeData(final long tupleId, final List<String> currentRow, final int column)
    throws ParseException {

  final String stringValue = currentRow.get(column);
  switch (this.types.get(column).getSpecificType()) {
    case DOUBLE:
      final Double doubleValue = (stringValue == null) ? null : Double.parseDouble(stringValue);
      this.dataByColumns.get(column).add(new RowIndexedDoubleValue(tupleId, doubleValue));
      break;
    case DATE:
      final Date dateValue =
      (stringValue == null) ? null : DateUtils.parseDate(stringValue,
          TypeInferrer.dateFormats);
      this.dataByColumns.get(column).add(new RowIndexedDateValue(tupleId, dateValue));
      break;
    case LONG:
      final Long longValue = (stringValue == null) ? null : Long.parseLong(stringValue);
      this.dataByColumns.get(column).add(new RowIndexedLongValue(tupleId, longValue));
      break;
    case STRING:
      this.dataByColumns.get(column).add(new RowIndexedStringValue(tupleId, stringValue));
      break;
    default:
      this.dataByColumns.get(column).add(new RowIndexedStringValue(tupleId, stringValue));
      break;
  }
}
项目:FHIR-CQL-ODM-service    文件:FhirServerTestConfigDstu3.java   
/**
 * Configure FHIR properties around the the JPA server via this bean
 */
@Bean
public DaoConfig daoConfig() {
    DaoConfig retVal = new DaoConfig();
    retVal.setSubscriptionEnabled(true);
    retVal.setSubscriptionPollDelay(5000);
    retVal.setSubscriptionPurgeInactiveAfterMillis(DateUtils.MILLIS_PER_HOUR);
    retVal.setAllowMultipleDelete(true);
    return retVal;  
}