use of java.text.DateFormat in project j2objc by google.
the class NativeDecimalFormatTest method testZeroHour.
// Verify formatting a date with a format string with zeros.
public void testZeroHour() throws Exception {
DateFormat sdf = new SimpleDateFormat("HH:mm:ss");
String timeString = "00:00:23";
sdf.setTimeZone(TimeZone.getTimeZone("UTC"));
// Issue found a ParseException was thrown here.
Date date = sdf.parse(timeString);
// Only check seconds, as hour and date changes depending on timezone.
assertTrue(date.toString().contains(":23"));
}
use of java.text.DateFormat in project jimfs by google.
the class PathURLConnection method connect.
@Override
public void connect() throws IOException {
if (stream != null) {
return;
}
Path path = Paths.get(toUri(url));
long length;
if (Files.isDirectory(path)) {
// Match File URL behavior for directories by having the stream contain the filenames in
// the directory separated by newlines.
StringBuilder builder = new StringBuilder();
try (DirectoryStream<Path> files = Files.newDirectoryStream(path)) {
for (Path file : files) {
builder.append(file.getFileName()).append('\n');
}
}
byte[] bytes = builder.toString().getBytes(UTF_8);
stream = new ByteArrayInputStream(bytes);
length = bytes.length;
} else {
stream = Files.newInputStream(path);
length = Files.size(path);
}
FileTime lastModified = Files.getLastModifiedTime(path);
String contentType = MoreObjects.firstNonNull(Files.probeContentType(path), DEFAULT_CONTENT_TYPE);
ImmutableListMultimap.Builder<String, String> builder = ImmutableListMultimap.builder();
builder.put("content-length", "" + length);
builder.put("content-type", contentType);
if (lastModified != null) {
DateFormat format = new SimpleDateFormat(HTTP_DATE_FORMAT, Locale.US);
format.setTimeZone(TimeZone.getTimeZone("GMT"));
builder.put("last-modified", format.format(new Date(lastModified.toMillis())));
}
headers = builder.build();
}
use of java.text.DateFormat in project iosched by google.
the class TimeUtils method formatShortTime.
public static String formatShortTime(Context context, Date time) {
// Android DateFormatter will honor the user's current settings.
DateFormat format = android.text.format.DateFormat.getTimeFormat(context);
// Override with Timezone based on settings since users can override their phone's timezone
// with Pacific time zones.
TimeZone tz = SettingsUtils.getDisplayTimeZone(context);
if (tz != null) {
format.setTimeZone(tz);
}
return format.format(time);
}
use of java.text.DateFormat in project iosched by google.
the class UIUtils method formatSessionSubtitle.
/**
* Format and return the given session time and {@link Rooms} values using {@link
* Config#CONFERENCE_TIMEZONE}.
*/
public static String formatSessionSubtitle(long intervalStart, long intervalEnd, String roomName, StringBuilder recycle, Context context, boolean shortFormat) {
// Determine if the session is in the past
long currentTimeMillis = TimeUtils.getCurrentTime(context);
boolean conferenceEnded = currentTimeMillis > Config.CONFERENCE_END_MILLIS;
boolean sessionEnded = currentTimeMillis > intervalEnd;
if (sessionEnded && !conferenceEnded) {
return context.getString(R.string.session_finished);
}
if (roomName == null) {
roomName = context.getString(R.string.unknown_room);
}
if (shortFormat) {
TimeZone timeZone = SettingsUtils.getDisplayTimeZone(context);
Date intervalStartDate = new Date(intervalStart);
SimpleDateFormat shortDateFormat = new SimpleDateFormat("MMM dd");
DateFormat shortTimeFormat = DateFormat.getTimeInstance(DateFormat.SHORT);
shortDateFormat.setTimeZone(timeZone);
shortTimeFormat.setTimeZone(timeZone);
return shortDateFormat.format(intervalStartDate) + " " + shortTimeFormat.format(intervalStartDate);
} else {
String timeInterval = formatIntervalTimeString(intervalStart, intervalEnd, recycle, context);
return context.getString(R.string.session_subtitle, timeInterval, roomName);
}
}
use of java.text.DateFormat in project j2objc by google.
the class DateFormatTest method test_getNumberFormat.
/**
* @tests java.text.DateFormat#getNumberFormat()
*/
public void test_getNumberFormat() {
DateFormat format = DateFormat.getInstance();
NumberFormat nf1 = format.getNumberFormat();
NumberFormat nf2 = format.getNumberFormat();
assertTrue("NumberFormats not identical", nf1 == nf2);
}
Aggregations