Search in sources :

Example 71 with DateFormat

use of java.text.DateFormat in project liquibase by liquibase.

the class StandardChangeLogHistoryService method getRanChangeSets.

/**
     * Returns the ChangeSets that have been run against the current getDatabase().
     */
public List<RanChangeSet> getRanChangeSets() throws DatabaseException {
    if (this.ranChangeSetList == null) {
        Database database = getDatabase();
        String databaseChangeLogTableName = getDatabase().escapeTableName(getLiquibaseCatalogName(), getLiquibaseSchemaName(), getDatabaseChangeLogTableName());
        List<RanChangeSet> ranChangeSetList = new ArrayList<RanChangeSet>();
        if (hasDatabaseChangeLogTable()) {
            LogFactory.getLogger().info("Reading from " + databaseChangeLogTableName);
            List<Map<String, ?>> results = queryDatabaseChangeLogTable(database);
            for (Map rs : results) {
                String fileName = rs.get("FILENAME").toString();
                String author = rs.get("AUTHOR").toString();
                String id = rs.get("ID").toString();
                String md5sum = rs.get("MD5SUM") == null || !databaseChecksumsCompatible ? null : rs.get("MD5SUM").toString();
                String description = rs.get("DESCRIPTION") == null ? null : rs.get("DESCRIPTION").toString();
                String comments = rs.get("COMMENTS") == null ? null : rs.get("COMMENTS").toString();
                Object tmpDateExecuted = rs.get("DATEEXECUTED");
                Date dateExecuted = null;
                if (tmpDateExecuted instanceof Date) {
                    dateExecuted = (Date) tmpDateExecuted;
                } else {
                    DateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
                    try {
                        dateExecuted = df.parse((String) tmpDateExecuted);
                    } catch (ParseException e) {
                    }
                }
                String tmpOrderExecuted = rs.get("ORDEREXECUTED").toString();
                Integer orderExecuted = (tmpOrderExecuted == null ? null : Integer.valueOf(tmpOrderExecuted));
                String tag = rs.get("TAG") == null ? null : rs.get("TAG").toString();
                String execType = rs.get("EXECTYPE") == null ? null : rs.get("EXECTYPE").toString();
                ContextExpression contexts = new ContextExpression((String) rs.get("CONTEXTS"));
                Labels labels = new Labels((String) rs.get("LABELS"));
                String deploymentId = (String) rs.get("DEPLOYMENT_ID");
                try {
                    RanChangeSet ranChangeSet = new RanChangeSet(fileName, id, author, CheckSum.parse(md5sum), dateExecuted, tag, ChangeSet.ExecType.valueOf(execType), description, comments, contexts, labels, deploymentId);
                    ranChangeSet.setOrderExecuted(orderExecuted);
                    ranChangeSetList.add(ranChangeSet);
                } catch (IllegalArgumentException e) {
                    LogFactory.getLogger().severe("Unknown EXECTYPE from database: " + execType);
                    throw e;
                }
            }
        }
        this.ranChangeSetList = ranChangeSetList;
    }
    return Collections.unmodifiableList(ranChangeSetList);
}
Also used : ContextExpression(liquibase.ContextExpression) Labels(liquibase.Labels) SimpleDateFormat(java.text.SimpleDateFormat) DateFormat(java.text.DateFormat) SQLiteDatabase(liquibase.database.core.SQLiteDatabase) DB2Database(liquibase.database.core.DB2Database) MSSQLDatabase(liquibase.database.core.MSSQLDatabase) Database(liquibase.database.Database) ParseException(java.text.ParseException) SimpleDateFormat(java.text.SimpleDateFormat)

Example 72 with DateFormat

use of java.text.DateFormat in project liquibase by liquibase.

the class DateType method sqlToObject.

@Override
public Object sqlToObject(String value, Database database) {
    if (database instanceof DB2Database) {
        return value.replaceFirst("^\"SYSIBM\".\"DATE\"\\('", "").replaceFirst("'\\)", "");
    }
    if (database instanceof DerbyDatabase) {
        return value.replaceFirst("^DATE\\('", "").replaceFirst("'\\)", "");
    }
    if (zeroTime(value)) {
        return value;
    }
    try {
        DateFormat dateFormat = getDateFormat(database);
        if (database instanceof OracleDatabase && value.matches("to_date\\('\\d+\\-\\d+\\-\\d+', 'YYYY\\-MM\\-DD'\\)")) {
            dateFormat = new SimpleDateFormat("yyyy-MM-dd");
            value = value.replaceFirst(".*?'", "").replaceFirst("',.*", "");
        }
        return new java.sql.Date(dateFormat.parse(value.trim()).getTime());
    } catch (ParseException e) {
        return new DatabaseFunction(value);
    }
}
Also used : DatabaseFunction(liquibase.statement.DatabaseFunction) SimpleDateFormat(java.text.SimpleDateFormat) DateFormat(java.text.DateFormat) ParseException(java.text.ParseException) SimpleDateFormat(java.text.SimpleDateFormat)

Example 73 with DateFormat

