Search in sources :

Example 11 with LocalDateTime

use of org.joda.time.LocalDateTime in project ninja by ninjaframework.

the class PrettyTimeController method index.

public Result index(Context context) {
    // Only render the page. It contains some language specific strings.
    // It will use the requested language (or a fallback language)
    // from Accept-Language header
    Result result = Results.html();
    // just in case we set the language => we remove it...
    lang.clearLanguage(result);
    // 25 works for summertime, too.
    LocalDateTime localDateTime = LocalDateTime.now().minusHours(25);
    result.render("date", new Date(localDateTime.toDateTime().getMillis()));
    return result;
}
Also used : LocalDateTime(org.joda.time.LocalDateTime) Date(java.util.Date) Result(ninja.Result)

Example 12 with LocalDateTime

use of org.joda.time.LocalDateTime in project querydsl by querydsl.

the class LocalDateTimeType method setValue.

@Override
public void setValue(PreparedStatement st, int index, LocalDateTime value) throws SQLException {
    DateTime dt = value.toDateTime(DateTimeZone.UTC);
    st.setTimestamp(index, new Timestamp(dt.getMillis()), utc());
}
Also used : DateTime(org.joda.time.DateTime) LocalDateTime(org.joda.time.LocalDateTime)

Example 13 with LocalDateTime

use of org.joda.time.LocalDateTime in project spring-framework by spring-projects.

the class JodaTimeFormattingTests method testBindLocalDateTimeAnnotated.

@Test
public void testBindLocalDateTimeAnnotated() {
    MutablePropertyValues propertyValues = new MutablePropertyValues();
    propertyValues.add("localDateTimeAnnotated", new LocalDateTime(2009, 10, 31, 12, 0));
    binder.bind(propertyValues);
    assertEquals(0, binder.getBindingResult().getErrorCount());
    String value = binder.getBindingResult().getFieldValue("localDateTimeAnnotated").toString();
    assertTrue(value.startsWith("Oct 31, 2009"));
    assertTrue(value.endsWith("12:00 PM"));
}
Also used : LocalDateTime(org.joda.time.LocalDateTime) MutablePropertyValues(org.springframework.beans.MutablePropertyValues) Test(org.junit.Test)

Example 14 with LocalDateTime

use of org.joda.time.LocalDateTime in project Settler by EmhyrVarEmreis.

the class ImportService method importTransactions.

