Example usage for org.joda.time DateTime toString

List of usage examples for org.joda.time DateTime toString

Introduction

In this page you can find the example usage for org.joda.time DateTime toString.

Prototype

public String toString(String pattern) 

Source Link

Document

Output the instant using the specified format pattern.

Usage

From source file:graphene.web.components.JodaTimeOutput.java

License:Apache License

private String format(Object value) {
    String formatted = "";

    if (value != null) {

        // If value is an AbstractInstant - includes DateTime and
        // DateMidnight
        if (value instanceof Long) {
            DateTime d = new DateTime((long) value);
            if (style != null) {
                formatted = DateTimeFormat.forStyle(style).print(d);
            } else if (formatter != null) {
                formatted = d.toString(formatter);
            } else if (pattern != null) {
                formatted = DateTimeFormat.forPattern(pattern).print(d);
            } else {
                formatted = value.toString();
            }/*from ww  w  .j a  v a 2s .c o  m*/
        } else if (value instanceof AbstractInstant) {
            AbstractInstant ai = ((AbstractInstant) value);
            if (style != null) {
                formatted = DateTimeFormat.forStyle(style).print(ai);
            } else if (formatter != null) {
                formatted = ai.toString(formatter);
            } else if (pattern != null) {
                formatted = DateTimeFormat.forPattern(pattern).print(ai);
            } else {
                formatted = value.toString();
            }
        }

        // Else if value is an AbstractPartial - includes LocalDate,
        // LocalTime,
        // LocalDateTime, YearMonthDay, and TimeOfDay

        else if (value instanceof AbstractPartial) {
            AbstractPartial ap = ((AbstractPartial) value);
            if (style != null) {
                formatted = DateTimeFormat.forStyle(style).print(ap);
            } else if (formatter != null) {
                formatted = ap.toString(formatter);
            } else if (pattern != null) {
                formatted = DateTimeFormat.forPattern(pattern).print(ap);
            } else {
                formatted = value.toString();
            }
        }

        // Else value is an unsupported type

        else {
            throw new IllegalArgumentException(
                    "JodaTimeOutput received a value of the wrong type.  Supported types are subclasses of AbstractInstant and AbstractPartial or instances of Long.  Type found is "
                            + value.getClass().getName() + ".");
        }
    }

    return formatted;
}

From source file:Implement.Service.AdminServiceImpl.java

@Override
public boolean approveTemporaryPackage(int packageID) throws Exception {
    DateTime now = new DateTime();
    String startDateStr = now.toString("MM/dd/yyyy");
    int newPackageID = packageDAO.approveTemporaryPackage(packageID, startDateStr);
    //Insert create image folder
    String path = System.getProperty("catalina.base");
    File folderPackage = new File(path + "/webapps/Images/TemporaryPackages/" + packageID);
    if (!folderPackage.exists()) {
        folderPackage.mkdirs();//  w  w w. j a  v  a  2s . c o m
    }

    //Copy image to new folder
    File sourceImageFolder = new File(path + "/webapps/Images/PrimaryPackages/" + newPackageID);
    if (!sourceImageFolder.exists()) {
        sourceImageFolder.mkdirs();
    }

    FileUtils.copyDirectory(folderPackage, sourceImageFolder);
    folderPackage.delete();
    //Update database
    for (final File fileEntry : sourceImageFolder.listFiles()) {
        String fileName = fileEntry.getName();
        String fileExtension = fileName.substring(fileName.lastIndexOf(".") + 1);
        if (fileName.contains("cover")) {
            packageDAO.updateCoverAfterApprove(newPackageID,
                    "/Images/PrimaryPackages/" + newPackageID + "/cover." + fileExtension);
        } else {
            packageDAO.updateAdditionalAfterApprove(newPackageID, "%" + fileName + "%",
                    "/Images/PrimaryPackages/" + newPackageID + "/" + fileName);
        }
    }
    return true;
}

From source file:Implement.Service.CommonServiceImpl.java

@Override
public String getToDateUnderFormatMMddyyyy() {
    DateTime toDateObj = new DateTime();
    String toDate = toDateObj.toString("MM/dd/yyyy");
    return toDate;
}

From source file:Implement.Service.ProviderServiceImpl.java

