Skip to content

Commit

Permalink
Unify & simplify date representation
Browse files Browse the repository at this point in the history
  • Loading branch information
phansier committed Jan 15, 2018
1 parent db30f03 commit d8d5aaf
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;

import static com.github.mobile.Intents.EXTRA_MILESTONE;
import static com.github.mobile.Intents.EXTRA_REPOSITORY_NAME;
Expand Down Expand Up @@ -122,7 +121,7 @@ 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("dd-MM-yyyy");
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 @@ -141,7 +140,7 @@ public void onClick(View v) {
Calendar calendar = Calendar.getInstance();
calendar.setTime(dateOfOrder);
dateAndTime.add(Calendar.DAY_OF_YEAR, noOfDays);
SimpleDateFormat sd = new SimpleDateFormat("dd-MM-yyyy");
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 @@ -153,7 +152,7 @@ public void onClick(View v) {
public void onClick(View v) {
final Calendar dateAndTime = Calendar.getInstance();
dateAndTime.add(Calendar.MONTH, 1);
SimpleDateFormat sd = new SimpleDateFormat("dd-MM-yyyy");
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 @@ -227,17 +226,8 @@ private void updateMilestone() {
descriptionText.setText(milestone.description);
Date dueOn = milestone.due_on;
if (dueOn != null) {
SimpleDateFormat sd = new SimpleDateFormat("dd-MM-yyyy");
try {
Date date = sd.parse(dueOn.toString());
dateText.setText(date.toString());
}
catch (ParseException e){
Calendar cal = new GregorianCalendar();
cal.setTime(dueOn);
dateText.setText(sd.format(cal.getTime()));
//dateText.setText(dueOn.toString());
}
SimpleDateFormat sd = new SimpleDateFormat(getApplicationContext().getString(R.string.ms_date_format));
dateText.setText(sd.format(dueOn));
} else {
dateText.setText("");
}
Expand Down Expand Up @@ -284,12 +274,11 @@ public boolean onOptionsItemSelected(MenuItem item) {
actionBar.setTitle(milestone.title);
milestone.title = titleText.getText().toString();
milestone.description = descriptionText.getText().toString();
SimpleDateFormat sd = new SimpleDateFormat("dd-MM-yyyy");
SimpleDateFormat sd = new SimpleDateFormat(getApplicationContext().getString(R.string.ms_date_format));
try {
Date date = sd.parse(dateText.getText().toString());
milestone.due_on = date;
}
catch (ParseException e){
} catch (ParseException e) {
e.printStackTrace();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ protected int[] getChildViewIds() {

@Override
protected void update(int position, Milestone milestone) {
SimpleDateFormat sdf = new SimpleDateFormat("dd MMM yyyy");
SimpleDateFormat sdf = new SimpleDateFormat(context.getString(R.string.ms_date_format));

setText(0, milestone.title);
setText(1, context.getString(R.string.ms_due_by) + sdf.format(milestone.due_on));
Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -358,5 +358,6 @@
<string name="ms_percent_completed">% completed</string>
<string name="issues_display_closed">Display closed</string>
<string name="issues_display_opened">Display opened</string>
<string name="ms_date_format">dd MMM yyyy</string>

</resources>

0 comments on commit d8d5aaf

Please sign in to comment.