Revision 2555
Added by Jing Tao about 19 years ago
src/edu/ucsb/nceas/metacat/ReplicationHandler.java | ||
---|---|---|
30 | 30 |
import edu.ucsb.nceas.dbadapter.AbstractDatabase; |
31 | 31 |
import java.sql.*; |
32 | 32 |
import java.util.*; |
33 |
import java.util.Date; |
|
33 | 34 |
import java.lang.Thread; |
34 | 35 |
import java.io.*; |
35 | 36 |
import java.net.*; |
... | ... | |
916 | 917 |
return parser; |
917 | 918 |
} |
918 | 919 |
|
920 |
/** |
|
921 |
* This method will combinate given time string(in short format) to |
|
922 |
* current date. If the given time (e.g 10:00 AM) passed the current time |
|
923 |
* (e.g 2:00 PM Aug 21, 2005), then the time will set to second day, |
|
924 |
* 10:00 AM Aug 22, 2005. If the given time (e.g 10:00 AM) haven't passed |
|
925 |
* the current time (e.g 8:00 AM Aug 21, 2005) The time will set to be |
|
926 |
* 10:00 AM Aug 21, 2005. |
|
927 |
* @param givenTime the format should be "10:00 AM " or "2:00 PM" |
|
928 |
* @return |
|
929 |
* @throws Exception |
|
930 |
*/ |
|
931 |
public static Date combinateCurrentDateAndGivenTime(String givenTime) throws Exception |
|
932 |
{ |
|
933 |
Date givenDate = parseTime(givenTime); |
|
934 |
Date newDate = null; |
|
935 |
Date now = new Date(); |
|
936 |
String currentTimeString = getTimeString(now); |
|
937 |
Date currentTime = parseTime(currentTimeString); |
|
938 |
if ( currentTime.getTime() >= givenDate.getTime()) |
|
939 |
{ |
|
940 |
MetaCatUtil.debugMessage("Today already pass the given time, we should set it as tomorrow", 30); |
|
941 |
String dateAndTime = getDateString(now) + " " + givenTime; |
|
942 |
Date combinationDate = parseDateTime(dateAndTime); |
|
943 |
// new date should plus 24 hours to make is the second day |
|
944 |
newDate = new Date(combinationDate.getTime()+24*3600*1000); |
|
945 |
} |
|
946 |
else |
|
947 |
{ |
|
948 |
MetaCatUtil.debugMessage("Today haven't pass the given time, we should it as today", 2); |
|
949 |
String dateAndTime = getDateString(now) + " " + givenTime; |
|
950 |
newDate = parseDateTime(dateAndTime); |
|
951 |
} |
|
952 |
MetaCatUtil.debugMessage("final setting time is "+ newDate.toString(), 20); |
|
953 |
return newDate; |
|
954 |
} |
|
919 | 955 |
|
956 |
/* |
|
957 |
* parse a given string to Time in short format. |
|
958 |
* For example, given time is 10:00 AM, the date will be return as |
|
959 |
* Jan 1 1970, 10:00 AM |
|
960 |
*/ |
|
961 |
private static Date parseTime(String timeString) throws Exception |
|
962 |
{ |
|
963 |
DateFormat format = DateFormat.getTimeInstance(DateFormat.SHORT); |
|
964 |
Date time = format.parse(timeString); |
|
965 |
System.out.println("Date string is after parse a time string "+time.toString()); |
|
966 |
return time; |
|
967 |
|
|
968 |
} |
|
969 |
|
|
970 |
/* |
|
971 |
* Pasre a given string to date and time. Date format is long and time |
|
972 |
* format is short. |
|
973 |
*/ |
|
974 |
private static Date parseDateTime(String timeString) throws Exception |
|
975 |
{ |
|
976 |
DateFormat format = DateFormat.getDateTimeInstance(DateFormat.LONG, DateFormat.SHORT); |
|
977 |
Date time = format.parse(timeString); |
|
978 |
System.out.println("Date string is after parse a time string "+time.toString()); |
|
979 |
return time; |
|
980 |
} |
|
981 |
|
|
982 |
/* |
|
983 |
* Get a date string from a Date object. The date format will be long |
|
984 |
*/ |
|
985 |
private static String getDateString(Date now) |
|
986 |
{ |
|
987 |
DateFormat df = DateFormat.getDateInstance(DateFormat.LONG); |
|
988 |
String s = df.format(now); |
|
989 |
System.out.println("Today is " + s); |
|
990 |
return s; |
|
991 |
} |
|
992 |
|
|
993 |
/* |
|
994 |
* Get a time string from a Date object, the time format will be short |
|
995 |
*/ |
|
996 |
private static String getTimeString(Date now) |
|
997 |
{ |
|
998 |
DateFormat df = DateFormat.getTimeInstance(DateFormat.SHORT); |
|
999 |
String s = df.format(now); |
|
1000 |
System.out.println("Time is " + s); |
|
1001 |
return s; |
|
1002 |
} |
|
920 | 1003 |
} |
921 | 1004 |
|
Also available in: Unified diff
Add some method to setting replication start time.