@Override
public String insertNewOfflineAndReturnNewList(String data, int providerID) {
    JsonObject jsonObject = gson.fromJson(data, JsonObject.class);
    String packageName = jsonObject.get("packageName").getAsString();
    int newPackageResource = jsonObject.get("newPackageResource").getAsInt();
    int newPackageMinimumResource = jsonObject.get("newPackageMinimumResource").getAsInt();
    int newPackageDuration = jsonObject.get("newPackageDuration").getAsInt();
    String newPackageDurationType = jsonObject.get("newPackageDurationType").getAsString();

    DateTimeFormatter dtf = DateTimeFormat.forPattern("MM/dd/yyyy");
    DateTime currentDate = new DateTime();
    String createdDatePackage = currentDate.toString(dtf);
    List<OfflinePackageDTO> offlines = bookingDAO.addOfflinePackageAndReturnNewList(packageName,
            newPackageResource, newPackageMinimumResource, newPackageDuration, newPackageDurationType,
            createdDatePackage, providerID);
    return gson.toJson(offlines);
}

From source file:Implement.Service.ProviderServiceImpl.java

@Override
public void updateBookingRegistrationFom(String data, int providerID) {
    JsonObject dataJson = gson.fromJson(data, JsonObject.class);
    int packageID = dataJson.get("packageID").getAsInt();
    String packageType = dataJson.get("packageType").getAsString();
    Integer minTripper = null;//  ww w.j av a2  s  . co  m
    try {
        minTripper = dataJson.get("minTripper").getAsInt();
    } catch (Exception e) {
    }

    Integer maxTripper = null;
    try {
        maxTripper = dataJson.get("maxTripper").getAsInt();
    } catch (Exception e) {
    }

    Integer resourceID = null;
    try {
        resourceID = dataJson.get("resourceID").getAsInt();
    } catch (Exception e) {
    }

    Integer minimumResources = null;
    try {
        minimumResources = dataJson.get("minimumResources").getAsInt();
    } catch (Exception e) {
    }

    Integer durationDay = 0;
    try {
        durationDay = dataJson.get("durationDay").getAsInt();
    } catch (Exception e) {
    }
    Integer durationMonth = 0;
    try {
        durationMonth = dataJson.get("durationMonth").getAsInt();
    } catch (Exception e) {
    }
    Integer durationYear = 0;
    try {
        durationYear = dataJson.get("durationYear").getAsInt();
    } catch (Exception e) {
    }

    System.out.println("day " + durationDay);
    System.out.println("month " + durationMonth);
    System.out.println("year " + durationYear);
    Integer durationHour = 0;
    try {
        durationHour = dataJson.get("durationHour").getAsInt();
    } catch (Exception e) {
    }

    Integer durationMinute = 0;
    try {
        durationMinute = dataJson.get("durationMinute").getAsInt();
    } catch (Exception e) {
    }

    Integer servingID = null;
    try {
        servingID = dataJson.get("servingID").getAsInt();
    } catch (Exception e) {
    }

    boolean isFreeBooking = dataJson.get("isFreeBooking").getAsBoolean();
    int freeInterval = dataJson.get("freeInterval").getAsInt();
    boolean isRunning = dataJson.get("isRunning").getAsBoolean();

    Integer fixedHour = null;
    try {
        fixedHour = dataJson.get("fixedHour").getAsInt();
    } catch (Exception e) {
    }

    Integer fixedMinute = null;
    try {
        fixedMinute = dataJson.get("fixedMinute").getAsInt();
    } catch (Exception e) {
    }

    Integer restingDay = 0;
    try {
        restingDay = dataJson.get("restingtimeDay").getAsInt();
    } catch (Exception e) {
    }
    Integer restingHour = 0;
    try {
        restingHour = dataJson.get("restingtimeHour").getAsInt();
    } catch (Exception e) {
    }

    Integer restingMinute = 0;
    try {
        restingMinute = dataJson.get("restingtimeMinute").getAsInt();
    } catch (Exception e) {
    }

    Integer readyBookingDuration = null;
    try {
        readyBookingDuration = dataJson.get("readyBookingDuration").getAsInt();
    } catch (Exception e) {
    }
    String readyBookingDurationType = null;
    try {
        readyBookingDurationType = dataJson.get("readyBookingDurationType").getAsString();
    } catch (Exception e) {
    }
    Date toDay = new Date();
    SimpleDateFormat fortmatMMddyyyy = new SimpleDateFormat("MM/dd/yyyy");
    String todaystartDate = fortmatMMddyyyy.format(toDay);

    String startDate;
    try {
        startDate = dataJson.get("startDate").getAsString();
    } catch (Exception e) {
        DateTime toDate = new DateTime();
        startDate = toDate.toString("MM/dd/yyyy");
    }

    boolean isUsingMaxQuota = dataJson.get("isUsingMaxQuota").getAsBoolean();
    int maxQuota;
    try {
        maxQuota = dataJson.get("maxQuota").getAsInt();
    } catch (Exception e) {
        maxQuota = 0;
    }
    String quotaType = dataJson.get("quotaType").getAsString();
    boolean isSpecificLaunchDate = dataJson.get("isSpecificLaunchDate").getAsBoolean();

    String unavailableDays = dataJson.get("unavailableDays").getAsString();
    int sequentialOperation = dataJson.get("sequentialOperation").getAsInt();
    packageDAO.updateBookingFormOfTempPackage(packageID, packageType, minTripper, maxTripper, resourceID,
            minimumResources, servingID, isFreeBooking, freeInterval, fixedHour, fixedMinute, unavailableDays,
            sequentialOperation, isRunning, readyBookingDuration, readyBookingDurationType, durationDay,
            durationMonth, durationYear, durationHour, durationMinute, restingDay, restingHour, restingMinute,
            providerID, startDate, isUsingMaxQuota, maxQuota, quotaType, isSpecificLaunchDate);

    //        JsonArray cyclesJson = dataJson.get("operationCycles").getAsJsonArray();
    //        if (!isRunning) {
    //            for (JsonElement cycleElement : cyclesJson) {
    //                JsonObject cycle = cycleElement.getAsJsonObject();
    //                String startDate = null;
    //                try {
    //                    startDate = cycle.get("startDate").getAsString();
    //                } catch (Exception e) {
    //                }
    //                String endDate = null;
    //                try {
    //
    //                    endDate = cycle.get("endDate").getAsString();
    //                } catch (Exception e) {
    //                }
    //                temporaryOperationCycleDAO.insertNewTemporaryCycle(packageID, startDate, endDate);
    //            }
    //        } else {
    //            temporaryOperationCycleDAO.insertNewTemporaryCycle(packageID, todaystartDate, null);
    //        }
}

