Fix gnu date issue
This commit is contained in:
parent
489f4a3a1c
commit
5a77ea217f
|
@ -593,28 +593,25 @@ public class Helper {
|
||||||
* @return Date
|
* @return Date
|
||||||
*/
|
*/
|
||||||
public static Date mstStringToDate(Context context, String date) throws ParseException {
|
public static Date mstStringToDate(Context context, String date) throws ParseException {
|
||||||
Locale userLocale;
|
if (date == null)
|
||||||
if (date == null )
|
|
||||||
return null;
|
return null;
|
||||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
|
|
||||||
userLocale = context.getResources().getConfiguration().getLocales().get(0);
|
|
||||||
} else {
|
|
||||||
//noinspection deprecation
|
|
||||||
userLocale = context.getResources().getConfiguration().locale;
|
|
||||||
}
|
|
||||||
String STRING_DATE_FORMAT;
|
String STRING_DATE_FORMAT;
|
||||||
if( !date.contains("+"))
|
Locale local = Locale.getDefault();
|
||||||
|
if (!date.contains("+")) {
|
||||||
STRING_DATE_FORMAT = "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'";
|
STRING_DATE_FORMAT = "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'";
|
||||||
else //GNU date format
|
} else{ //GNU date format
|
||||||
STRING_DATE_FORMAT = "EEE MMM dd HH:mm:ss ZZZZZ yyyy";
|
STRING_DATE_FORMAT = "EEE MMM dd HH:mm:ss ZZZZZ yyyy";
|
||||||
SimpleDateFormat simpleDateFormat = new SimpleDateFormat(STRING_DATE_FORMAT, userLocale);
|
local = Locale.ENGLISH;
|
||||||
|
}
|
||||||
|
SimpleDateFormat simpleDateFormat = new SimpleDateFormat(STRING_DATE_FORMAT, local);
|
||||||
simpleDateFormat.setTimeZone(TimeZone.getTimeZone("gmt"));
|
simpleDateFormat.setTimeZone(TimeZone.getTimeZone("gmt"));
|
||||||
simpleDateFormat.setLenient(true);
|
simpleDateFormat.setLenient(true);
|
||||||
try {
|
try {
|
||||||
return simpleDateFormat.parse(date);
|
return simpleDateFormat.parse(date);
|
||||||
}catch (Exception e){
|
}catch (Exception e){
|
||||||
String newdate = date.split("\\+")[0].trim();
|
String newdate = date.split("\\+")[0].trim();
|
||||||
simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss", userLocale);
|
simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss", local);
|
||||||
simpleDateFormat.setTimeZone(TimeZone.getTimeZone("gmt"));
|
simpleDateFormat.setTimeZone(TimeZone.getTimeZone("gmt"));
|
||||||
simpleDateFormat.setLenient(true);
|
simpleDateFormat.setLenient(true);
|
||||||
return simpleDateFormat.parse(newdate);
|
return simpleDateFormat.parse(newdate);
|
||||||
|
|
|
@ -20,6 +20,7 @@ import android.database.Cursor;
|
||||||
import android.database.sqlite.SQLiteDatabase;
|
import android.database.sqlite.SQLiteDatabase;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.Date;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import fr.gouv.etalab.mastodon.client.Entities.Account;
|
import fr.gouv.etalab.mastodon.client.Entities.Account;
|
||||||
|
@ -51,7 +52,10 @@ public class AccountDAO {
|
||||||
public boolean insertAccount(Account account)
|
public boolean insertAccount(Account account)
|
||||||
{
|
{
|
||||||
ContentValues values = new ContentValues();
|
ContentValues values = new ContentValues();
|
||||||
|
if( account.getCreated_at() == null)
|
||||||
|
account.setCreated_at(new Date());
|
||||||
|
if( account.getNote() == null)
|
||||||
|
account.setNote("");
|
||||||
values.put(Sqlite.COL_USER_ID, account.getId());
|
values.put(Sqlite.COL_USER_ID, account.getId());
|
||||||
values.put(Sqlite.COL_USERNAME, account.getUsername());
|
values.put(Sqlite.COL_USERNAME, account.getUsername());
|
||||||
values.put(Sqlite.COL_ACCT, account.getAcct());
|
values.put(Sqlite.COL_ACCT, account.getAcct());
|
||||||
|
@ -97,7 +101,10 @@ public class AccountDAO {
|
||||||
public int updateAccount(Account account)
|
public int updateAccount(Account account)
|
||||||
{
|
{
|
||||||
ContentValues values = new ContentValues();
|
ContentValues values = new ContentValues();
|
||||||
|
if( account.getNote() == null)
|
||||||
|
account.setNote("");
|
||||||
|
if( account.getCreated_at() == null)
|
||||||
|
account.setCreated_at(new Date());
|
||||||
values.put(Sqlite.COL_ACCT, account.getAcct());
|
values.put(Sqlite.COL_ACCT, account.getAcct());
|
||||||
values.put(Sqlite.COL_DISPLAYED_NAME, account.getDisplay_name());
|
values.put(Sqlite.COL_DISPLAYED_NAME, account.getDisplay_name());
|
||||||
values.put(Sqlite.COL_LOCKED,account.isLocked());
|
values.put(Sqlite.COL_LOCKED,account.isLocked());
|
||||||
|
|
Loading…
Reference in New Issue