use of com.codename1.l10n.DateFormat in project CodenameOne by codenameone.
the class SimpleDateFormatTests method runTest.
@Override
public boolean runTest() throws Exception {
if (Display.getInstance().isSimulator()) {
NativeTimeZoneUtil tzUtil = NativeLookup.create(NativeTimeZoneUtil.class);
TimeZone defaultTz = TimeZone.getDefault();
try {
for (String tzName : new String[] { "America/Vancouver", "America/Chicago", "UTC" }) {
tzUtil.setDefaultTimeZone(tzName);
String[] data = new String[] { "yyyy-MM-dd kk:mm:ss.SSS", "2018-04-26 08:04:30.511", "h:mm aa", "8:04 AM", "yyyy-MM-dd hh:mm aaa, z", "2018-04-26 08:04 PM, PDT", "h:mm aa", "8:04 PM", "yyyy-MM-dd hh:mm aaa, z", "2018-04-26 08:04 PM, GMT-08:00", "h:mm aa", "5:04 PM", "yyyy-MM-dd hh:mm aaa, z", "2018-04-26 08:04 PM, GMT", "h:mm aa", "5:04 PM", // ,
"dd-MMM-yy HH:mm:ss z", // ,
"26-aug-20 18:02:09 gmt" // "EEE, dd-MMM-yy HH:mm:ss z", "wed, 26-aug-20 18:02:09 gmt"
};
for (int i = 0; i < data.length; i += 4) {
java.text.DateFormat messageDateFormat0 = new java.text.SimpleDateFormat(data[i], java.util.Locale.US);
SimpleDateFormat messageDateFormat = new SimpleDateFormat(data[i]);
messageDateFormat.getDateFormatSymbols().addZoneMapping("America/Vancouver", "Pacific Standard Time", "Pacific Daylight Time", "PST", "PDT");
messageDateFormat.getDateFormatSymbols().addZoneMapping("America/New_York", "Eastern Standard Time", "Eastern Daylight Time", "EST", "EDT");
messageDateFormat.getDateFormatSymbols().addZoneMapping("America/Chicago", "Central Standard Time", "Central Daylight Time", "CST", "CDT");
Date when0 = messageDateFormat0.parse(data[i + 1]);
Date when = messageDateFormat.parse(data[i + 1]);
assertEqual(when0, when, "In timezone " + tzName + ", SimpleDateFormat parse deviated from java.text version. Parsing " + data[i + 1] + " with format " + data[i]);
// if (!when0.equals(when)) {
// throw new RuntimeException("Test "+(i/4)+" FAILED. Expected "+when0+" but found "+when);
// }
// What is date that is associated with when?
DateFormat displayTimeFormat = messageDateFormat;
java.text.DateFormat displayTimeFormat0 = new java.text.SimpleDateFormat(data[i], java.util.Locale.US);
String output0 = displayTimeFormat0.format(when);
String output = displayTimeFormat.format(when);
assertEqual(output0, output, "In timezone " + tzName + " SimpleDateFormat format deviated from java.text version. Formatting " + data[i + 1] + " with format " + data[i]);
}
}
} finally {
tzUtil.setDefaultTimeZone(defaultTz.getID());
}
}
/*
if (true) {
long[] timestamps = new long[]{
1524755070511L, 1524798240000L, 1524801840000L, 1524773040000L
};
String[] data = new String[]{
"yyyy-MM-dd kk:mm:ss.SSS", "2018-04-26 08:04:30.511 PDT", "h:mm aa", "8:04 AM",
"yyyy-MM-dd hh:mm aaa, z", "2018-04-26 08:04 PM, PDT", "h:mm aa", "8:04 PM",
"yyyy-MM-dd hh:mm aaa, z", "2018-04-26 08:04 PM, GMT-08:00", "h:mm aa", "5:04 PM",
"yyyy-MM-dd hh:mm aaa, z", "2018-04-26 08:04 PM, GMT", "h:mm aa", "5:04 PM"
};
for (int i=0; i<data.length; i+=4) {
//java.text.DateFormat messageDateFormat0 = new java.text.SimpleDateFormat(data[i]);
SimpleDateFormat messageDateFormat = new SimpleDateFormat(data[i]);
messageDateFormat.getDateFormatSymbols().addZoneMapping("America/Vancouver", "Pacific Standard Time", "Pacific Daylight Time", "PST", "PDT");
messageDateFormat.getDateFormatSymbols().addZoneMapping("America/New_York", "Eastern Standard Time", "Eastern Daylight Time", "EST", "EDT");
//Date when0 = messageDateFormat0.parse(data[i+1]);
Date when = messageDateFormat.parse(data[i+1]);
assertEqual(timestamps[i/4], when.getTime(), "SimpleDateFormat parse deviated from java.text version. Parsing "+data[i+1]+" with format "+data[i]);
// Formatting depends on the timezone, so we won't run these tests as they will turn out
// differently depending on the timezone of the device.
//if (!when0.equals(when)) {
// throw new RuntimeException("Test "+(i/4)+" FAILED. Expected "+when0+" but found "+when);
//}
// What is date that is associated with when?
//DateFormat displayTimeFormat = new SimpleDateFormat(data[i+2]);
//java.text.DateFormat displayTimeFormat0 = new java.text.SimpleDateFormat(data[i+2]);
//String output0 = displayTimeFormat0.format(when);
//String output = displayTimeFormat.format(when);
//assertEqual(output0, output, "SimpleDateFormat format deviated from java.text version. Formatting "+data[i+1]+" with format "+data[i+2]);
}
}
*/
return true;
}
use of com.codename1.l10n.DateFormat in project CodenameOne by codenameone.
the class CameraKitPickerTest7 method showAnotherForm.
public void showAnotherForm() {
Form form = new Form(new BorderLayout(BorderLayout.CENTER_BEHAVIOR_SCALE));
form.setScrollable(false);
Container container = new Container(BoxLayout.y());
container.add(new Label("Test", "heading5"));
container.add(new Label("", "newLine"));
container.add(new Label("", "newLine"));
final Picker fromDate = new Picker();
fromDate.setType(Display.PICKER_TYPE_DATE);
container.add(new Label("From Date", "heading7"));
container.add(fromDate);
container.add(new Label("", "newLine"));
final Picker toDate = new Picker();
toDate.setType(Display.PICKER_TYPE_DATE);
container.add(new Label("To Date", "heading7"));
container.add(toDate);
Button nextBtn = new Button("Proceed");
nextBtn.setUIID("loginBtn");
nextBtn.addActionListener((ev) -> {
DateFormat dateFormat = new SimpleDateFormat("dd-MMM-yyyy");
String fromDateStr = dateFormat.format(fromDate.getDate());
String toDateStr = dateFormat.format(toDate.getDate());
});
container.add(new Label("", "newLine"));
container.add(new Label("", "newLine"));
container.add(nextBtn);
form.add(BorderLayout.CENTER, container);
form.show();
}
Aggregations