From source file:Implement.Service.ProviderServiceImpl.java

@Override
public void updateBookingOfMainPackage(String data, int providerID) {
    JsonObject dataJson = gson.fromJson(data, JsonObject.class);
    int packageID = dataJson.get("packageID").getAsInt();
    String packageType = dataJson.get("packageType").getAsString();
    Integer minTripper = null;/*  w ww . j a  v  a 2  s.c  o m*/
    try {
        minTripper = dataJson.get("minTripper").getAsInt();
    } catch (Exception e) {
    }

    Integer maxTripper = null;
    try {
        maxTripper = dataJson.get("maxTripper").getAsInt();
    } catch (Exception e) {
    }

    Integer resourceID = null;
    try {
        resourceID = dataJson.get("resourceID").getAsInt();
    } catch (Exception e) {
    }

    Integer minimumResources = null;
    try {
        minimumResources = dataJson.get("minimumResources").getAsInt();
    } catch (Exception e) {
    }

    Integer durationDay = 0;
    try {
        durationDay = dataJson.get("durationDay").getAsInt();
    } catch (Exception e) {
    }

    Integer durationMonth = 0;
    try {
        durationMonth = dataJson.get("durationMonth").getAsInt();
    } catch (Exception e) {
    }
    Integer durationYear = 0;
    try {
        durationYear = dataJson.get("durationYear").getAsInt();
    } catch (Exception e) {
    }

    Integer durationHour = 0;
    try {
        durationHour = dataJson.get("durationHour").getAsInt();
    } catch (Exception e) {
    }

    Integer durationMinute = 0;
    try {
        durationMinute = dataJson.get("durationMinute").getAsInt();
    } catch (Exception e) {
    }

    Integer servingID = null;
    try {
        servingID = dataJson.get("servingID").getAsInt();
    } catch (Exception e) {
    }

    boolean isFreeBooking = dataJson.get("isFreeBooking").getAsBoolean();
    int freeInterval = dataJson.get("freeInterval").getAsInt();
    boolean isRunning = dataJson.get("isRunning").getAsBoolean();

    Integer fixedHour = null;
    try {
        fixedHour = dataJson.get("fixedHour").getAsInt();
    } catch (Exception e) {
    }

    Integer fixedMinute = null;
    try {
        fixedMinute = dataJson.get("fixedMinute").getAsInt();
    } catch (Exception e) {
    }

    Integer restingDay = 0;
    try {
        restingDay = dataJson.get("restingtimeDay").getAsInt();
    } catch (Exception e) {
    }
    Integer restingHour = 0;
    try {
        restingHour = dataJson.get("restingtimeHour").getAsInt();
    } catch (Exception e) {
    }

    Integer restingMinute = 0;
    try {
        restingMinute = dataJson.get("restingtimeMinute").getAsInt();
    } catch (Exception e) {
    }

    Integer readyBookingDuration = null;
    try {
        readyBookingDuration = dataJson.get("readyBookingDuration").getAsInt();
    } catch (Exception e) {
    }
    String readyBookingDurationType = null;
    try {
        readyBookingDurationType = dataJson.get("readyBookingDurationType").getAsString();
    } catch (Exception e) {
    }
    Date toDay = new Date();
    SimpleDateFormat fortmatMMddyyyy = new SimpleDateFormat("MM/dd/yyyy");
    String todaystartDate = fortmatMMddyyyy.format(toDay);

    String unavailableDays = dataJson.get("unavailableDays").getAsString();
    int sequentialOperation = dataJson.get("sequentialOperation").getAsInt();

    String startDate;
    try {
        startDate = dataJson.get("startDate").getAsString();
    } catch (Exception e) {
        DateTime toDate = new DateTime();
        startDate = toDate.toString("MM/dd/yyyy");
    }

    boolean isUsingMaxQuota = dataJson.get("isUsingMaxQuota").getAsBoolean();
    int maxQuota;
    try {
        maxQuota = dataJson.get("maxQuota").getAsInt();
    } catch (Exception e) {
        maxQuota = 0;
    }

    String quotaType = dataJson.get("quotaType").getAsString();
    packageDAO.editBookingFormOfMainPackage(packageID, packageType, minTripper, maxTripper, resourceID,
            minimumResources, servingID, isFreeBooking, freeInterval, fixedHour, fixedMinute, unavailableDays,
            sequentialOperation, isRunning, readyBookingDuration, readyBookingDurationType, durationDay,
            durationMonth, durationYear, durationHour, durationMinute, restingDay, restingHour, restingMinute,
            providerID, startDate, isUsingMaxQuota, maxQuota, quotaType);

    //        JsonArray cyclesJson = dataJson.get("operationCycles").getAsJsonArray();
    //        if (!isRunning) {
    //            for (JsonElement cycleElement : cyclesJson) {
    //                JsonObject cycle = cycleElement.getAsJsonObject();
    //                String startDate = null;
    //                try {
    //                    startDate = cycle.get("startDate").getAsString();
    //                } catch (Exception e) {
    //                }
    //                String endDate = null;
    //                try {
    //
    //                    endDate = cycle.get("endDate").getAsString();
    //                } catch (Exception e) {
    //                }
    //                temporaryOperationCycleDAO.insertNewTemporaryCycle(packageID, startDate, endDate);
    //            }
    //        } else {
    //            temporaryOperationCycleDAO.insertNewTemporaryCycle(packageID, todaystartDate, null);
    //        }
}

