Example usage for org.joda.time.format DateTimeFormat forPattern

List of usage examples for org.joda.time.format DateTimeFormat forPattern

Introduction

In this page you can find the example usage for org.joda.time.format DateTimeFormat forPattern.

Prototype

public static DateTimeFormatter forPattern(String pattern) 

Source Link

Document

Factory to create a formatter from a pattern string.

Usage

From source file:com.hotwire.test.steps.tools.c3.search.C3SearchModel.java

License:Open Source License

public void verifyCustomerType() {
    String type = customerInfo.getCustomerType().toString();
    CustomerInfo profile = customerProfiles.get(type);
    assertThat(profile.getAccountType())
            .isEqualTo(new C3CustomerInfoFragment(getWebdriverInstance()).getAccountType());
    LOGGER.info("Customer Type: OK");
    assertThat(profile.getWatermark())//from  w w  w.j a  va  2 s . c  o  m
            .isEqualTo(new C3CustomerInfoFragment(getWebdriverInstance()).getWatermark());
    LOGGER.info("Customer Watermark: OK");

    verifyBreadCrumbs(profile.getBreadcrumbs());
    switch (customerInfo.getCustomerType()) {
    case PARTNER:
        LOGGER.info("Partner purchase");
        break;
    case EX_EXPRESS:
        LOGGER.info("Former express customer purchase");
        final String expressProgramStatus = new C3CustomerInfoFragment(getWebdriverInstance())
                .getExpressProgramStatus();
        assertThat(expressProgramStatus).contains("Former");
        String timestamp = expressProgramStatus.replaceFirst("^.*\\(", "").replaceFirst("\\)$", "");
        DateTime parsedTimestamp = DateTimeFormat.forPattern("dd-MMM-yy h:mm a")
                .parseDateTime(timestamp.replace(" at", ""));
        //Assert that timestamp that is displayed in C3 not differs timestamp
        // from DB or differs in 5 seconds range
        assertThat(Math.abs(parsedTimestamp.getMillis() - customerInfo.getExpressDownGradeDate().getMillis())
                / 10000).isLessThanOrEqualTo(5);
        break;
    default:
        assertThat(profile.getExpressProgram())
                .isEqualTo(new C3CustomerInfoFragment(getWebdriverInstance()).getExpressProgramStatus());
    }
    LOGGER.info("Express Program: OK");

}

From source file:com.hotwire.test.steps.tools.c3.search.C3SearchModel.java

License:Open Source License

public void verifyStarRatingChange() {
    final C3HotelStarRatingPage c3HotelStarRatingPage = new C3HotelStarRatingPage(getWebdriverInstance());
    if (c3HotelSupplyInfo.isRatingChanged()) {
        assertThat(DateTimeFormat.forPattern("d MMM YYYY")
                .parseDateTime(c3HotelStarRatingPage.getLastRatingChange()))
                        .isEqualTo(c3HotelSupplyInfo.getLastRatingChange());
        assertThat(c3HotelStarRatingPage.getRatingChange()).isNotEqualTo(UNAVAILABLE);
        c3HotelStarRatingPage.verifyRatingChangeFragment();
    } else {//from  w w w.j  a  v  a2 s  .  c o m
        assertThat(c3HotelStarRatingPage.getLastRatingChange()).isEqualTo(UNAVAILABLE);
        assertThat(c3HotelStarRatingPage.getRatingChange()).contains(UNAVAILABLE);
    }
}

From source file:com.hp.autonomy.frontend.find.idol.search.IdolDocumentService.java

License:MIT License

private String formatDate(final ReadableInstant date) {
    return date == null ? null : DateTimeFormat.forPattern(IDOL_DATE_PARAMETER_FORMAT).print(date);
}

From source file:com.hp.autonomy.searchcomponents.idol.search.HavenSearchAciParameterHandlerImpl.java

License:MIT License

protected String formatDate(final ReadableInstant date) {
    return date == null ? null : DateTimeFormat.forPattern(IDOL_DATE_PARAMETER_FORMAT).print(date);
}

From source file:com.huang.rp.common.utils.TimeUtils.java

License:Apache License

/**
 * ?DateTime//ww w.  j a v  a2s.  co  m
 * @param dateStr
 * @return
 */
public static DateTime getDateTime(String dateStr) {
    if (dateStr.matches(yyyyMMddFormtterRegex)) {
        return DateTime.parse(dateStr, DateTimeFormat.forPattern(yyyyMMddFormtter));
    } else if (dateStr.matches(yyyyMMddHHmmssFormtterRegex)) {
        return DateTime.parse(dateStr, DateTimeFormat.forPattern(yyyMMddHHmmssFormtter));
    }
    return null;
}

From source file:com.hula.lang.util.DateUtil.java

License:Apache License

