Skip to content

Commit

Permalink
Fix bug #60
Browse files Browse the repository at this point in the history
  • Loading branch information
tsnik committed Jan 27, 2018
1 parent 5f549cc commit f3928f2
Show file tree
Hide file tree
Showing 2 changed files with 9 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 @@ -103,11 +104,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"));

titleText = finder.find(R.id.et_milestone_title);
descriptionText = finder.find(R.id.et_milestone_description);
dateText = finder.find(R.id.tv_milestone_date);
Expand All @@ -127,7 +133,6 @@ 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);
SimpleDateFormat sd = new SimpleDateFormat(getApplicationContext().getString(R.string.ms_date_format));
final Date startDate = dateAndTime.getTime();
String fdate = sd.format(startDate);
dateText.setText(fdate);
Expand All @@ -146,7 +151,6 @@ public void onClick(View v) {
Calendar calendar = Calendar.getInstance();
calendar.setTime(dateOfOrder);
dateAndTime.add(Calendar.DAY_OF_YEAR, noOfDays);
SimpleDateFormat sd = new SimpleDateFormat(getApplicationContext().getString(R.string.ms_date_format));
final Date startDate = dateAndTime.getTime();
String fdate = sd.format(startDate);
dateText.setText(fdate);
Expand All @@ -158,7 +162,6 @@ public void onClick(View v) {
public void onClick(View v) {
final Calendar dateAndTime = Calendar.getInstance();
dateAndTime.add(Calendar.MONTH, 1);
SimpleDateFormat sd = new SimpleDateFormat(getApplicationContext().getString(R.string.ms_date_format));
final Date startDate = dateAndTime.getTime();
String fdate = sd.format(startDate);
dateText.setText(fdate);
Expand Down Expand Up @@ -235,7 +238,6 @@ private void updateMilestone() {
descriptionText.setText(milestone.description);
Date dueOn = milestone.due_on;
if (dueOn != null) {
SimpleDateFormat sd = new SimpleDateFormat(getApplicationContext().getString(R.string.ms_date_format));
dateText.setText(sd.format(dueOn));
} else {
dateText.setText("");
Expand Down Expand Up @@ -283,7 +285,6 @@ public boolean onOptionsItemSelected(MenuItem item) {
actionBar.setTitle(milestone.title);
milestone.title = titleText.getText().toString();
milestone.description = descriptionText.getText().toString();
SimpleDateFormat sd = new SimpleDateFormat(getApplicationContext().getString(R.string.ms_date_format));
try {
Date date = sd.parse(dateText.getText().toString());
milestone.due_on = date;
Expand Down

0 comments on commit f3928f2

Please sign in to comment.