| 27870 |
amit.gupta |
1 |
|
| 21543 |
ashik.ali |
2 |
package com.spice.profitmandi.common.util;
|
|
|
3 |
|
|
|
4 |
import java.text.NumberFormat;
|
| 23532 |
amit.gupta |
5 |
import java.time.LocalDateTime;
|
|
|
6 |
import java.time.format.DateTimeFormatter;
|
| 21543 |
ashik.ali |
7 |
import java.util.Locale;
|
|
|
8 |
|
|
|
9 |
public class FormattingUtils {
|
|
|
10 |
|
| 29929 |
amit.gupta |
11 |
private static final NumberFormat currencyFormatter = NumberFormat.getCurrencyInstance(new Locale("en", "IN"));
|
|
|
12 |
private static final NumberFormat numberFormatter = NumberFormat.getNumberInstance(new Locale("en", "IN"));
|
|
|
13 |
private static final DateTimeFormatter dateFormatter = DateTimeFormatter.ofPattern("dd-MM-yyyy");
|
|
|
14 |
private static final DateTimeFormatter dateMonthFormatter = DateTimeFormatter.ofPattern("MMM-dd");
|
|
|
15 |
private static final DateTimeFormatter reporticoFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
|
|
|
16 |
private static final DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("dd-MM-yyyy HH:mm");
|
|
|
17 |
private static final DateTimeFormatter ymFormatter = DateTimeFormatter.ofPattern("yyyyMM");
|
|
|
18 |
private static final DateTimeFormatter monYYYYFormatter = DateTimeFormatter.ofPattern("MMM, yyyy");
|
|
|
19 |
|
| 28532 |
amit.gupta |
20 |
public static String getYearMonth(LocalDateTime dateTime) {
|
| 28533 |
amit.gupta |
21 |
return dateTime.format(ymFormatter);
|
| 28532 |
amit.gupta |
22 |
}
|
| 29929 |
amit.gupta |
23 |
|
|
|
24 |
|
| 28532 |
amit.gupta |
25 |
public static String formatYearMonth(LocalDateTime dateTime) {
|
|
|
26 |
return dateTime.format(monYYYYFormatter);
|
|
|
27 |
}
|
| 29929 |
amit.gupta |
28 |
|
|
|
29 |
public static String formatDecimal(double number) {
|
|
|
30 |
return numberFormatter.format(number).replace("\\.00", "");
|
| 21543 |
ashik.ali |
31 |
}
|
| 29929 |
amit.gupta |
32 |
|
|
|
33 |
public static String formatDecimal(int number) {
|
|
|
34 |
return numberFormatter.format(number).replace("\\.00", "");
|
| 21543 |
ashik.ali |
35 |
}
|
| 29929 |
amit.gupta |
36 |
|
|
|
37 |
public static String formatDecimal(long number) {
|
|
|
38 |
return numberFormatter.format(number).replace("\\.00", "");
|
| 21543 |
ashik.ali |
39 |
}
|
| 29929 |
amit.gupta |
40 |
|
|
|
41 |
public static String formatDecimal(float number) {
|
|
|
42 |
return numberFormatter.format(number).replace("\\.00", "");
|
|
|
43 |
}
|
|
|
44 |
/*
|
|
|
45 |
public String formatDecimal(double amount){
|
|
|
46 |
return numberFormatter.format(amount).replace("\\.00", "");
|
|
|
47 |
}*/
|
|
|
48 |
|
|
|
49 |
public static String format(LocalDateTime localDateTime) {
|
| 28310 |
amit.gupta |
50 |
return localDateTime.format(dateTimeFormatter);
|
|
|
51 |
}
|
| 29929 |
amit.gupta |
52 |
|
|
|
53 |
public String formatPrice(double amount) {
|
|
|
54 |
return currencyFormatter.format(amount).replace("\\.00", "");
|
| 23556 |
amit.gupta |
55 |
}
|
| 29929 |
amit.gupta |
56 |
|
|
|
57 |
public String formatPrice(float amount) {
|
|
|
58 |
return currencyFormatter.format(amount).replace("\\.00", "");
|
|
|
59 |
}
|
|
|
60 |
|
|
|
61 |
public String formatPrice(int amount) {
|
|
|
62 |
return currencyFormatter.format(amount).replace("\\.00", "");
|
|
|
63 |
}
|
|
|
64 |
|
|
|
65 |
public String formatPrice(long amount) {
|
|
|
66 |
return currencyFormatter.format(amount).replace("\\.00", "");
|
|
|
67 |
}
|
|
|
68 |
|
| 23532 |
amit.gupta |
69 |
public static String formatDate(LocalDateTime dateTime) {
|
| 23539 |
amit.gupta |
70 |
return dateTime.format(dateFormatter);
|
| 23532 |
amit.gupta |
71 |
}
|
| 29929 |
amit.gupta |
72 |
|
| 29910 |
amit.gupta |
73 |
public static String formatDateMonth(LocalDateTime dateTime) {
|
|
|
74 |
return dateTime.format(dateMonthFormatter);
|
|
|
75 |
}
|
| 29929 |
amit.gupta |
76 |
|
| 23945 |
amit.gupta |
77 |
public static String formatReporitcoDate(LocalDateTime dateTime) {
|
| 29929 |
amit.gupta |
78 |
if (dateTime == null) return "-";
|
| 23945 |
amit.gupta |
79 |
return dateTime.format(reporticoFormatter);
|
|
|
80 |
}
|
| 21543 |
ashik.ali |
81 |
}
|