/**
 * Convert a Date into a String//  w  w w  . j a v a2  s  .c o m
 * 
 * @param date The date to convert
 * @param format The format of the Date
 * @return A string containing the datre
 */
public static String toString(Date date, String format) {
    DateTimeFormatter fmt = DateTimeFormat.forPattern(format);
    return fmt.print(date.getTime());
}

From source file:com.hula.lang.util.DateUtil.java

License:Apache License

/**
 * Convert a String into a Date//from   www  .ja v a 2 s .  c  o  m
 * 
 * @param string The string to convert
 * @param format The format of the String
 * @return A Date
 */
public static Date toDate(String string, String format) {
    DateTimeFormatter fmt = DateTimeFormat.forPattern(format);
    DateTime dt = fmt.parseDateTime(string);
    return dt.toDate();
}

From source file:com.ideaspymes.tesakaplugin.importacion.jpa.RetencionGenerada.java

public RetencionGenerada(Datos d, RecepcionImp r) {

    this.uuid = d.getAtributos().getUuid();

    this.fechaCreacion = LocalDate
            .parse(d.getAtributos().getFechaCreacion(), DateTimeFormat.forPattern("yyyy-MM-dd")).toDate();
    this.fechaHoraCreacion = DateTime
            .parse(d.getAtributos().getFechaHoraCreacion(), DateTimeFormat.forPattern("yyyy-MM-dd HH:mm:ss"))
            .toDate();//from   ww  w. ja  va 2 s  .c  om

    this.codigoEstablecimiento = d.getInformante().getCodigoEstablecimiento();
    this.timbradoComprobante = d.getInformante().getTimbradoComprobante();
    this.puntoExpedicionComprobante = d.getInformante().getPuntoExpedicionComprobante();
    this.establecimiento = d.getInformante().getEstablecimiento();

    this.condicionCompra = d.getTransaccion().getCondicionCompra();
    this.tipoComprobante = d.getTransaccion().getTipoComprobante();
    this.numeroTimbradoFactura = d.getTransaccion().getNumeroTimbrado();
    this.numeroComprobanteVenta = d.getTransaccion().getNumeroComprobanteVenta();
    this.fechaFactura = LocalDate.parse(d.getTransaccion().getFecha(), DateTimeFormat.forPattern("yyyy-MM-dd"))
            .toDate();
    this.proveedorRuc = d.getInformado().getRuc();
    this.proveedorDv = d.getInformado().getDv();
    this.proveedorNombre = d.getInformado().getNombre();
    this.proveedorTipoIdentificacion = d.getInformado().getTipoIdentificacionNombre();
    this.proveedorIdentificacion = d.getInformado().getIdentificacion();
    this.proveedorSituacion = d.getInformado().getSituacion();
    this.proveedorCorreo = d.getInformado().getCorreoElectronico();
    this.proveedorDomicilio = d.getInformado().getDomicilio() == null ? d.getInformado().getDireccion()
            : d.getInformado().getDomicilio();

    Double total = 0d;
    for (DetalleImp dt : d.getDetalle()) {
        total += (dt.getPrecioUnitario() * dt.getCantidad());
    }

    this.totalFactura = total;

    this.fechaRetencion = LocalDate.parse(d.getRetencion().getFecha(), DateTimeFormat.forPattern("yyyy-MM-dd"))
            .toDate();
    this.moneda = d.getRetencion().getMoneda();
    this.tipoCambio = d.getRetencion().getTipoCambio();
    this.retencionIva = d.getRetencion().getRetencionIva();
    this.retencionRenta = d.getRetencion().getRetencionRenta();
    this.conceptoRenta = d.getRetencion().getConceptoRenta();
    this.conceptoIva = d.getRetencion().getConceptoIva();
    this.habilitadoRentaCabezas = d.getRetencion().getHabilitadoRentaCabezas();
    this.habilitadoRentaToneladas = d.getRetencion().getHabilitadoRentaToneladas();
    this.ivaBase5 = d.getRetencion().getIvaBase5();
    this.ivaTotal5 = d.getRetencion().getIvaTotal5();
    this.ivaBase10 = d.getRetencion().getIvaBase10();
    this.ivaTotal10 = d.getRetencion().getIvaTotal10();
    this.ivaTotal = d.getRetencion().getIvaTotal();
    this.rentaBase = d.getRetencion().getRentaBase();
    this.rentaTotal = d.getRetencion().getRentaTotal();
    this.rentaCabezasBase = d.getRetencion().getRentaCabezasBase();
    this.rentaCabezasCantidad = d.getRetencion().getRentaCabezasCantidad();
    this.rentaCabezasTotal = d.getRetencion().getRentaCabezasTotal();
    this.rentaToneladasBase = d.getRetencion().getRentaToneladasBase();
    this.rentaToneladasCantidad = d.getRetencion().getRentaToneladasCantidad();
    this.rentaToneladasTotal = d.getRetencion().getRentaToneladasTotal();
    this.retencionIvaTotal = d.getRetencion().getRetencionIvaTotal();
    this.retencionRentaTotal = d.getRetencion().getRetencionRentaTotal();
    this.retencionTotal = d.getRetencion().getRetencionTotal();
    this.rentaPorcentaje = d.getRetencion().getRentaPorcentaje();
    this.conceptoIvaNombre = d.getRetencion().getConceptoIvaNombre();
    this.conceptoRentaNombre = d.getRetencion().getConceptoRentaNombre();
    this.ivaPorcentaje5 = d.getRetencion().getIvaPorcentaje5();
    this.ivaPorcentaje10 = d.getRetencion().getIvaPorcentaje10();
    this.monedaNombre = d.getRetencion().getMonedaNombre();
    //totales
    this.impuestoTotalExento = d.getTotales().getImpuestoTotalExento();
    this.impuestoTotalAl5 = d.getTotales().getImpuestoTotalAl5();
    this.impuestoTotalAl10 = d.getTotales().getImpuestoTotalAl10();
    this.valorTotalExento = d.getTotales().getValorTotalExento();
    this.valorTotalAl5 = d.getTotales().getValorTotalAl5();
    this.valorTotalAl10 = d.getTotales().getValorTotalAl10();
    this.impuestoTotal = d.getTotales().getImpuestoTotal();
    this.valorTotal = d.getTotales().getValorTotal();

    String[] anumero = r.getNumeroComprobante().split("-");

    this.fechaProceso = DateTime.parse(r.getFechaProceso(), DateTimeFormat.forPattern("yyyy-MM-dd'T'HH:mm:SSS"))
            .toDate();
    this.numeroComprobante = anumero[2];
    this.fechaEmision = LocalDate.parse(r.getFechaEmision(), DateTimeFormat.forPattern("yyyy-MM-dd")).toDate();
    this.cadenaControl = r.getCadenaControl();
    this.numero = anumero[2];
    this.fechaRecepcion = DateTime
            .parse(r.getFechaRecepcion(), DateTimeFormat.forPattern("yyyy-MM-dd'T'HH:mm:SSS")).toDate();
    this.hashString = r.getHash();
    this.recepcionCorrecta = r.getRecepcionCorrecta();
    this.mensajeRecepcion = r.getMensajeRecepcion();
    this.procesamientoCorrecto = r.getProcesamientoCorrecto();
    this.mensajeProcesamiento = r.getMensajeProcesamiento();
    this.migrado = false;
}

