Skip to content

Commit

Permalink
fix: Fix converting date to medium format. (#455)
Browse files Browse the repository at this point in the history
  • Loading branch information
k4wel committed Feb 27, 2017
1 parent 8b570c6 commit 7965c35
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 17 deletions.
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
27 changes: 12 additions & 15 deletions mifosng-android/src/main/java/com/mifos/utils/Utils.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,10 @@
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 +124,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 +145,4 @@ public static LayerDrawable setCircularBackground(int colorId, Context context)
LayerDrawable ld = new LayerDrawable(new Drawable[]{image, color});
return ld;
}
}
}

0 comments on commit 7965c35

Please sign in to comment.