use of java.text.DateFormat in project react-native-image-picker by marcshilling.

the class ImagePickerModule method onActivityResult.

@Override
public void onActivityResult(Activity activity, int requestCode, int resultCode, Intent data) {
    //robustness code
    if (callback == null || (cameraCaptureURI == null && requestCode == REQUEST_LAUNCH_IMAGE_CAPTURE) || (requestCode != REQUEST_LAUNCH_IMAGE_CAPTURE && requestCode != REQUEST_LAUNCH_IMAGE_LIBRARY && requestCode != REQUEST_LAUNCH_VIDEO_LIBRARY && requestCode != REQUEST_LAUNCH_VIDEO_CAPTURE)) {
        return;
    }
    responseHelper.cleanResponse();
    // user cancel
    if (resultCode != Activity.RESULT_OK) {
        responseHelper.invokeCancel(callback);
        callback = null;
        return;
    }
    Uri uri;
    switch(requestCode) {
        case REQUEST_LAUNCH_IMAGE_CAPTURE:
            uri = cameraCaptureURI;
            this.fileScan(uri.getPath());
            break;
        case REQUEST_LAUNCH_IMAGE_LIBRARY:
            uri = data.getData();
            break;
        case REQUEST_LAUNCH_VIDEO_LIBRARY:
            responseHelper.putString("uri", data.getData().toString());
            responseHelper.putString("path", getRealPathFromURI(data.getData()));
            responseHelper.invokeResponse(callback);
            callback = null;
            return;
        case REQUEST_LAUNCH_VIDEO_CAPTURE:
            final String path = getRealPathFromURI(data.getData());
            responseHelper.putString("uri", data.getData().toString());
            responseHelper.putString("path", path);
            this.fileScan(path);
            responseHelper.invokeResponse(callback);
            callback = null;
            return;
        default:
            uri = null;
    }
    String realPath = getRealPathFromURI(uri);
    boolean isUrl = false;
    if (realPath != null) {
        try {
            URL url = new URL(realPath);
            isUrl = true;
        } catch (MalformedURLException e) {
        // not a url
        }
    }
    // image isn't in memory cache
    if (realPath == null || isUrl) {
        try {
            File file = createFileFromURI(uri);
            realPath = file.getAbsolutePath();
            uri = Uri.fromFile(file);
        } catch (Exception e) {
            // image not in cache
            responseHelper.putString("error", "Could not read photo");
            responseHelper.putString("uri", uri.toString());
            responseHelper.invokeResponse(callback);
            callback = null;
            return;
        }
    }
    int currentRotation = 0;
    try {
        ExifInterface exif = new ExifInterface(realPath);
        // extract lat, long, and timestamp and add to the response
        float[] latlng = new float[2];
        exif.getLatLong(latlng);
        float latitude = latlng[0];
        float longitude = latlng[1];
        if (latitude != 0f || longitude != 0f) {
            responseHelper.putDouble("latitude", latitude);
            responseHelper.putDouble("longitude", longitude);
        }
        final String timestamp = exif.getAttribute(ExifInterface.TAG_DATETIME);
        final SimpleDateFormat exifDatetimeFormat = new SimpleDateFormat("yyyy:MM:dd HH:mm:ss");
        final DateFormat isoFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss");
        isoFormat.setTimeZone(TimeZone.getTimeZone("UTC"));
        try {
            final String isoFormatString = new StringBuilder(isoFormat.format(exifDatetimeFormat.parse(timestamp))).append("Z").toString();
            responseHelper.putString("timestamp", isoFormatString);
        } catch (Exception e) {
        }
        int orientation = exif.getAttributeInt(ExifInterface.TAG_ORIENTATION, ExifInterface.ORIENTATION_NORMAL);
        boolean isVertical = true;
        switch(orientation) {
            case ExifInterface.ORIENTATION_ROTATE_270:
                isVertical = false;
                currentRotation = 270;
                break;
            case ExifInterface.ORIENTATION_ROTATE_90:
                isVertical = false;
                currentRotation = 90;
                break;
            case ExifInterface.ORIENTATION_ROTATE_180:
                currentRotation = 180;
                break;
        }
        responseHelper.putInt("originalRotation", currentRotation);
        responseHelper.putBoolean("isVertical", isVertical);
    } catch (IOException e) {
        e.printStackTrace();
        responseHelper.invokeError(callback, e.getMessage());
        callback = null;
        return;
    }
    BitmapFactory.Options options = new BitmapFactory.Options();
    options.inJustDecodeBounds = true;
    BitmapFactory.decodeFile(realPath, options);
    int initialWidth = options.outWidth;
    int initialHeight = options.outHeight;
    // don't create a new file if contraint are respected
    if (((initialWidth < maxWidth && maxWidth > 0) || maxWidth == 0) && ((initialHeight < maxHeight && maxHeight > 0) || maxHeight == 0) && quality == 100 && (rotation == 0 || currentRotation == rotation)) {
        responseHelper.putInt("width", initialWidth);
        responseHelper.putInt("height", initialHeight);
    } else {
        File resized = getResizedImage(realPath, initialWidth, initialHeight);
        if (resized == null) {
            responseHelper.putString("error", "Can't resize the image");
        } else {
            realPath = resized.getAbsolutePath();
            uri = Uri.fromFile(resized);
            BitmapFactory.decodeFile(realPath, options);
            responseHelper.putInt("width", options.outWidth);
            responseHelper.putInt("height", options.outHeight);
        }
    }
    if (saveToCameraRoll && requestCode == REQUEST_LAUNCH_IMAGE_CAPTURE) {
        final File oldFile = new File(uri.getPath());
        final File newDir = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DCIM);
        final File newFile = new File(newDir.getPath(), uri.getLastPathSegment());
        try {
            moveFile(oldFile, newFile);
            uri = Uri.fromFile(newFile);
        } catch (IOException e) {
            e.printStackTrace();
            responseHelper.putString("error", "Error moving image to camera roll: " + e.getMessage());
        }
    }
    responseHelper.putString("uri", uri.toString());
    responseHelper.putString("path", realPath);
    if (!noData) {
        responseHelper.putString("data", getBase64StringFromFile(realPath));
    }
    putExtraFileInfo(realPath, responseHelper);
    responseHelper.invokeResponse(callback);
    callback = null;
    this.options = null;
}
Also used : Options(android.graphics.BitmapFactory.Options) MalformedURLException(java.net.MalformedURLException) Options(android.graphics.BitmapFactory.Options) ExifInterface(android.media.ExifInterface) IOException(java.io.IOException) Uri(android.net.Uri) URL(java.net.URL) FileNotFoundException(java.io.FileNotFoundException) ActivityNotFoundException(android.content.ActivityNotFoundException) MalformedURLException(java.net.MalformedURLException) IOException(java.io.IOException) DateFormat(java.text.DateFormat) SimpleDateFormat(java.text.SimpleDateFormat) BitmapFactory(android.graphics.BitmapFactory) File(java.io.File) SimpleDateFormat(java.text.SimpleDateFormat)

