-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #178 from Telephone2019/work
Work
- Loading branch information
Showing
62 changed files
with
1,969 additions
and
1,060 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
287 changes: 165 additions & 122 deletions
287
app/src/main/java/com/telephone/coursetable/Clock/Clock.java
Large diffs are not rendered by default.
Oops, something went wrong.
160 changes: 160 additions & 0 deletions
160
app/src/main/java/com/telephone/coursetable/Clock/DateTime.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,160 @@ | ||
package com.telephone.coursetable.Clock; | ||
|
||
import androidx.annotation.NonNull; | ||
import androidx.annotation.Nullable; | ||
|
||
import java.util.Calendar; | ||
import java.util.Date; | ||
import java.util.Locale; | ||
import java.util.Scanner; | ||
import java.util.TimeZone; | ||
import java.util.regex.Pattern; | ||
|
||
public class DateTime { | ||
|
||
public static TimeZone timezone_GMT8 = TimeZone.getTimeZone("GMT+08:00"); | ||
|
||
private TimeZone tz; | ||
private Calendar cld; | ||
|
||
private final int year; | ||
private final int month; | ||
private final int day; | ||
private int weekday; | ||
|
||
public int hour_24; | ||
public int minute; | ||
public int second; | ||
|
||
public static DateTime getGMT8_Instance(long timestamp){ | ||
return new DateTime(DateTime.timezone_GMT8, timestamp); | ||
} | ||
|
||
public static DateTime getDefault_Instance(long timestamp){ | ||
return new DateTime(TimeZone.getDefault(), timestamp); | ||
} | ||
|
||
/** | ||
* the {@link #weekday} won't be set | ||
* the data MUST be valid | ||
* all of the the time fields will be set to 0 | ||
*/ | ||
public DateTime(TimeZone tz, int year, int month, int day){ | ||
this.tz = tz; | ||
this.cld = Calendar.getInstance(this.tz); | ||
|
||
this.year = year; | ||
this.month = month; | ||
this.day = day; | ||
|
||
this.hour_24 = 0; | ||
this.minute = 0; | ||
this.second = 0; | ||
} | ||
|
||
public DateTime(TimeZone timeZone, long timestamp){ | ||
this.tz = timeZone; | ||
this.cld = Calendar.getInstance(this.tz); | ||
|
||
cld.setTime(new Date(timestamp)); | ||
this.year = cld.get(Calendar.YEAR); | ||
this.month = cld.get(Calendar.MONTH) + 1; | ||
this.day = cld.get(Calendar.DAY_OF_MONTH); | ||
this.weekday = cld.get(Calendar.DAY_OF_WEEK) - 1; | ||
if (this.weekday == 0){ | ||
this.weekday = 7; | ||
} | ||
this.hour_24 = cld.get(Calendar.HOUR_OF_DAY); | ||
this.minute = cld.get(Calendar.MINUTE); | ||
this.second = cld.get(Calendar.SECOND); | ||
} | ||
|
||
public DateTime(DateTime src, @NonNull String time_string, @NonNull String delimiter) { | ||
this.tz = src.tz; | ||
this.cld = Calendar.getInstance(this.tz); | ||
|
||
this.year = src.year; | ||
this.month = src.month; | ||
this.day = src.day; | ||
this.weekday = src.weekday; | ||
Scanner scanner = new Scanner(time_string); | ||
scanner.useDelimiter(delimiter); | ||
this.hour_24 = scanner.nextInt(); | ||
this.minute = scanner.nextInt(); | ||
if (scanner.hasNext()) { | ||
this.second = scanner.nextInt(); | ||
} else { | ||
this.second = 0; | ||
} | ||
} | ||
|
||
public long getTime(){ | ||
cld.set( | ||
this.year, | ||
this.month - 1, | ||
this.day, | ||
this.hour_24, | ||
this.minute, | ||
this.second | ||
); | ||
return cld.getTime().getTime(); | ||
} | ||
|
||
public int getYear() { | ||
return year; | ||
} | ||
|
||
public int getMonth() { | ||
return month; | ||
} | ||
|
||
public int getDay() { | ||
return day; | ||
} | ||
|
||
public int getWeekday() { | ||
return weekday; | ||
} | ||
|
||
public boolean equals(@NonNull DateTime dateTime) { | ||
return this.getTime() == dateTime.getTime(); | ||
} | ||
|
||
public boolean before(@NonNull DateTime dateTime){ | ||
return this.getTime() < dateTime.getTime(); | ||
} | ||
|
||
public boolean after(@NonNull DateTime dateTime){ | ||
return this.getTime() > dateTime.getTime(); | ||
} | ||
|
||
public boolean before_or_equals(@NonNull DateTime dateTime){ | ||
return this.getTime() < dateTime.getTime() || this.getTime() == dateTime.getTime(); | ||
} | ||
|
||
public boolean after_or_equals(@NonNull DateTime dateTime){ | ||
return this.getTime() > dateTime.getTime() || this.getTime() == dateTime.getTime(); | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "DateTime{" + | ||
"year=" + year + | ||
", month=" + month + | ||
", day=" + day + | ||
", weekday=" + weekday + | ||
", hour_24=" + hour_24 + | ||
", minute=" + minute + | ||
", second=" + second + | ||
", timestamp=" + this.getTime() + | ||
'}'; | ||
} | ||
|
||
public String dateTimeString(){ | ||
return String.format(Locale.getDefault(), "%04d-%02d-%02d %02d:%02d:%02d %s", year, month, day, hour_24, minute, second, tz.getDisplayName()); | ||
} | ||
|
||
public String dateTimeString(Locale locale){ | ||
return String.format(Locale.getDefault(), "%04d-%02d-%02d %02d:%02d:%02d %s", year, month, day, hour_24, minute, second, tz.getDisplayName(locale)); | ||
} | ||
} |
69 changes: 69 additions & 0 deletions
69
app/src/main/java/com/telephone/coursetable/Clock/GetDateInfo.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
package com.telephone.coursetable.Clock; | ||
|
||
import android.content.SharedPreferences; | ||
|
||
import androidx.annotation.Nullable; | ||
import androidx.core.content.res.TypedArrayUtils; | ||
|
||
import com.telephone.coursetable.Database.TermInfo; | ||
import com.telephone.coursetable.Database.TermInfoDao; | ||
import com.telephone.coursetable.MyApp; | ||
|
||
import java.util.Arrays; | ||
import java.util.LinkedList; | ||
import java.util.List; | ||
|
||
public class GetDateInfo { | ||
|
||
// 遇事不决,GMT+8 | ||
public static String[] get_a_week_date_info_all_timezone_using_gmt8(@Nullable TermInfo termInfo, long weekNum){ | ||
|
||
long[] a_week_ts; | ||
|
||
if(termInfo == null || weekNum <= 0){ | ||
long nts = Clock.nowTimeStamp(); | ||
long today_ts1 = nts; | ||
long today_ts2 = nts; | ||
|
||
List<Long> ts_list = new LinkedList<>(); | ||
ts_list.add(nts); | ||
|
||
int expand_num = 6; | ||
|
||
for (int i = 0; i < expand_num; i++) { | ||
today_ts1 -= 86400000L; | ||
ts_list.add(0, today_ts1); | ||
} | ||
|
||
for (int i = 0; i < expand_num; i++) { | ||
today_ts2 += 86400000L; | ||
ts_list.add(today_ts2); | ||
} | ||
|
||
DateTime now_gmt8 = DateTime.getGMT8_Instance(nts); | ||
|
||
int start_index = expand_num - (now_gmt8.getWeekday() - 1); | ||
int end_index = expand_num + (7 - now_gmt8.getWeekday()); | ||
|
||
Long[] a_week_ts_Long = Arrays.copyOfRange(ts_list.toArray(new Long[0]), start_index, end_index + 1); | ||
a_week_ts = new long[a_week_ts_Long.length]; | ||
for (int i = 0; i < a_week_ts_Long.length; i++) { | ||
a_week_ts[i] = a_week_ts_Long[i]; | ||
} | ||
}else { | ||
a_week_ts = Clock.getAWeekTimeStampForWeekSince( | ||
termInfo.sts, | ||
weekNum | ||
); | ||
} | ||
|
||
String[] data_info_ary = new String[a_week_ts.length]; | ||
|
||
for (int i = 0; i < a_week_ts.length; i++) { | ||
DateTime dateTime_gmt8 = DateTime.getGMT8_Instance(a_week_ts[i]); | ||
data_info_ary[i] = dateTime_gmt8.getMonth() + "." + dateTime_gmt8.getDay(); | ||
} | ||
|
||
return data_info_ary; | ||
} | ||
} |
Oops, something went wrong.