Skip to content

Commit

Permalink
fix: Fix converting date to medium format. (#454)
Browse files Browse the repository at this point in the history
  • Loading branch information
k4wel committed Dec 20, 2016
1 parent 1522bd3 commit bc0015f
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -505,7 +505,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 @@ -162,7 +162,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: 11 additions & 17 deletions mifosng-android/src/main/java/com/mifos/utils/Utils.java
Original file line number Diff line number Diff line change
@@ -1,18 +1,14 @@
package com.mifos.utils;

import android.content.Context;
import android.util.Log;

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 @@ -120,20 +116,18 @@ 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());
}
}

0 comments on commit bc0015f

Please sign in to comment.