Skip to content

Commit cbc69a4

Browse files
committed
Only show holidays that are national, not local
Bumped plugins / dependencies Updated tests to accomode the holiday change
1 parent e68ca65 commit cbc69a4

File tree

8 files changed

+52
-31
lines changed

8 files changed

+52
-31
lines changed

.idea/misc.xml

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/vcs.xml

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

CODE_OF_CONDUCT.md

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

55
We as members, contributors, and leaders pledge to make participation in our
66
community a harassment-free experience for everyone, regardless of age, body
7-
size, visible or invisible disability, ethnicity, sex characteristics, gender
8-
identity and expression, level of experience, education, socio-economic status,
7+
size, visible or invisible disability, ethnicity, sex characteristics,
8+
level of experience, education, socio-economic status,
99
nationality, personal appearance, race, religion, or sexual identity
1010
and orientation.
1111

pom.xml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
<groupId>org.fross</groupId>
55
<artifactId>cal</artifactId>
6-
<version>2.7.5</version>
6+
<version>2.7.6</version>
77
<packaging>jar</packaging>
88

99
<name>cal</name>
@@ -113,7 +113,7 @@
113113
<plugin>
114114
<groupId>org.apache.maven.plugins</groupId>
115115
<artifactId>maven-surefire-plugin</artifactId>
116-
<version>3.5.2</version>
116+
<version>3.5.3</version>
117117
</plugin>
118118

119119
<!-- ========================================================================================== -->
@@ -252,7 +252,7 @@
252252
<dependency>
253253
<groupId>com.google.code.gson</groupId>
254254
<artifactId>gson</artifactId>
255-
<version>2.12.1</version>
255+
<version>2.13.1</version>
256256
</dependency>
257257

258258
<!-- Fross library functions: https://github.com/frossm/library -->

snap/snapcraft.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name: fcal
2-
version: '2.7.5'
2+
version: '2.7.6'
33
summary: Command line calendar display
44
description: |
55
fCal is a command line calendar utility. It will display a