From source file:com.ikon.servlet.RepositoryStartupServlet.java

License:Open Source License

/**
 * Start openkm and possible repository and database initialization
 *//*from   w  w  w  .j ava2s .  c  om*/
public static synchronized void start() throws ServletException {
    SystemAuthentication systemAuth = new SystemAuthentication();

    if (running) {
        throw new IllegalStateException("openkm already started");
    }

    try {
        log.info("*** Repository initializing... ***");

        if (Config.REPOSITORY_NATIVE) {
            systemAuth.enable();
            DbRepositoryModule.initialize();
            systemAuth.disable();
        } else {
            JcrRepositoryModule.initialize();
        }

        log.info("*** Repository initialized ***");
    } catch (Exception e) {
        throw new ServletException(e.getMessage(), e);
    }

    if (Config.USER_ITEM_CACHE) {
        // Deserialize
        try {
            log.info("*** Cache deserialization ***");
            UserItemsManager.deserialize();
            UserNodeKeywordsManager.deserialize();
        } catch (DatabaseException e) {
            log.warn(e.getMessage(), e);
        }
    }

    log.info("*** User database initialized ***");

    if (!Config.REPOSITORY_NATIVE) {
        // Test for datastore
        SessionImpl si = (SessionImpl) JcrRepositoryModule.getSystemSession();

        if (((RepositoryImpl) si.getRepository()).getDataStore() == null) {
            hasConfiguredDataStore = false;
        } else {
            hasConfiguredDataStore = true;
        }
    }

    // Create timers
    uiTimer = new Timer("Update Info", true);
    cronTimer = new Timer("Crontab Manager", true);
    uinTimer = new Timer("User Interface Notification", true);

    // Workflow
    log.info("*** Initializing workflow engine... ***");
    JbpmContext jbpmContext = JBPMUtils.getConfig().createJbpmContext();
    jbpmContext.setSessionFactory(HibernateUtil.getSessionFactory());
    jbpmContext.getGraphSession();
    jbpmContext.getJbpmConfiguration().getJobExecutor().start(); // startJobExecutor();
    jbpmContext.close();

    // Mime types
    log.info("*** Initializing MIME types... ***");
    MimeTypeConfig.loadMimeTypes();

    if (Config.UPDATE_INFO) {
        log.info("*** Activating update info ***");
        ui = new UpdateInfo();
        uiTimer.schedule(ui, 1000, 24 * 60 * 60 * 1000); // First in 1 seg, next each 24 hours
    }

    log.info("*** Activating cron ***");
    cron = new Cron();
    Calendar calCron = Calendar.getInstance();
    calCron.add(Calendar.MINUTE, 1);
    calCron.set(Calendar.SECOND, 0);
    calCron.set(Calendar.MILLISECOND, 0);

    // Round begin to next minute, 0 seconds, 0 miliseconds
    cronTimer.scheduleAtFixedRate(cron, calCron.getTime(), 60 * 1000); // First in 1 min, next each 1 min

    log.info("*** Activating UI Notification ***");
    uin = new UINotification();

    //Licensing stuff
    if (Config.HIBERNATE_HBM2DDL.equals("create")) {
        if (!LICENSE_PATH.exists()) {
            try {
                FileUtils.writeStringToFile(LICENSE_PATH,
                        new DateTime().plusDays(30).toString(DateTimeFormat.forPattern("d MMM yyyy")));
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }

    // First in 1 second next in x minutes
    uinTimer.scheduleAtFixedRate(uin, 1000, TimeUnit.MINUTES.toMillis(Config.SCHEDULE_UI_NOTIFICATION));

    try {
        // General maintenance works
        String uisContent = "com.ikon.cache.UserItemsManager.serialize();";
        CronTabUtils.createOrUpdate("User Items Serialize", "@hourly", uisContent);

        String umiContent = "new com.ikon.core.UserMailImporter().run();";
        CronTabUtils.createOrUpdate("User Mail Importer", "*/30 * * * *", umiContent);

        String tewContent = "new com.ikon.extractor.TextExtractorWorker().run();";
        CronTabUtils.createOrUpdate("Text Extractor Worker", "*/5 * * * *", tewContent);

        String riContent = "new com.ikon.core.RepositoryInfo().run();";
        CronTabUtils.createOrUpdate("Repository Info", "@daily", riContent);

        String swdContent = "new com.ikon.core.Watchdog().run();";
        CronTabUtils.createOrUpdate("Session Watchdog", "*/5 * * * *", swdContent);

        if (LicenseManager.getInstance().getFeature("Retention").equals("RET761WER")) {
            String retentionContent = "new com.ikon.util.RetentionPolicyTimer().run();";
            CronTabUtils.createOrUpdate("Retention Policies", "* */10 * * *", retentionContent);
        }

        String hotFolderContent = "new com.ikon.util.HotFolderTimer().run();";
        CronTabUtils.createOrUpdate("Hot Folders", "* */10 * * *", hotFolderContent);
        // Datastore garbage collection
        if (!Config.REPOSITORY_NATIVE && hasConfiguredDataStore) {
            String dgcContent = "new com.ikon.module.jcr.stuff.DataStoreGarbageCollector().run();";
            CronTabUtils.createOrUpdate("Datastore Garbage Collector", "@daily", dgcContent);
        }

    } catch (Exception e) {
        log.warn(e.getMessage(), e);
    }

    try {
        log.info("*** Activating thesaurus repository ***");
        RDFREpository.getInstance();
    } catch (Exception e) {
        log.warn(e.getMessage(), e);
    }

    try {
        if (!Config.SYSTEM_OPENOFFICE_PATH.equals("")) {
            log.info("*** Start OpenOffice manager ***");
            DocConverter.getInstance().start();
        } else {
            log.warn("*** No OpenOffice manager configured ***");
        }
    } catch (Throwable e) {
        log.warn(e.getMessage(), e);
    }

    // Initialize plugin framework
    ExtensionManager.getInstance();

    try {
        log.info("*** Ejecute start script ***");
        File script = new File(Config.HOME_DIR + File.separatorChar + Config.START_SCRIPT);
        ExecutionUtils.runScript(script);
        File jar = new File(Config.HOME_DIR + File.separatorChar + Config.START_JAR);
        ExecutionUtils.getInstance().runJar(jar);
    } catch (Throwable e) {
        log.warn(e.getMessage(), e);
    }

    // openkm is started
    running = true;
}

From source file:com.ikon.servlet.ValidateLicenseServlet.java

private int remainingDays() {
    DateTimeFormatter formatter = DateTimeFormat.forPattern("d MMM yyyy");
    DateTime expiryDate = null;/*from w  w  w.  j  ava 2s  .c o m*/
    try {
        expiryDate = formatter.parseDateTime(FileUtils.readFileToString(LICENSE_PATH));
    } catch (IOException e) {
        e.printStackTrace();
    }
    return Days.daysBetween(new DateTime(), expiryDate).getDays();
}