Skip to content

Commit 8262c03

Browse files
committed
fix bug: use default value if blank value was set in configue file
1 parent 22ee2ad commit 8262c03

File tree

6 files changed

+63
-14
lines changed

6 files changed

+63
-14
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,8 @@
3232

3333
## 待办
3434

35-
[ ] 修正转义不完善的问题(针对`\$`等转义字符)
36-
[ ] 对于可选的留空的配置选项, 使用默认值而不是空字符串作为配置结果
35+
- [ ] 修正转义不完善的问题(针对`\$`等转义字符)
36+
- [x] 对于可选的留空的配置选项, 使用默认值而不是空字符串作为配置结果
3737

3838
## 许可
3939

doc/csti-define.md

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,17 +39,19 @@
3939

4040
此处的值为一个整数, 范围是 `0-7`, 其中 `0``7` 都代表周日
4141

42+
默认会使用与 `semester-start-date` 相吻合的值.
43+
4244
### `semester-start-date`
4345

4446
定义学期的第一天, 格式定为 `yyyy-MM-dd`, 注意这一天的与 `first-day-of-week` 应该相吻合
4547

4648
### `reminder-time`
4749

48-
定义课程的提醒时间, 整数表示延后, 负数表示提前, 单位支持 `s`\`m``h`, 分别表示提前或者延后的秒\\时.
50+
定义课程的提醒时间, 整数表示延后, 负数表示提前, 单位支持 `s`\\`m``h`, 分别表示提前或者延后的秒\\\\时.
4951

50-
可以填写多个值, 其间使用逗号分隔, 表示对于同一节课提醒多次
52+
可以填写多个值, 其间使用逗号分隔, 表示对于同一节课提醒多次.
5153

52-
比如 `-1h,-15m` 表示在上课前1小时和前15分钟提醒两次
54+
> 比如 `-1h,-15m` 表示在上课前1小时和前15分钟提醒两次.
5355
5456
### `lesson-ranges`
5557

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
<groupId>com.github.leafee98</groupId>
88
<artifactId>class-schedule-to-icalendar-core</artifactId>
9-
<version>v0.0.2</version>
9+
<version>v0.0.3</version>
1010

1111
<name>class schedule to icalendar core</name>
1212

