GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — first commit · robz/TimeDiff@883d5ec

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • README
  • TimeDiff.class
  • TimeDiff.java
  • teamtimes
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎README‎

Copy file name to clipboard
+26Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
This is a project that can diff several different week-long schedules to find the intersection. It outputs the results in a 7 by 24 (7 days by 24 hours) matrix.
2+
3+
For example, the file 'teamtimes' in this directory contains 5 week-long schedules. One of those schedules looks like this:
4+
5+
Mon. 6:00 - 9:00 PM, Tues. 6:00 - 9:00 PM, Wed. 6:00 - 9:00 PM, Thurs. 6:00 - 9:00 PM, Fri. 3:00 - 6:00 PM, Fri. 6:00 - 9:00 PM, Sat. 12 Noon - 3:00 PM, Sat. 3:00 - 6:00 PM, Sun. 3:00 - 6:00 PM
6+
7+
Several of these schedules can be listed out, each separated by a newline character, and provided as input to the program. The program is written in java. This is what the command line should look like if the 'teamtimes' file is used:
8+
9+
$ javac TimeDiff.java
10+
$ java TimeDiff teamtimes
11+
Intersection of hours available:
12+
(first column is 1 AM, last is midnight)
13+
123456789012345678901234
14+
Mon: 000000000000000000000000
15+
Tues: 000000000000000000000000
16+
Wed: 000000000000000000000000
17+
Thurs: 000000000000000000000000
18+
Fri: 000000000000000000000000
19+
Sat: 000000000000000001000000
20+
Sun: 000000000000001111000000
21+
22+
The matrix is made up of zeros and ones where one means the corresponding hour block is listed in each schedules, and zero means their is some schedule that does not list that hour.
23+
24+
The input file must exactly adhere to the syntax in the 'teamtimes' example file. Any number of schedules may be listed.
25+
26+
Have fun!
Collapse file

‎TimeDiff.class‎

Copy file name to clipboard
2.81 KB
Binary file not shown.
Collapse file

‎TimeDiff.java‎

Copy file name to clipboard
+111Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
import java.io.File;
2+
import java.io.FileNotFoundException;
3+
import java.util.ArrayList;
4+
import java.util.Scanner;
5+
6+
7+
public class TimeDiff {
8+
static String dayslist[] = new String[]{"Mon","Tues","Wed","Thurs","Fri","Sat","Sun"};
9+
10+
public static void main(String[] args) throws FileNotFoundException {
11+
parseData(args[0]);
12+
}
13+
14+
public static void parseData(String filename) throws FileNotFoundException {
15+
Scanner sc = new Scanner(new File(filename));
16+
ArrayList<String> data = new ArrayList<String>();
17+
while(sc.hasNext())
18+
data.add(sc.nextLine());
19+
sc.close();
20+
21+
boolean diffArr[][][] = new boolean[4][7][24];
22+
int i = 0;
23+
for(String times:data) {
24+
//System.out.println(times);
25+
String[] days = times.split(", ");
26+
//System.out.println(i);
27+
for(String day_str:days) {
28+
String[] day_info = day_str.split("[.] ");
29+
int day = getDayIndex(day_info[0]);
30+
//System.out.println(day_info[0]+"--"+day);
31+
String range[] = day_info[1].split(" - ");
32+
int hour1 = getHourIndexes(day_info[1])[0], hour2 = getHourIndexes(day_info[1])[1];
33+
//System.out.println(range[0]+"-"+range[1]+" == "+hour1+"-"+hour2);
34+
for(int j = hour1; j <= hour2; j++)
35+
diffArr[i][day][j-1] = true;
36+
}
37+
//System.out.println("\n");
38+
i++;
39+
}
40+
41+
boolean andedArr[][] = new boolean[7][24];
42+
for(int r = 0; r < andedArr.length; r++)
43+
for(int c = 0; c < andedArr[r].length; c++)
44+
andedArr[r][c] = true;
45+
46+
for(i = 0; i < diffArr.length; i++) {
47+
//printTimes(diffArr[i]);
48+
//System.out.println("\n");
49+
for(int r = 0; r < diffArr[i].length; r++)
50+
for(int c = 0; c < diffArr[i][r].length; c++)
51+
andedArr[r][c] &= diffArr[i][r][c];
52+
}
53+
54+
System.out.println("Intersection of hours available:\n(first column is 1 AM, last is midnight)");
55+
printTimes(andedArr);
56+
}
57+
58+
public static void printTimes(boolean[][] matrix) {
59+
System.out.print("\t");
60+
for(int i = 0; i < matrix[0].length; i++)
61+
System.out.print((i+1)%10);
62+
System.out.println();
63+
for(int r = 0; r < matrix.length; r++) {
64+
System.out.print(dayslist[r]+":\t");
65+
for(int c = 0; c < matrix[0].length; c++) {
66+
int num = (matrix[r][c]) ? 1 : 0;
67+
System.out.print(num);
68+
}
69+
System.out.println();
70+
}
71+
}
72+
73+
public static int[] getHourIndexes(String range) {
74+
String[] tokens = range.split(" ");
75+
String hours[] = range.split(" - ");
76+
int index1 = getHourIndex(hours[0]),
77+
index2 = getHourIndex(hours[1]);
78+
if (tokens.length < 5) {
79+
String suffix = tokens[3];
80+
if (suffix.equals("PM"))
81+
index1+=12;
82+
else if (suffix.equals("AM") && index1 == 12)
83+
index1 = 24;
84+
}
85+
return new int[]{index1, index2};
86+
}
87+
88+
public static int getHourIndex(String hour) {
89+
String tokens[] = hour.split(" ");
90+
int num = 0;
91+
if (hour.split(":").length == 1)
92+
num = Integer.parseInt(tokens[0]);
93+
else
94+
num = Integer.parseInt(hour.split(":")[0]);
95+
if (tokens.length > 1) {
96+
String suffix = tokens[1];
97+
if (suffix.equals("PM"))
98+
num+=12;
99+
else if (suffix.equals("AM") && num == 12)
100+
num = 24;
101+
}
102+
return num;
103+
}
104+
105+
public static int getDayIndex(String day) {
106+
for(int i = 0; i < dayslist.length; i++)
107+
if (day.equals(dayslist[i]))
108+
return i;
109+
return -1;
110+
}
111+
}
Collapse file