public void importTransactions(MultipartFile file) throws IOException {
    List<Category> categoryList = categoryRepository.findAll();
    Map<String, Category> categoryMap = categoryList == null ? new HashMap<>() : categoryList.stream().collect(Collectors.toMap(Category::getCode, category -> category));
    List<Transaction> transactionList = new ArrayList<>();
    ByteArrayInputStream stream = new ByteArrayInputStream(file.getBytes());
    String content = IOUtils.toString(stream, "UTF-8");
    String[] lines = content.split("\\r?\\n");
    DateTimeFormatter dateTimeFormatter = DateTimeFormat.forPattern("dd.MM.yyyy");
    User o = userRepository.findOneByLogin(splitLine(lines[0])[26]);
    User c = userRepository.findOneByLogin(splitLine(lines[0])[27]);
    int ln = 0;
    for (String line : lines) {
        ln++;
        if (ln < 3) {
            continue;
        }
        try {
            String[] cells = splitLine(line);
            String name = cells[0];
            String mark = cells[4].trim();
            Double value;
            Double sharedAValue;
            Double sharedBValue;
            Integer sharedA;
            Integer sharedB;
            LocalDateTime date;
            Boolean normal;
            Transaction transaction = new Transaction();
            List<Redistribution> owners = new ArrayList<>();
            List<Redistribution> contractors = new ArrayList<>();
            value = Double.valueOf(cells[2].replaceAll("[^0-9^,-]+", "").replace(",", "."));
            date = dateTimeFormatter.parseLocalDateTime(cells[1]);
            sharedA = cells.length < 7 || cells[5].trim().isEmpty() ? -1 : Integer.valueOf(cells[5].trim());
            sharedB = cells.length < 7 || cells[6].trim().isEmpty() ? -1 : Integer.valueOf(cells[6].trim());
            normal = value > 0;
            value = Math.abs(value);
            if (mark.equalsIgnoreCase("x")) {
                if (sharedA < 0 || sharedB < 0) {
                    sharedA = 1;
                    sharedB = 2;
                }
            } else if (mark.equalsIgnoreCase("b") || mark.equalsIgnoreCase("z")) {
                sharedA = 1;
                sharedB = 1;
            } else {
                continue;
            }
            sharedAValue = value;
            value = (value / (sharedA)) * sharedB;
            value = (double) Math.round(value * 100) / 100;
            sharedBValue = value - sharedAValue;
            sharedBValue = (double) Math.round(sharedBValue * 100) / 100;
            if (normal) {
                owners.add(new Redistribution(RedistributionType.O, transaction, o, value));
                if (sharedBValue > 0) {
                    contractors.add(new Redistribution(RedistributionType.C, transaction, o, sharedBValue));
                }
                contractors.add(new Redistribution(RedistributionType.C, transaction, c, sharedAValue));
            } else {
                owners.add(new Redistribution(RedistributionType.O, transaction, c, value));
                contractors.add(new Redistribution(RedistributionType.C, transaction, o, sharedAValue));
                if (sharedBValue > 0) {
                    contractors.add(new Redistribution(RedistributionType.C, transaction, c, sharedBValue));
                }
            }
            transaction.setValue(value);
            owners.forEach(redistribution -> redistribution.setPercentage(redistribution.getPercentage() / 1.0 / transaction.getValue()));
            contractors.forEach(redistribution -> redistribution.setPercentage(redistribution.getPercentage() / 1.0 / transaction.getValue()));
            transaction.setOwners(owners);
            transaction.setContractors(contractors);
            date = date.withHourOfDay(12).withMinuteOfHour(0).withSecondOfMinute(0);
            transaction.setCreator(Security.currentUser());
            transaction.setType(TransactionType.NOR);
            transaction.setDescription(name);
            transaction.setEvaluated(date);
            List<Category> cl = checkCategories(transaction.getDescription()).stream().map(categoryMap::get).filter(Objects::nonNull).collect(Collectors.toList());
            transaction.setCategories(cl.isEmpty() ? null : cl);
            transaction.setReference(sequenceManager.getNextReferenceForTransaction(transaction));
            transactionList.add(transaction);
        } catch (Exception e) {
            log.warn("Unable to convert line No{}: {}", ln, line, e);
        }
    }
    transactionList.sort((o1, o2) -> o1.getEvaluated().compareTo(o2.getCreated()));
    transactionList.forEach(t -> {
        t.setCreated(new LocalDateTime());
        log.info(t.getEvaluated() + " " + t.getReference() + " " + t.getValue() + " [" + t.getDescription() + "]" + " [" + t.getOwners().stream().map(r -> r.getId().getUser().getLogin() + "/" + r.getPercentage()).collect(Collectors.joining(", ")) + "]" + " [" + t.getContractors().stream().map(r -> r.getId().getUser().getLogin() + "/" + r.getPercentage()).collect(Collectors.joining(", ")) + "]" + " [" + (t.getCategories() == null ? "" : t.getCategories().stream().map(Category::getCode).collect(Collectors.joining(", "))) + "]");
        transactionRepository.save(t);
    });
}
Also used : LocalDateTime(org.joda.time.LocalDateTime) TransactionType(pl.morecraft.dev.settler.domain.dictionaries.TransactionType) java.util(java.util) LoggerFactory(org.slf4j.LoggerFactory) Autowired(org.springframework.beans.factory.annotation.Autowired) Category(pl.morecraft.dev.settler.domain.Category) ByteArrayInputStream(java.io.ByteArrayInputStream) Transaction(pl.morecraft.dev.settler.domain.Transaction) Gson(com.google.gson.Gson) Service(org.springframework.stereotype.Service) UserRepository(pl.morecraft.dev.settler.dao.repository.UserRepository) Qualifier(org.springframework.beans.factory.annotation.Qualifier) CategoryRepository(pl.morecraft.dev.settler.dao.repository.CategoryRepository) RedistributionType(pl.morecraft.dev.settler.domain.dictionaries.RedistributionType) DateTimeFormat(org.joda.time.format.DateTimeFormat) User(pl.morecraft.dev.settler.domain.User) Logger(org.slf4j.Logger) DateTimeFormatter(org.joda.time.format.DateTimeFormatter) Security(pl.morecraft.dev.settler.security.util.Security) IOException(java.io.IOException) LocalDateTime(org.joda.time.LocalDateTime) Collectors(java.util.stream.Collectors) TransactionRepository(pl.morecraft.dev.settler.dao.repository.TransactionRepository) IOUtils(org.apache.commons.io.IOUtils) MultipartFile(org.springframework.web.multipart.MultipartFile) Redistribution(pl.morecraft.dev.settler.domain.Redistribution) Transactional(org.springframework.transaction.annotation.Transactional) Category(pl.morecraft.dev.settler.domain.Category) User(pl.morecraft.dev.settler.domain.User) IOException(java.io.IOException) Redistribution(pl.morecraft.dev.settler.domain.Redistribution) Transaction(pl.morecraft.dev.settler.domain.Transaction) ByteArrayInputStream(java.io.ByteArrayInputStream) DateTimeFormatter(org.joda.time.format.DateTimeFormatter)