src/main/java/com/github/leafee98/CSTI/core/bean/Configure.java

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,9 @@ public class Configure {
2828
// default is system default time zone
2929
private ZoneId timezone = ZoneId.systemDefault();
3030

31-
// default is 0, means Sunday
32-
private int firstDayOfWeek = 0;
31+
// default unset, init when loading from configure file
32+
// use day of semesterStartDate if not present in configure file
33+
private int firstDayOfWeek = -1;
3334

3435
// no default, and must occur in config file
3536
private LocalDate semesterStartDate;
@@ -50,16 +51,30 @@ public static Configure load(String str) {
5051
for (String line : lines) {
5152
if (line.startsWith(KeyWords.eventSummaryFormat)) {
5253
// keep white spaces of format description
53-
result.setEventSummaryFormat(line.substring(KeyWords.eventSummaryFormat.length() + 1));
54+
String tmp = line.substring(KeyWords.eventSummaryFormat.length() + 1);
55+
if (tmp.trim().length() != 0) {
56+
result.setEventSummaryFormat(tmp);
57+
}
58+
// result.setEventSummaryFormat(line.substring(KeyWords.eventSummaryFormat.length() + 1));
5459
} else if (line.startsWith(KeyWords.eventDescriptionFormat)) {
55-
result.setEventDescriptionFormat(line.substring(KeyWords.eventDescriptionFormat.length() + 1));
60+
String tmp = line.substring(KeyWords.eventDescriptionFormat.length() + 1);
61+
if (tmp.trim().length() != 0) {
62+
result.setEventDescriptionFormat(tmp);
63+
}
64+
// result.setEventDescriptionFormat(line.substring(KeyWords.eventDescriptionFormat.length() + 1));
5665
} else if (line.startsWith(KeyWords.firstDayOfWeek)) {
5766
// take 0 as Sunday
58-
int dow = Integer.parseInt(line.substring(KeyWords.firstDayOfWeek.length() + 1).trim());
59-
result.setFirstDayOfWeek(dow % 7);
67+
String tmp = line.substring(KeyWords.firstDayOfWeek.length() + 1).trim();
68+
if (tmp.length() != 0) {
69+
int dow = Integer.parseInt(tmp);
70+
result.setFirstDayOfWeek(dow % 7);
71+
}
6072
} else if (line.startsWith(KeyWords.semesterStartDate)) {
6173
result.setSemesterStartDate(
6274
LocalDate.parse(line.substring(KeyWords.semesterStartDate.length() + 1).trim()));
75+
if (result.getFirstDayOfWeek() < 0) {
76+
result.setFirstDayOfWeek(result.getSemesterStartDate().getDayOfWeek().getValue());
77+
}
6378
} else if (line.startsWith(KeyWords.reminderTime)) {
6479
// get reminder description and remove redundant spaces
6580
List<String> reminder = new ArrayList<>();

src/test/java/com/github/leafee98/CSTI/core/ConfigureTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ public class ConfigureTest {
1111
public void testLoad() {
1212
String expected =
1313
"event-summary-format:lesson${lessonName}location${location}-${schedule}${teacher}\n"
14-
+ "event-description-format:\n"
14+
+ "event-description-format:name:${lessonName}\\nlocation:${location}\\nteacher:${teacher}\\ntype:${lessonType}\\nremark:${remark}\\nschedule:${scheduleFull}\n"
1515
+ "timezone:Asia/Shanghai\n"
1616
+ "first-day-of-week:5\n"
1717
+ "semester-start-date:2020-02-21\n"

src/test/java/com/github/leafee98/CSTI/core/ScheduleObjectTest.java

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,40 @@ public void test() {
4141
" 4,6-7,9-10|1|1-3;\n" +
4242
">>>\n";
4343

44+
String expected = "[[[\n" +
45+
"event-summary-format:lesson${lessonName}location${location}-${schedule}${teacher}\n" +
46+
"event-description-format:name:${lessonName}\\nlocation:${location}\\nteacher:${teacher}\\ntype:${lessonType}\\nremark:${remark}\\nschedule:${scheduleFull}\n" +
47+
"timezone:Asia/Shanghai\n" +
48+
"first-day-of-week:5\n" +
49+
"semester-start-date:2020-02-21\n" +
50+
"reminder-time:-15m\n" +
51+
"lesson-ranges:\n" +
52+
" 1=08:00:00-08:45:00,\n" +
53+
" 2=08:50:00-09:35:00,\n" +
54+
" 3=09:50:00-10:35:00,\n" +
55+
" 4=10:40:00-11:25:00,\n" +
56+
" 5=11:30:00-12:15:00,\n" +
57+
" 6=13:30:00-14:15:00,\n" +
58+
" 7=14:20:00-15:05:00,\n" +
59+
" 8=15:20:00-16:05:00,\n" +
60+
" 9=16:10:00-16:55:00,\n" +
61+
" 10=18:30:00-19:15:00,\n" +
62+
" 11=19:20:00-20:05:00,\n" +
63+
" 12=20:10:00-20:55:00\n" +
64+
"]]]\n" +
65+
"<<<\n" +
66+
"name:C语言课\n" +
67+
"type:专业必修课\n" +
68+
"teacher:某某大师\n" +
69+
"location:某校区某楼某层某室\n" +
70+
"remark:其实暂时没什么其他信息的啦\n" +
71+
"schedule:\n" +
72+
" 4,7-8,10|1|1,3;\n" +
73+
" 4,6-7,9-10|1|1-3;\n" +
74+
">>>\n";
75+
4476
ScheduleObject obj = ScheduleObject.load(BreakLine.recovery(input));
45-
Assertions.assertEquals(input, BreakLine.doBreak(obj.toString(), false));
77+
Assertions.assertEquals(expected, BreakLine.doBreak(obj.toString(), false));
4678
}
4779

4880
}

0 commit comments

Comments
 (0)