src/main/java/org/fross/cal/CommandLineArgs.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,7 @@ public static void ProcessCommandLine(String[] argv) {
128128
// Clear the holiday cache in the Java preferences system
129129
if (cli.clClearCache == true) {
130130
clearCache();
131+
System.exit(0);
131132
}
132133

133134
// Show Help and Exit
@@ -206,7 +207,6 @@ public static void clearCache() {
206207
try {
207208
prefHolidayCache.removeNode();
208209
Output.printColorln(Ansi.Color.CYAN, "Clearing the local holiday cache");
209-
System.exit(0);
210210

211211
} catch (BackingStoreException ex) {
212212
Output.printColorln(Ansi.Color.RED, "ERROR: Could not clear the holiday cache");

src/main/java/org/fross/cal/Holidays.java

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -122,11 +122,16 @@ public static TreeMap<String, String> getHolidays(int year) {
122122
TreeMap<String, Object>[] gsonMap = gson.fromJson(holidayRawData, TreeMap[].class);
123123

124124
// Loop through the <String,Object> map and convert it to a <String, String> TreeMap
125+
// Note, only use holidays that are listed as "global: true" as others are not national holidays
125126
for (int holidayEntry = 0; holidayEntry < gsonMap.length; holidayEntry++) {
126-
holidays.put(gsonMap[holidayEntry].get("date").toString(), gsonMap[holidayEntry].get("localName").toString());
127-
128-
// Save the holiday information into the preferences cache
129-
prefHolidayCache.put(gsonMap[holidayEntry].get("date").toString(), gsonMap[holidayEntry].get("localName").toString());
127+
if (gsonMap[holidayEntry].get("global").toString().equals("true")) {
128+
holidays.put(gsonMap[holidayEntry].get("date").toString(), gsonMap[holidayEntry].get("localName").toString());
129+
130+
// Save the holiday information into the preferences cache
131+
prefHolidayCache.put(gsonMap[holidayEntry].get("date").toString(), gsonMap[holidayEntry].get("localName").toString());
132+
} else {
133+
Output.debugPrintln("Skipping non-global holiday: " + gsonMap[holidayEntry].get("localName"));
134+
}
130135
}
131136

132137
} catch (Exception ex) {

src/test/java/org/fross/cal/HolidaysTest.java

Lines changed: 34 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,31 @@
11
/******************************************************************************
22
* Cal - A command line calendar utility
3-
*
3+
* <p>
44
* Copyright (c) 2019-2025 Michael Fross
5-
*
5+
* <p>
66
* Permission is hereby granted, free of charge, to any person obtaining a copy
77
* of this software and associated documentation files (the "Software"), to deal
88
* in the Software without restriction, including without limitation the rights
99
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
1010
* copies of the Software, and to permit persons to whom the Software is
1111
* furnished to do so, subject to the following conditions:
12-
*
12+
* <p>
1313
* The above copyright notice and this permission notice shall be included in all
1414
* copies or substantial portions of the Software.
15-
*
15+
* <p>
1616
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
1717
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
1818
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
1919
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
2020
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
2121
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
2222
* SOFTWARE.
23-
*
23+
* <p>
2424
******************************************************************************/
2525
package org.fross.cal;
2626

2727
import org.fross.library.Output;
28+
import org.junit.jupiter.api.Assertions;
2829
import org.junit.jupiter.api.Test;
2930

3031
import java.util.Locale;
@@ -68,27 +69,33 @@ class HolidaysTest {
6869
//
6970
// }
7071

71-
// Test holiday list - US
72+
// Test holiday list - US 2023
7273
@Test
7374
void holidayListTestUS() {
75+
Locale.setDefault(Locale.US);
76+
Output.println("Current locale set to: " + Locale.getDefault().getDisplayCountry());
77+
7478
// ------------------------------------------------------------------------
7579
// For now, skip this test if the JVM does not report it's in the US
7680
// ------------------------------------------------------------------------
77-
if (Locale.getDefault().getDisplayCountry().toString().compareTo("United States") != 0) {
81+
if (Locale.getDefault().getDisplayCountry().compareTo("United States") != 0) {
7882
Output.println("Current locale set to: '" + Locale.getDefault().getDisplayCountry() + "' -- Skipping Test");
7983
return;
8084
}
8185

86+
// Clear the cache before the test
87+
CommandLineArgs.clearCache();
88+
8289
Output.print("Current locale set to: '" + Locale.getDefault().getDisplayCountry() + "'");
8390

8491
// Get the holiday list for the US in 2023
8592
TreeMap<String, String> holidayListUS = Holidays.getHolidays(2023);
8693

8794
// There should be 12 holidays in 2023
88-
assertEquals(14, holidayListUS.size());
95+
Assertions.assertNotNull(holidayListUS);
96+
assertEquals(10, holidayListUS.size());
8997

90-
String[] correctValuesUS = {"2023-01-02", "2023-01-16", "2023-02-12", "2023-02-20", "2023-04-07", "2023-05-08", "2023-05-29",
91-
"2023-06-19", "2023-07-04", "2023-09-04", "2023-10-09", "2023-11-10", "2023-11-23", "2023-12-25"};
98+
String[] correctValuesUS = {"2023-01-02", "2023-01-16", "2023-02-20", "2023-05-29", "2023-06-19", "2023-07-04", "2023-09-04", "2023-11-10", "2023-11-23", "2023-12-25"};
9299

93100
// Loop through the results and verify the keys (dates)
94101
int i = 0;
@@ -102,37 +109,45 @@ void holidayListTestUS() {
102109
// Test US month holidays for April 2025
103110
@Test
104111
void monthHolidayListTestUS() {
112+
Output.println("Current locale set to: " + Locale.getDefault().getDisplayCountry());
113+
105114
// ------------------------------------------------------------------------
106-
// For now, skip this test if the JVM does not report it's in the US
115+
// For this test, skip this test if the JVM does not report it's in the US
107116
// ------------------------------------------------------------------------
108117
if (Locale.getDefault().getDisplayCountry().toString().compareTo("United States") != 0) {
109118
Output.println("Current locale set to: '" + Locale.getDefault().getDisplayCountry() + "' -- Skipping Test");
110119
return;
111120
}
112121

113-
StringBuilder sb = Holidays.queryHolidayListMonth(4, 2025);
114-
assertEquals("2025-04-18 | Good Friday", sb.toString().trim());
122+
StringBuilder sb = Holidays.queryHolidayListMonth(12, 2025);
123+
assertEquals("2025-12-25 | Christmas Day", sb.toString().trim());
124+
125+
sb = Holidays.queryHolidayListMonth(7, 2025);
126+
assertEquals("2025-07-04 | Independence Day", sb.toString().trim());
115127

116128
}
117129

118-
// // Test holiday list - CA
130+
// Test holiday list - CA
119131
// @Test
120132
// void holidayListTestCA() {
133+
// Output.println("\nExecuting holidayListTestCA()");
121134
// // ------------------------------------------------------------------------
122135
// // Set the default country to Canada
123136
// // ------------------------------------------------------------------------
124137
// Locale.setDefault(Locale.CANADA);
125138
// Output.println("Current locale set to: " + Locale.getDefault().getDisplayCountry());
126139
//
140+
// // Clear the cache before the test
141+
// CommandLineArgs.clearCache();
142+
//
127143
// // Get the holiday list for the 2023 Canadian holidays
128144
// TreeMap<String, String> holidayListCA = Holidays.getHolidays(2024);
129145
//
130-
// // There should be 19 holidays in 2023
131-
// assertEquals(19, holidayListCA.size());
146+
// // There should be 8 holidays in 2024
147+
// Assertions.assertNotNull(holidayListCA);
148+
// assertEquals(8, holidayListCA.size());
132149
//
133-
// String[] correctValuesCA = { "2024-01-01", "2024-02-19", "2024-03-17", "2024-03-29", "2024-04-01", "2024-04-23", "2024-05-20", "2024-06-21",
134-
// "2024-06-24", "2024-07-01", "2024-07-12", "2024-08-05", "2024-08-19", "2024-09-02", "2024-09-30", "2024-10-14", "2024-11-11", "2024-12-25",
135-
// "2024-12-26" };
150+
// String[] correctValuesCA = { "2024-01-01", "2024-03-29", "2024-05-20", "2024-07-01", "2024-09-02", "2024-09-30", "2024-10-14", "2024-12-25" };
136151
//
137152
// // Loop through the results and verify the keys (dates)
138153
// int i = 0;

0 commit comments

Comments
 (0)