Skip to content
This repository has been archived by the owner on May 21, 2020. It is now read-only.

Commit

Permalink
Fix date format
Browse files Browse the repository at this point in the history
  • Loading branch information
Dounx committed Mar 28, 2018
1 parent f4c5ae4 commit d78bf74
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 6 deletions.
4 changes: 2 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ android {
applicationId "me.dounx.nintendoeshophelper"
minSdkVersion 21
targetSdkVersion 27
versionCode 3
versionName "1.1.1"
versionCode 4
versionName "1.1.2"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
Expand Down
Binary file modified app/src/main/assets/GameBase.db
Binary file not shown.
17 changes: 13 additions & 4 deletions app/src/main/java/Util/DateFormatter.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import android.content.Context;

import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Locale;
Expand All @@ -13,18 +14,26 @@
public class DateFormatter {
public static Date ParseStringToDate(String dateString) {
SimpleDateFormat dateFormatUS = new SimpleDateFormat("MMM d, yyyy", Locale.US);
SimpleDateFormat dateFormatEU = new SimpleDateFormat("yyyy-mm-dd", Locale.ENGLISH);
SimpleDateFormat dateFormatJP = new SimpleDateFormat("yyyy.m.d", Locale.JAPAN);
DateFormat dateFormatEU = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss Z");
SimpleDateFormat dateFormatJP = new SimpleDateFormat("yyyy.M.d");

// Strict mode
dateFormatUS.setLenient(false);
dateFormatEU.setLenient(false);
dateFormatJP.setLenient(false);

Date date = null;
try {
date = dateFormatUS.parse(dateString);

} catch (Exception e0) {
try {
date = dateFormatEU.parse(dateString);
date = dateFormatJP.parse(dateString);

} catch (Exception e1) {
try {
date = dateFormatJP.parse(dateString);
date = dateFormatEU.parse(dateString.replace("Z", " UTC"));

} catch (Exception e2) {
e2.printStackTrace();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,8 @@ public void onClick(View view) {
final TextView gamePageCountry = findViewById(R.id.game_page_country);
final ProgressBar progressBar = findViewById(R.id.price_progress_bar);
final TextView progress_info = findViewById(R.id.progress_info);
final TextView gamePageStartTime = findViewById(R.id.game_page_start_time);
final TextView gamePageEndTime = findViewById(R.id.game_page_end_time);

final List<SupportedCountry> list = SupportedCountryLab.get(this).getSupportedCountries();
progressBar.setMax(list.size());
Expand Down Expand Up @@ -155,6 +157,8 @@ public void onSuccess() {
public void onFailed() {
gamePagePrice.setText(R.string.failed);
gamePageCountry.setText(R.string.failed);
gamePageStartTime.setText(R.string.failed);
gamePageEndTime.setText(R.string.failed);
if (mGame.getGameCode() == null || mGame.getUsNsUid() == null && (mGame.getEuNsUid() == null && mGame.getJpNsUid() == null)) {
Toast.makeText(mContext, getString(R.string.not_exist), Toast.LENGTH_LONG).show();
} else {
Expand Down

0 comments on commit d78bf74

Please sign in to comment.