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);
}
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);
}
}
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;
}
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;
}
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);
}
Aggregations