Skip to content

Commit

Permalink
Merge pull request #456 from TypicalGitHubUser/medium-date-error-fix
Browse files Browse the repository at this point in the history
Fix converting date to medium format.
  • Loading branch information
therajanmaurya authored Mar 14, 2017
2 parents c75ed46 + 70c94d7 commit 3f11163
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -145,8 +145,8 @@ public void showCenterDetails(CenterWithAssociations centerWithAssociations) {
setToolbarTitle(centerWithAssociations.getName());
if (!centerWithAssociations.getActivationDate().isEmpty()) {
tvStaffName.setText(centerWithAssociations.getStaffName());
tvActivationDate.setText(Utils.getStringOfDate(getContext(),
centerWithAssociations.getActivationDate()));
tvActivationDate.setText(Utils.getStringOfDate
(centerWithAssociations.getActivationDate()));
}
}

Expand All @@ -162,9 +162,8 @@ public void showMeetingDetails(CenterWithAssociations centerWithAssociations) {
getView().findViewById(R.id.row_meeting_frequency).setVisibility(View.GONE);
}
} else {
tvMeetingDate.setText(Utils.getStringOfDate(getContext(),
centerWithAssociations.getCollectionMeetingCalendar()
.getNextTenRecurringDates().get(0)));
tvMeetingDate.setText(Utils.getStringOfDate(centerWithAssociations
.getCollectionMeetingCalendar().getNextTenRecurringDates().get(0)));
if (getView() != null) {
getView().findViewById(R.id.row_meeting_frequency).setVisibility(View.VISIBLE);
tvMeetingFrequency.setText(centerWithAssociations.getCollectionMeetingCalendar()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -405,7 +405,7 @@ public void showClientInformation(Client client) {
rowExternal.setVisibility(GONE);

try {
String dateString = Utils.getStringOfDate(getActivity(),
String dateString = Utils.getStringOfDate(
client.getActivationDate());
tv_activationDate.setText(dateString);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ public void showGroup(Group group) {
tv_externalId.setText(group.getExternalId());

try {
String dateString = Utils.getStringOfDate(getActivity(), group.getActivationDate());
String dateString = Utils.getStringOfDate(group.getActivationDate());
tv_activationDate.setText(dateString);

if (TextUtils.isEmpty(dateString))
Expand Down
28 changes: 12 additions & 16 deletions mifosng-android/src/main/java/com/mifos/utils/Utils.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,17 @@
import android.graphics.drawable.Drawable;
import android.graphics.drawable.LayerDrawable;
import android.support.v4.content.ContextCompat;
import android.util.Log;

import com.mifos.mifosxdroid.R;
import com.mifos.objects.PaymentTypeOption;
import com.mifos.objects.accounts.loan.LoanAccount;
import com.mifos.objects.accounts.savings.SavingsAccount;

import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.Calendar;
import java.util.List;
import java.util.TimeZone;

import rx.Observable;
import rx.functions.Action1;
Expand Down Expand Up @@ -125,21 +123,19 @@ public void call(SavingsAccount savingsAccount) {
/**
* This Method Converting the List<Integer> of Activation Date to String.
*
* @param context Context
* @param dateObj List<Integer> of Date
* @return
*/
public static String getStringOfDate(Context context, List<Integer> dateObj) {
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("dd MMM yyyy",
context.getResources().getConfiguration().locale);
Date date = null;
try {
date = simpleDateFormat.parse(DateHelper.getDateAsString(dateObj));
} catch (ParseException e) {
Log.d(LOG_TAG, e.getLocalizedMessage());
}
public static String getStringOfDate(List<Integer> dateObj) {
Calendar calendar = Calendar.getInstance();
calendar.setTimeZone(TimeZone.getTimeZone("UTC"));
calendar.set(Calendar.YEAR, dateObj.get(0));
//in Calendar months are indexed from 0 to 11
calendar.set(Calendar.MONTH, dateObj.get(1) - 1);
calendar.set(Calendar.DAY_OF_MONTH, dateObj.get(2));

DateFormat df = DateFormat.getDateInstance(DateFormat.MEDIUM);
return df.format(date);
return df.format(calendar.getTime());
}

public static LayerDrawable setCircularBackground(int colorId, Context context) {
Expand All @@ -148,4 +144,4 @@ public static LayerDrawable setCircularBackground(int colorId, Context context)
LayerDrawable ld = new LayerDrawable(new Drawable[]{image, color});
return ld;
}
}
}

0 comments on commit 3f11163

Please sign in to comment.