‎teamtimes‎

Copy file name to clipboard
+4Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
Mon. 6:00 - 9:00 PM, Tues. 6:00 - 9:00 PM, Wed. 6:00 - 9:00 PM, Thurs. 6:00 - 9:00 PM, Fri. 3:00 - 6:00 PM, Fri. 6:00 - 9:00 PM, Sat. 12 Noon - 3:00 PM, Sat. 3:00 - 6:00 PM, Sun. 3:00 - 6:00 PM
2+
Fri. 9:00 PM - 12:00 AM, Sat. 9 AM - 12 Noon, Sat. 12 Noon - 3:00 PM, Sat. 3:00 - 6:00 PM, Sat. 6:00 - 9:00 PM, Sat. 9:00 PM - 12:00 AM, Sun. 9 AM - 12 Noon, Sun. 12 Noon - 3:00 PM, Sun. 3:00 - 6:00 PM, Sun. 6:00 - 9:00 PM, Sun. 9:00 PM - 12:00 AM
3+
Mon. 6:00 - 9:00 PM, Mon. 9:00 PM - 12:00 AM, Tues. 3:00 - 6:00 PM, Tues. 9:00 PM - 12:00 AM, Wed. 3:00 - 6:00 PM, Wed. 6:00 - 9:00 PM, Wed. 9:00 PM - 12:00 AM, Thurs. 3:00 - 6:00 PM, Thurs. 9:00 PM - 12:00 AM, Fri. 9 AM - 12 Noon, Fri. 3:00 - 6:00 PM, Fri. 6:00 - 9:00 PM, Fri. 9:00 PM - 12:00 AM, Sat. 6:00 - 9:00 PM, Sat. 9:00 PM - 12:00 AM, Sun. 3:00 - 6:00 PM, Sun. 6:00 - 9:00 PM, Sun. 9:00 PM - 12:00 AM
4+
Mon. 12 Noon - 3:00 PM, Tues. 12 Noon - 3:00 PM, Wed. 12 Noon - 3:00 PM, Sat. 3:00 - 6:00 PM, Sat. 6:00 - 9:00 PM, Sat. 9:00 PM - 12:00 AM, Sun. 3:00 - 6:00 PM, Sun. 6:00 - 9:00 PM

0 commit comments

Comments
0 (0)
You are visitor 01402520 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.