Skip to content

Commit

Permalink
Merge pull request #81 from AndreySBer/bugfix-60-dateproblem
Browse files Browse the repository at this point in the history
Fix bug #60
  • Loading branch information
phansier authored Jan 29, 2018
2 parents 25824b6 + b39189c commit 25bd40d
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 7 deletions.
5 changes: 3 additions & 2 deletions app/src/main/java/com/github/mobile/api/DateAdapter.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,13 @@
import java.util.TimeZone;

public class DateAdapter {
private final DateFormat[] formats = new DateFormat[3];
private final DateFormat[] formats = new DateFormat[4];

public DateAdapter() {
formats[0] = new SimpleDateFormat("yyyy-MM-dd\'T\'HH:mm:ss\'Z\'");
formats[1] = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss Z");
formats[2] = new SimpleDateFormat("yyyy-MM-dd\'T\'HH:mm:ss");
formats[3] = new SimpleDateFormat("yyyy-MM-dd\'T\'HH:mm:ss\'Z\'X");
final TimeZone timeZone = TimeZone.getTimeZone("Zulu");
for (DateFormat format : formats) {
format.setTimeZone(timeZone);
Expand All @@ -40,7 +41,7 @@ public DateAdapter() {

@ToJson
String toJson(Date date) {
return formats[0].format(date);
return formats[3].format(date);
}

@FromJson
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.TimeZone;

import static com.github.mobile.Intents.EXTRA_MILESTONE;
import static com.github.mobile.Intents.EXTRA_REPOSITORY;
Expand Down Expand Up @@ -106,11 +107,16 @@ public static Intent createIntent(final Milestone milestone,

private MenuItem saveItem;

private SimpleDateFormat sd;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.milestone_edit);

sd = new SimpleDateFormat(getApplicationContext().getString(R.string.ms_date_format));
sd.setTimeZone(TimeZone.getTimeZone("Zulu"));

etTitle = finder.find(R.id.et_milestone_title);
etDescription = finder.find(R.id.et_milestone_description);
etDate = finder.find(R.id.tv_milestone_date);
Expand All @@ -130,7 +136,9 @@ public void onDateSet(DatePicker view, int year, int monthOfYear, int dayOfMonth
dateAndTime.set(Calendar.YEAR, year);
dateAndTime.set(Calendar.MONTH, monthOfYear);
dateAndTime.set(Calendar.DAY_OF_MONTH, dayOfMonth);

final Date startDate = dateAndTime.getTime();
String fdate = sd.format(startDate);
etDate.setText(fdate);
}
}, dateAndTime.get(Calendar.YEAR), dateAndTime.get(Calendar.MONTH), dateAndTime.get(Calendar.DAY_OF_MONTH)).show();

Expand Down Expand Up @@ -177,7 +185,7 @@ public void onClick(View v) {
if (milestone == null)
milestone = new Milestone();

repository=(Repository) intent.getSerializableExtra(EXTRA_REPOSITORY);
repository = (Repository) intent.getSerializableExtra(EXTRA_REPOSITORY);
repositoryId = RepositoryId.create(
intent.getStringExtra(EXTRA_REPOSITORY_OWNER),
intent.getStringExtra(EXTRA_REPOSITORY_NAME));
Expand Down Expand Up @@ -280,7 +288,7 @@ public boolean onOptionsItemSelected(MenuItem item) {
protected void onSuccess(Milestone created) throws Exception {
super.onSuccess(created);

Intent intent =RepositoryMilestonesActivity.createIntent(repository);
Intent intent = RepositoryMilestonesActivity.createIntent(repository);
startActivity(intent);
}

Expand Down Expand Up @@ -333,8 +341,8 @@ protected void onException(Exception e) throws RuntimeException {
}.execute();
}

private void updateDate(Date date){
if (date == null){
private void updateDate(Date date) {
if (date == null) {
etDate.setVisibility(View.GONE);
mDate = null;
milestone.due_on = null;
Expand Down

0 comments on commit 25bd40d

Please sign in to comment.