From source file:io.confluent.connect.hdfs.partitioner.TimeBasedPartitioner.java

License:Apache License

@Override
public String encodePartition(SinkRecord sinkRecord) {
    long timestamp = System.currentTimeMillis();
    DateTime bucket = new DateTime(getPartition(partitionDurationMs, timestamp, formatter.getZone()));
    return bucket.toString(formatter);
}

From source file:io.confluent.connect.hdfs.partitioner.TimeUtils.java

License:Apache License

public static String encodeTimestamp(long partitionDurationMs, String pathFormat, String timeZoneString,
        long timestamp) {
    DateTimeZone timeZone = DateTimeZone.forID(timeZoneString);
    DateTimeFormatter formatter = DateTimeFormat.forPattern(pathFormat).withZone(timeZone);
    DateTime partition = new DateTime(getPartition(partitionDurationMs, timestamp, timeZone));
    return partition.toString(formatter);
}

From source file:io.confluent.connect.storage.partitioner.TimeBasedPartitioner.java

License:Open Source License

private String encodedPartitionForTimestamp(SinkRecord sinkRecord, Long timestamp) {
    if (timestamp == null) {
        String msg = "Unable to determine timestamp using timestamp.extractor "
                + timestampExtractor.getClass().getName() + " for record: " + sinkRecord;
        log.error(msg);/* w  ww  .  j  a v a2s.  com*/
        throw new ConnectException(msg);
    }
    DateTime bucket = new DateTime(getPartition(partitionDurationMs, timestamp, formatter.getZone()));
    return bucket.toString(formatter);
}

From source file:io.github.romankl.bitcoinvalue.util.DateUtility.java

License:Open Source License

public static String convertIsoDateTimeToLocaleDateTime(final Context context, String isoDate,
        String separator) {//from  w  w  w  . j a va 2s  .  c  o  m
    if (isNullOrEmpty(isoDate))
        return "";

    DateTime dateTime = new DateTime(isoDate);
    return new StringBuilder(dateTime.toString(getDateRepresentation(context))).append(separator)
            .append(dateTime.toString(getTimeRepresentation(context))).toString();
}