Skip to content

Commit

Permalink
Checked for month/year = 0 & added debug code
Browse files Browse the repository at this point in the history
  • Loading branch information
frossm committed Apr 28, 2022
1 parent 76a1165 commit 6b99894
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 28 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

<groupId>org.fross</groupId>
<artifactId>cal</artifactId>
<version>2.3.12</version>
<version>2.3.13</version>
<packaging>jar</packaging>

<name>cal</name>
Expand Down
2 changes: 1 addition & 1 deletion snap/snapcraft.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: fcal
version: '2.3.12'
version: '2.3.13'
summary: Command line calendar display
description: |
fCal is a command line calendar display utility. It will display a
Expand Down
10 changes: 8 additions & 2 deletions src/main/java/org/fross/cal/Calendar.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ public class Calendar {
// Class Constants
static final int DEFAULT_CALS_PER_ROW = 3;
static final int CALENDARWIDTH = 20;
static final int SPACESBETWEENCALS = 3;
static final String[] MONTHLIST = { "none", "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November",
static final int SPACESBETWEENCALS = 2;
static final String[] MONTHLIST = { "", "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November",
"December" };

// Class Variables
Expand Down Expand Up @@ -100,6 +100,9 @@ public static boolean isLeapYear(int year) {
public static void printMonth(int month, int year) {
String[] days = getCalDays(month, year);

Output.debugPrint(" 1 2 3 4 5 6 7 8\n"
+ "12345678901234567890123456789012345678901234567890123456789012345678901234567890");

Output.printColorln(Ansi.Color.CYAN, getCalHeader(month, year));
Output.printColorln(Ansi.Color.YELLOW, "Su Mo Tu We Th Fr Sa");

Expand All @@ -119,6 +122,9 @@ public static void printYear(int month, int year) {
String[] dayrows = new String[6];
int i, j, k;

Output.debugPrint(" 1 2 3 4 5 6 7 8\n"
+ "12345678901234567890123456789012345678901234567890123456789012345678901234567890");

// Loop through the calendar rows
for (i = 0; i < 12; i = i + calsPerRow) {
// Initialize the arrays
Expand Down
33 changes: 9 additions & 24 deletions src/main/java/org/fross/cal/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,6 @@ public static void main(String[] args) {
default:
Output.fatalError("ERROR: Unknown Command Line Option -" + optG.getOptarg() + "'", 0);
Help.display();

break;
}
}
Expand All @@ -131,31 +130,19 @@ public static void main(String[] args) {
Output.debugPrint("Number of command line arguments: " + args.length);
int clParameters = args.length - optG.getOptind();
Output.debugPrint("Number of command line parameters: " + clParameters);
Output.debugPrint("Current Date: Month: " + month + " Year: " + year);

// DISABLE THIE HEADER AS IT SEEMS OBTRUSIVE
// // Display header information
// int headerWidth = (Calendar.CALENDARWIDTH * Calendar.calsPerRow) + (Calendar.calsPerRow * Calendar.SPACESBETWEENCALS) - 2;
// String headerText = "Cal v" + VERSION + " by Michael Fross";
// int headerSpaces = headerWidth / 2 - headerText.length() / 2;
//
// // Ensure we have enough room if user selects -n1
// if (headerSpaces < 0) {
// headerSpaces = 0;
// headerWidth = headerText.length();
// }
//
// Output.debugPrint("headerWidth = " + headerWidth);
// Output.debugPrint("headerText = " + "'" + headerText + "' (Len = " + headerText.length() + ")");
// Output.debugPrint("headerSpaces = " + headerSpaces);
//
// Output.printColorln(Ansi.Color.CYAN, "\n+" + "-".repeat(headerWidth) + "+");
// Output.printColorln(Ansi.Color.YELLOW, " ".repeat(headerSpaces) + headerText);
// Output.printColorln(Ansi.Color.CYAN, "+" + "-".repeat(headerWidth) + "+");
Output.debugPrint("Current Date: Month: " + month + " Year: " + year);

// Ensure the month and year are greater than zero
for (int i=0; i < clParameters; i++) {
if (args[i].compareTo("0") == 0) {
Output.fatalError("Month & Year must be greater than zero", 6);
}
}

// Process options and display the calendar
try {
Output.println("");

switch (clParameters) {
case 0:
// Process no dates provided
Expand All @@ -171,8 +158,6 @@ public static void main(String[] args) {
if (d > 12) {
year = d;
Output.debugPrint("Commandline Year provided. Using Month: " + month + " Year: " + year);
Output.debugPrint(" 1 2 3 4 5 6 7");
Output.debugPrint("90123456789012345678901234567890123456789012345678901234567890");
Calendar.printYear(month, year);

// Assume the number provided is a month
Expand Down

0 comments on commit 6b99894

Please sign in to comment.