Example 15 with LocalDateTime

use of org.joda.time.LocalDateTime in project joda-time by JodaOrg.

the class TestDateTimeFormatter method testParseLocalDateTime_monthDay_feb29.

public void testParseLocalDateTime_monthDay_feb29() {
    Chronology chrono = GJChronology.getInstanceUTC();
    DateTimeFormatter f = DateTimeFormat.forPattern("M d H m").withChronology(chrono).withLocale(Locale.UK);
    assertEquals(new LocalDateTime(2000, 2, 29, 13, 40, 0, 0, chrono), f.parseLocalDateTime("2 29 13 40"));
}
Also used : LocalDateTime(org.joda.time.LocalDateTime) Chronology(org.joda.time.Chronology) GJChronology(org.joda.time.chrono.GJChronology) ISOChronology(org.joda.time.chrono.ISOChronology) BuddhistChronology(org.joda.time.chrono.BuddhistChronology)

Aggregations

LocalDateTime (org.joda.time.LocalDateTime)66 Test (org.junit.Test)35 DateTime (org.joda.time.DateTime)15 Interval (org.joda.time.Interval)12 LocalDate (org.joda.time.LocalDate)11 ArrayList (java.util.ArrayList)5 Date (java.util.Date)5 ApplianceLogger (de.avanux.smartapplianceenabler.log.ApplianceLogger)4 BigDecimal (java.math.BigDecimal)4 BigInteger (java.math.BigInteger)4 DateTimeZone (org.joda.time.DateTimeZone)4 Person (org.qi4j.test.indexing.model.Person)4 HashMap (java.util.HashMap)3 Chronology (org.joda.time.Chronology)3 LocalTime (org.joda.time.LocalTime)3 de.avanux.smartapplianceenabler.appliance (de.avanux.smartapplianceenabler.appliance)2 BuddhistChronology (org.joda.time.chrono.BuddhistChronology)2 GJChronology (org.joda.time.chrono.GJChronology)2 ISOChronology (org.joda.time.chrono.ISOChronology)2 DateTimeFormatter (org.joda.time.format.DateTimeFormatter)2