Skip to content
This repository was archived by the owner on Dec 1, 2020. It is now read-only.

Commit db71e15

Browse files
committed
verification test1
1 parent ed61356 commit db71e15

File tree

4 files changed

+173
-34
lines changed

4 files changed

+173
-34
lines changed

Milestone_1_Fabian/bin/.project

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<projectDescription>
3+
<name>Milestone_1_Fabian</name>
4+
<comment></comment>
5+
<projects>
6+
</projects>
7+
<buildSpec>
8+
<buildCommand>
9+
<name>org.eclipse.jdt.core.javabuilder</name>
10+
<arguments>
11+
</arguments>
12+
</buildCommand>
13+
</buildSpec>
14+
<natures>
15+
<nature>org.eclipse.jdt.core.javanature</nature>
16+
</natures>
17+
</projectDescription>

ProjectManager/src/Back/Main.java

Lines changed: 35 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@
66
import java.util.ArrayList;
77
import java.time.LocalDate;
88
import java.time.format.DateTimeFormatter;
9+
import java.text.ParseException;
10+
import java.text.SimpleDateFormat;
11+
import java.util.Calendar;
12+
import java.util.Locale;
913

1014

1115
public class Main {
@@ -56,30 +60,20 @@ public static Project createProject(Scanner sc, ArrayList<Project> oArrayList, H
5660
String pname = getPNameString(oArrayList, sc, hSet);
5761
Date pEndDate = new Date();
5862
Date pStartDate = new Date();
59-
//please refactor later this is not optimal, there should be a recoursive solution
60-
//try {
61-
String start = "start";
62-
String end = "end";
63-
pStartDate = scanDate(sc, start);
64-
pEndDate = scanDate(sc, end);
65-
while( ! pStartDate.isEarlierDate(pEndDate)){
66-
System.out.println("---------------------------------------------------------------");
67-
System.out.println("there might have been an error let's check that again");
68-
System.out.println("---------------------------------------------------------------");
69-
pStartDate = scanDate(sc, start);
70-
pEndDate = scanDate(sc, end);
71-
}
72-
/*} catch (ArrayIndexOutOfBoundsException | InputMismatchException | NumberFormatException e) {
73-
System.out.println("----------------------");
74-
System.err.println("|inproper date format|");
75-
System.out.println("----------------------");
76-
System.out.println("| restarting creator |");
77-
System.out.println("----------------------");
78-
return createProject(sc, oArrayList, hSet);
79-
}*/
63+
String start = "start";
64+
String end = "end";
65+
pStartDate = scanDate(sc, start);
66+
pEndDate = scanDate(sc, end);
67+
while( ! pStartDate.isEarlierDate( pEndDate ) ){
68+
System.out.println("---------------------------------------------------------------");
69+
System.out.println("there might have been an error let's check that again");
70+
System.out.println("---------------------------------------------------------------");
71+
pStartDate = scanDate( sc, start );
72+
pEndDate = scanDate( sc, end );
73+
}
8074
int pid = 0;
8175
if (oArrayList.size() == 0 ) pid = 0;
82-
else pid = oArrayList.get(oArrayList.size()-1).getId() + 1;
76+
else pid = oArrayList.get( oArrayList.size() - 1 ).getId() + 1;
8377
Project createProject = new Project(pid, pname, pStartDate, pEndDate);
8478
System.out.println("---------------------------------------------------------------");
8579
System.out.println("you created project is");
@@ -91,24 +85,35 @@ public static Project createProject(Scanner sc, ArrayList<Project> oArrayList, H
9185

9286
public static Date scanDate( Scanner sc, String dateType ) throws ArrayIndexOutOfBoundsException {
9387
System.out.println("so whats the " + dateType + " date");
94-
System.out.println("please enter date like (YYYY/MM/DD)");
88+
System.out.println("please enter date like dd-MM-yyyy");
9589
Date scDate = new Date();
9690
try {
91+
String todayString = sc.nextLine();
92+
String[] todayStringArr = todayString.split("-");
9793

98-
String[] inDate = sc.nextLine().split("/");
94+
Calendar cals = parseTimestamp(todayString);
9995

100-
scDate = new Date(Integer.parseInt(inDate[0]), Integer.parseInt(inDate[1]), Integer.parseInt(inDate[2]) );
101-
102-
// litte date validation, not in depth but the biggest mistakes will be stoped
103-
if( Integer.parseInt(inDate[1]) > 12 || Integer.parseInt(inDate[2]) > 31 || Integer.parseInt(inDate[1]) > 0 || Integer.parseInt(inDate[2]) > 0 ) return scanDate(sc, dateType);
96+
scDate = new Date(Integer.parseInt(todayStringArr[2]), Integer.parseInt(todayStringArr[1]),Integer.parseInt(todayStringArr[0])) ;
97+
//pDate.printDate();
10498

105-
} catch( ArrayIndexOutOfBoundsException | InputMismatchException | NumberFormatException e) {
99+
} catch( ArrayIndexOutOfBoundsException | InputMismatchException | NumberFormatException | ParseException e) {
100+
106101
return scanDate(sc, dateType);
102+
107103
}
108104

109105
return scDate;
110106
}
111-
107+
108+
public synchronized static Calendar parseTimestamp(String timestamp) throws ParseException {
109+
SimpleDateFormat sdf = new SimpleDateFormat("dd-MM-yyyy", Locale.GERMAN);
110+
sdf.setLenient(false);
111+
java.util.Date d = sdf.parse(timestamp);
112+
Calendar cal = Calendar.getInstance();
113+
cal.setTime(d);
114+
return cal;
115+
}
116+
112117
public static String getPNameString(ArrayList<Project> oArrayList, Scanner sc, HashSet<String> hSet){
113118
System.out.println("please enter a project name");
114119
String pname = sc.nextLine();

oldstuff/kb/helpful/Date.java

Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
package helpful;
2+
3+
public class Date {
4+
private int day;
5+
private int month;
6+
private int year;
7+
8+
public Date(int year, int month, int day){
9+
this.day = day;
10+
this.month = month;
11+
this.year = year;
12+
}
13+
14+
public Date(){
15+
this.day = 1;
16+
this.month = 1;
17+
this.year = 1970;
18+
}
19+
20+
public void printDate(){
21+
System.out.println(year + "/" + month + "/" + day );
22+
}
23+
24+
public String getDate(){
25+
return(year + "/" + month + "/" + day);
26+
}
27+
28+
public boolean compareDate(Date d){ // if : else also no variable because ma memory
29+
if( ! ( this.day == d.day ) ) return false;
30+
if( ! ( this.month == d.month ) ) return false;
31+
if( ! ( this.year == d.year ) ) return false;
32+
return true;
33+
}
34+
35+
public boolean isEarlierDate(Date d){
36+
if( this.year < d.year ) return true;
37+
else if ( this.year == d.year ){
38+
if ( this.month < d.month ) return true;
39+
else if ( this.month == d.month ){
40+
if(this.day < d.day) return true;
41+
else return false;
42+
} else return false;
43+
} else return false;
44+
45+
//if (this. year <= d.year && this.month <= d.month && this.day < d.day ) return false;
46+
//else return true;
47+
}
48+
49+
public boolean isEqualEarlierDate(Date d){
50+
if( this.year < d.year ) return true;
51+
else if ( this.year == d.year ){
52+
if ( this.month < d.month ) return true;
53+
else if ( this.month == d.month ){
54+
if(this.day < d.day) return true;
55+
else if (this.day == d.day ) return true;
56+
else return false;
57+
} else return false;
58+
} else return false;
59+
}
60+
61+
/**
62+
* @return int return the day
63+
*/
64+
public int getDay() {
65+
return day;
66+
}
67+
68+
/**
69+
* @param day the day to set
70+
*/
71+
public void setDay(int day) {
72+
this.day = day;
73+
}
74+
75+
/**
76+
* @return int return the month
77+
*/
78+
public int getMonth() {
79+
return month;
80+
}
81+
82+
/**
83+
* @param month the month to set
84+
*/
85+
public void setMonth(int month) {
86+
this.month = month;
87+
}
88+
89+
/**
90+
* @return int return the year
91+
*/
92+
public int getYear() {
93+
return year;
94+
}
95+
96+
/**
97+
* @param year the year to set
98+
*/
99+
public void setYear(int year) {
100+
this.year = year;
101+
}
102+
103+
public static void main(String[] args) {
104+
System.out.println("this is not the class you are looking for, move along");
105+
}
106+
107+
}
108+
109+
110+

oldstuff/kb/yeet.java

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
import java.time.LocalDate;
55
import java.time.format.DateTimeFormatter;
66
import java.util.Calendar;
7-
import java.util.Date;
87
import java.util.Locale;
98
import helpful.*;
109

@@ -23,10 +22,18 @@ public synchronized static void main(String[] args) throws ParseException {
2322
DateTimeFormatter dtf = DateTimeFormatter.ofPattern("dd-MM-yyyy");
2423
LocalDate localDate = LocalDate.now();
2524
String todayString = dtf.format(localDate);
26-
25+
String todayStringArr[] = dtf.format(localDate).split("-");
26+
Calendar cals = parseTimestamp("01-01-1970");
2727
//compatibilty layer
28-
Calendar cals = parseTimestamp(todayString);
28+
try {
29+
cals = parseTimestamp(todayString);
30+
} catch (Exception e) {
31+
System.err.println("y u du dis");
32+
return;
33+
}
2934

35+
Date pDate = new Date(Integer.parseInt(todayStringArr[2]), Integer.parseInt(todayStringArr[1]),Integer.parseInt(todayStringArr[0])) ;
36+
pDate.printDate();
3037
SimpleDateFormat sdf = new SimpleDateFormat("dd-MM-yyyy", Locale.GERMAN);
3138
System.out.println("Calendar : " + sdf.format(cals.getTime()));
3239

@@ -35,7 +42,7 @@ public synchronized static void main(String[] args) throws ParseException {
3542
public synchronized static Calendar parseTimestamp(String timestamp) throws ParseException {
3643
SimpleDateFormat sdf = new SimpleDateFormat("dd-MM-yyyy", Locale.GERMAN);
3744
sdf.setLenient(false);
38-
Date d = sdf.parse(timestamp);
45+
java.util.Date d = sdf.parse(timestamp);
3946
Calendar cal = Calendar.getInstance();
4047
cal.setTime(d);
4148
return cal;

0 commit comments

Comments
 (0)