Subversion Repositories SmartDukaan

Rev

Rev 21986 | Rev 22242 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 21986 Rev 22215
Line 3... Line 3...
3
import java.time.Instant;
3
import java.time.Instant;
4
import java.time.LocalDate;
4
import java.time.LocalDate;
5
import java.time.LocalDateTime;
5
import java.time.LocalDateTime;
6
import java.time.LocalTime;
6
import java.time.LocalTime;
7
import java.time.ZoneId;
7
import java.time.ZoneId;
-
 
8
import java.time.format.DateTimeFormatter;
8
import java.time.format.DateTimeParseException;
9
import java.time.format.DateTimeParseException;
9
import java.util.ArrayList;
10
import java.util.ArrayList;
10
import java.util.List;
11
import java.util.List;
11
 
12
 
12
import javax.mail.internet.InternetAddress;
13
import javax.mail.internet.InternetAddress;
Line 20... Line 21...
20
public class StringUtils {
21
public class StringUtils {
21
	
22
	
22
	private static ObjectMapper objectMapper = new ObjectMapper();
23
	private static ObjectMapper objectMapper = new ObjectMapper();
23
	
24
	
24
	private static final Logger LOGGER = LoggerFactory.getLogger(StringUtils.class);
25
	private static final Logger LOGGER = LoggerFactory.getLogger(StringUtils.class);
25
	
-
 
-
 
26
	private static final String DATE_PATTERN = "MM/dd/yyyy";
26
	private StringUtils(){
27
	private StringUtils(){
27
 
28
 
28
	}
29
	}
29
	public static final LocalDate toDate(String dateString)throws DateTimeParseException{
30
	public static final LocalDate toDate(String dateString)throws DateTimeParseException{
-
 
31
		LOGGER.info("Converting dateString [{}] with pattern[{}]", dateString, DATE_PATTERN);
-
 
32
		DateTimeFormatter formatter = DateTimeFormatter.ofPattern(DATE_PATTERN);
30
		return LocalDate.parse(dateString);
33
		return LocalDate.parse(dateString, formatter);
31
	}
34
	}
32
 
35
 
33
	public static final LocalTime toTime(String timeString) throws DateTimeParseException{
36
	public static final LocalTime toTime(String timeString) throws DateTimeParseException{
34
		return LocalTime.parse(timeString);
37
		return LocalTime.parse(timeString);
35
	}
38
	}
36
	
39
	
37
	public static final LocalDateTime toDateTime(long epocTime){
40
	public static final LocalDateTime toDateTime(long epocTime){
38
		return Instant.ofEpochMilli(epocTime).atZone(ZoneId.systemDefault()).toLocalDateTime();
41
		return Instant.ofEpochMilli(epocTime).atZone(ZoneId.systemDefault()).toLocalDateTime();
39
	}
42
	}
40
	
43
	
-
 
44
	public static final String toString(LocalDate localDate){
-
 
45
		DateTimeFormatter formatter = DateTimeFormatter.ofPattern(DATE_PATTERN);
-
 
46
		String formattedDateTime = localDate.format(formatter); // "1986-04-08 12:30"
-
 
47
		return formattedDateTime;
-
 
48
	}
-
 
49
	
41
	public static final LocalDateTime toDateTime(String dateTimeString) throws DateTimeParseException{
50
	public static final LocalDateTime toDateTime(String dateTimeString) throws DateTimeParseException{
42
		if(dateTimeString == null || dateTimeString.equals("0")){
51
		if(dateTimeString == null || dateTimeString.equals("0")){
43
			return null;
52
			return null;
44
		}
53
		}
45
		LocalDateTime date =
54
		LocalDateTime date =
Line 109... Line 118...
109
		}
118
		}
110
		return true;
119
		return true;
111
		
120
		
112
	}
121
	}
113
	
122
	
-
 
123
	public static String generatePolicyNumber(String prefix, int sequence){
-
 
124
		String policyNumber = String.format(prefix + "%06d", sequence);
-
 
125
		LOGGER.info("Generated Policy Number {}", policyNumber);
-
 
126
		return policyNumber;
114
	
127
	}
115
 
128
 
116
}
129
}