Example 74 with DateFormat

use of java.text.DateFormat in project okhttp by square.

the class HttpDate method parse.

/** Returns the date for {@code value}. Returns null if the value couldn't be parsed. */
public static Date parse(String value) {
    if (value.length() == 0) {
        return null;
    }
    ParsePosition position = new ParsePosition(0);
    Date result = STANDARD_DATE_FORMAT.get().parse(value, position);
    if (position.getIndex() == value.length()) {
        // non-standard trailing "+01:00". Those cases are covered below.
        return result;
    }
    synchronized (BROWSER_COMPATIBLE_DATE_FORMAT_STRINGS) {
        for (int i = 0, count = BROWSER_COMPATIBLE_DATE_FORMAT_STRINGS.length; i < count; i++) {
            DateFormat format = BROWSER_COMPATIBLE_DATE_FORMATS[i];
            if (format == null) {
                format = new SimpleDateFormat(BROWSER_COMPATIBLE_DATE_FORMAT_STRINGS[i], Locale.US);
                // Set the timezone to use when interpreting formats that don't have a timezone. GMT is
                // specified by RFC 2616.
                format.setTimeZone(UTC);
                BROWSER_COMPATIBLE_DATE_FORMATS[i] = format;
            }
            position.setIndex(0);
            result = format.parse(value, position);
            if (position.getIndex() != 0) {
                // trailing junk is ignored.
                return result;
            }
        }
    }
    return null;
}
Also used : SimpleDateFormat(java.text.SimpleDateFormat) DateFormat(java.text.DateFormat) SimpleDateFormat(java.text.SimpleDateFormat) Date(java.util.Date) ParsePosition(java.text.ParsePosition)

Example 75 with DateFormat

use of java.text.DateFormat in project okhttp by square.

the class ResponseCacheTest method formatDate.

private String formatDate(Date date) {
    DateFormat rfc1123 = new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss zzz", Locale.US);
    rfc1123.setTimeZone(TimeZone.getTimeZone("GMT"));
    return rfc1123.format(date);
}
Also used : DateFormat(java.text.DateFormat) SimpleDateFormat(java.text.SimpleDateFormat) SimpleDateFormat(java.text.SimpleDateFormat)

Aggregations

DateFormat (java.text.DateFormat)646 SimpleDateFormat (java.text.SimpleDateFormat)486 Date (java.util.Date)315 ParseException (java.text.ParseException)132 Calendar (java.util.Calendar)78 Test (org.junit.Test)69 ArrayList (java.util.ArrayList)48 IOException (java.io.IOException)43 File (java.io.File)31 HashMap (java.util.HashMap)27 GregorianCalendar (java.util.GregorianCalendar)24 TimeZone (java.util.TimeZone)23 Locale (java.util.Locale)18 Timestamp (java.sql.Timestamp)17 List (java.util.List)14 InputStream (java.io.InputStream)12 DateTime (org.joda.time.DateTime)11 Map (java.util.Map)10 Matcher (java.util.regex.Matcher)8 TestBean (org.springframework.tests.sample.beans.TestBean)8