Formatted the raw dates returned by the beatmap download servers.
Signed-off-by: Jeffrey Han <itdelatrisu@gmail.com>
This commit is contained in:
parent
6c8d4ea49a
commit
f828349304
|
@ -27,6 +27,10 @@ import java.io.UnsupportedEncodingException;
|
|||
import java.net.MalformedURLException;
|
||||
import java.net.URL;
|
||||
import java.net.URLEncoder;
|
||||
import java.text.DateFormat;
|
||||
import java.text.ParseException;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Date;
|
||||
|
||||
import org.json.JSONArray;
|
||||
import org.json.JSONObject;
|
||||
|
@ -76,7 +80,7 @@ public class BloodcatServer extends DownloadServer {
|
|||
for (int i = 0; i < nodes.length; i++) {
|
||||
JSONObject item = arr.getJSONObject(i);
|
||||
nodes[i] = new DownloadNode(
|
||||
item.getInt("id"), item.getString("date"),
|
||||
item.getInt("id"), formatDate(item.getString("date")),
|
||||
item.getString("title"), item.isNull("titleUnicode") ? null : item.getString("titleUnicode"),
|
||||
item.getString("artist"), item.isNull("artistUnicode") ? null : item.getString("artistUnicode"),
|
||||
item.getString("creator")
|
||||
|
@ -96,4 +100,26 @@ public class BloodcatServer extends DownloadServer {
|
|||
|
||||
@Override
|
||||
public int totalResults() { return totalResults; }
|
||||
|
||||
/**
|
||||
* Returns a formatted date string from a raw date.
|
||||
* @param s the raw date string (e.g. "2015-05-14T23:38:47+09:00")
|
||||
* @return the formatted date, or the raw string if it could not be parsed
|
||||
*/
|
||||
private String formatDate(String s) {
|
||||
try {
|
||||
// make string parseable by SimpleDateFormat
|
||||
int index = s.lastIndexOf(':');
|
||||
if (index == -1)
|
||||
return s;
|
||||
String str = new StringBuilder(s).deleteCharAt(index).toString();
|
||||
|
||||
DateFormat f = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssZ");
|
||||
Date d = f.parse(str);
|
||||
DateFormat fmt = new SimpleDateFormat("d MMM yyyy HH:mm:ss");
|
||||
return fmt.format(d);
|
||||
} catch (StringIndexOutOfBoundsException | ParseException e) {
|
||||
return s;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -27,7 +27,12 @@ import java.io.UnsupportedEncodingException;
|
|||
import java.net.MalformedURLException;
|
||||
import java.net.URL;
|
||||
import java.net.URLEncoder;
|
||||
import java.text.DateFormat;
|
||||
import java.text.ParseException;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.TimeZone;
|
||||
|
||||
import org.json.JSONArray;
|
||||
import org.json.JSONObject;
|
||||
|
@ -100,7 +105,7 @@ public class OsuMirrorServer extends DownloadServer {
|
|||
int beatmapSetID = item.getInt("OSUSetid");
|
||||
int serverID = item.getInt("id");
|
||||
nodes[i] = new DownloadNode(
|
||||
beatmapSetID, item.getString("ModifyDate"),
|
||||
beatmapSetID, formatDate(item.getString("ModifyDate")),
|
||||
item.getString("Title"), null,
|
||||
item.getString("Artist"), null,
|
||||
item.getString("Mapper")
|
||||
|
@ -126,4 +131,21 @@ public class OsuMirrorServer extends DownloadServer {
|
|||
|
||||
@Override
|
||||
public int totalResults() { return totalResults; }
|
||||
|
||||
/**
|
||||
* Returns a formatted date string from a raw date.
|
||||
* @param s the raw date string (e.g. "2015-05-14T23:38:47Z")
|
||||
* @return the formatted date, or the raw string if it could not be parsed
|
||||
*/
|
||||
private String formatDate(String s) {
|
||||
try {
|
||||
DateFormat f = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'");
|
||||
f.setTimeZone(TimeZone.getTimeZone("UTC"));
|
||||
Date d = f.parse(s);
|
||||
DateFormat fmt = new SimpleDateFormat("d MMM yyyy HH:mm:ss");
|
||||
return fmt.format(d);
|
||||
} catch (ParseException e) {
|
||||
return s;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -203,9 +203,9 @@ public class OptionsMenu extends BasicGameState {
|
|||
int mouseX = input.getMouseX(), mouseY = input.getMouseY();
|
||||
|
||||
// title
|
||||
float c = container.getWidth() * 0.02f;
|
||||
Utils.FONT_LARGE.drawString(c, c, "Game Options", Color.white);
|
||||
Utils.FONT_DEFAULT.drawString(c, c + Utils.FONT_LARGE.getLineHeight() * 0.9f,
|
||||
float marginX = width * 0.02f, marginY = height * 0.015f;
|
||||
Utils.FONT_LARGE.drawString(marginX, marginY, "Game Options", Color.white);
|
||||
Utils.FONT_DEFAULT.drawString(marginX, marginY + Utils.FONT_LARGE.getLineHeight() * 0.92f,
|
||||
"Click or drag an option to change it.", Color.white);
|
||||
|
||||
// game options
|
||||
|
|
Loading…
Reference in New Issue
Block a user