Subversion Repositories SmartDukaan

Rev

Rev 28536 | Rev 29929 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
27870 amit.gupta 1
 
21543 ashik.ali 2
package com.spice.profitmandi.common.util;
3
 
23556 amit.gupta 4
import java.text.DecimalFormat;
21543 ashik.ali 5
import java.text.NumberFormat;
23532 amit.gupta 6
import java.time.LocalDateTime;
7
import java.time.format.DateTimeFormatter;
21543 ashik.ali 8
import java.util.Locale;
9
 
10
public class FormattingUtils {
11
 
12
	private static Locale indianLocale = new Locale("en", "IN");
23556 amit.gupta 13
	private static DecimalFormat f = new DecimalFormat("##.00");
14
	private NumberFormat currencyFormat;
24401 amit.gupta 15
	private static DateTimeFormatter dateFormatter = DateTimeFormatter.ofPattern("dd-MM-yyyy");
29910 amit.gupta 16
	private static DateTimeFormatter dateMonthFormatter = DateTimeFormatter.ofPattern("MMM-dd");
24401 amit.gupta 17
	private static DateTimeFormatter reporticoFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
28310 amit.gupta 18
	private static DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("dd-MM-yyyy HH:mm");
28532 amit.gupta 19
	private static DateTimeFormatter ymFormatter = DateTimeFormatter.ofPattern("yyyyMM");
28536 amit.gupta 20
	private static DateTimeFormatter monYYYYFormatter = DateTimeFormatter.ofPattern("MMM, yyyy");
21543 ashik.ali 21
 
28532 amit.gupta 22
	public static String getYearMonth(LocalDateTime dateTime) {
28533 amit.gupta 23
		return dateTime.format(ymFormatter);
28532 amit.gupta 24
	}
25
 
26
 
27
	public static String formatYearMonth(LocalDateTime dateTime) {
28
		return dateTime.format(monYYYYFormatter);
29
	}
30
 
21543 ashik.ali 31
	public FormattingUtils(){
32
		currencyFormat = NumberFormat.getNumberInstance(indianLocale);
33
		currencyFormat.setMaximumFractionDigits(2);
34
		currencyFormat.setMinimumFractionDigits(2);
35
		currencyFormat.setMinimumIntegerDigits(1);
36
	}
37
 
38
	public FormattingUtils(int maximumFractionDigits){
39
		currencyFormat = NumberFormat.getNumberInstance(indianLocale);
40
		currencyFormat.setMaximumFractionDigits(maximumFractionDigits);
41
		currencyFormat.setMinimumIntegerDigits(1);
42
	}
43
 
44
	public String formatPrice(double amount){
45
		return currencyFormat.format(amount);
46
	}
47
 
28310 amit.gupta 48
	public static String format(LocalDateTime localDateTime){
49
		return localDateTime.format(dateTimeFormatter);
50
	}
51
 
23556 amit.gupta 52
	public static String formatDecimalTwoDigits(double number) {
53
		return f.format(number);
54
	}
23532 amit.gupta 55
	public static String formatDate(LocalDateTime dateTime) {
23539 amit.gupta 56
		return dateTime.format(dateFormatter);
23532 amit.gupta 57
	}
29910 amit.gupta 58
	public static String formatDateMonth(LocalDateTime dateTime) {
59
		return dateTime.format(dateMonthFormatter);
60
	}
23532 amit.gupta 61
 
23945 amit.gupta 62
	public static String formatReporitcoDate(LocalDateTime dateTime) {
24251 amit.gupta 63
		if(dateTime==null) return "-";
23945 amit.gupta 64
		return dateTime.format(reporticoFormatter);
65
	}
27870 amit.gupta 66
 
67
	public static String formatShortHand(long value) {
68
		String finalval = null;
69
 
70
		if (value >= 100000 && value < 10000000) {
71
			long reminder = value / 100000;
72
			long quitonent = value % 100000;
73
			finalval = reminder + "." + quitonent;
74
			String secondval = String.valueOf(quitonent);
75
			if (secondval.length() >= 2) {
76
				secondval = secondval.substring(0, 2);
77
				finalval = reminder + "." + secondval;
78
			}
79
			return String.valueOf(finalval) + " Lacs";
80
		} else if (value >= 1000 && value < 100000) {
81
			long reminder = value / 1000;
82
			long quitonent = value % 1000;
83
			finalval = reminder + "." + quitonent;
84
			String secondval = String.valueOf(quitonent);
85
			if (secondval.length() >= 2) {
86
				secondval = secondval.substring(0, 2);
87
				finalval = reminder + "." + secondval;
88
			}
89
			return String.valueOf(finalval) + " K";
90
		} else if (value >= 10000000 && value < 1000000000) {
91
			long reminder = value / 10000000;
92
			long quitonent = value % 10000000;
93
			finalval = reminder + "." + quitonent;
94
			String secondval = String.valueOf(quitonent);
95
			if (secondval.length() >= 2) {
96
				secondval = secondval.substring(0, 2);
97
				finalval = reminder + "." + secondval;
98
			}
99
			return String.valueOf(finalval) + " Cr";
100
		}
101
		return String.valueOf(finalval);
102
 
103
	}
21543 ashik.ali 104
}