Skip to content
Snippets Groups Projects
Commit d3e7e97b authored by marc.vachon's avatar marc.vachon
Browse files

Change date format

parent 40c4dc98
Branches
No related tags found
No related merge requests found
...@@ -17,10 +17,7 @@ public class Appointment { ...@@ -17,10 +17,7 @@ public class Appointment {
System.out.println("--------------------------------------------------"); System.out.println("--------------------------------------------------");
System.out.println("Calcul de la date et heure idéal..."); System.out.println("Calcul de la date et heure idéal...");
this.most_popular_date(); this.most_popular_date();
System.out.println("Rendez-vous fixé le: " + System.out.println("Rendez-vous fixé le: " + this.f_date.get_date().toString());
this.f_date.get_day() + "/" +
this.f_date.get_month() + "/" +
this.f_date.get_year());
System.out.println("Fini"); System.out.println("Fini");
} }
...@@ -37,7 +34,7 @@ public class Appointment { ...@@ -37,7 +34,7 @@ public class Appointment {
for(MyDate date1: this.t_date){ for(MyDate date1: this.t_date){
for(MyDate date2: this.t_date){ for(MyDate date2: this.t_date){
if(compare_date(date1, date2)) if(date1.get_date().equals(date2.get_date()))
c++; c++;
} }
// if date's most popular // if date's most popular
...@@ -54,21 +51,4 @@ public class Appointment { ...@@ -54,21 +51,4 @@ public class Appointment {
for(MyDate d: this.t_date){ for(MyDate d: this.t_date){
} }
} }
/**
* Compare 2 dates
* @param d1 Date format, first date
* @param d2 Date format, second date
* @return true if dates are the same
*/
private Boolean compare_date(MyDate d1, MyDate d2){
if(d1.get_day() == d2.get_day()){
if(d1.get_month() == d2.get_month()){
if(d1.get_year() == d2.get_year()){
return true;
}
}
}
return false;
}
} }
...@@ -7,13 +7,16 @@ import java.text.SimpleDateFormat; ...@@ -7,13 +7,16 @@ import java.text.SimpleDateFormat;
public class Meeting{ public class Meeting{
private static ArrayList<User> table_User; private static ArrayList<User> table_User;
private static SimpleDateFormat parseDate = new SimpleDateFormat("dd/MM/yyyy");
public static void main(String[] args) { public static void main(String[] args) throws Exception {
table_User = new ArrayList<User>(); table_User = new ArrayList<User>();
String date = "14/03/2019"; String date = "14/03/2019";
System.out.println(date_validity(date)); System.out.println(date_validity(parseDate.parse(date)));
Date d1 = new Date(2019, 3, 21);
System.out.println(parseDate.format(d1));
set_t_user(); set_t_user();
...@@ -56,7 +59,7 @@ public class Meeting{ ...@@ -56,7 +59,7 @@ public class Meeting{
System.out.println("Utilisateur :"); System.out.println("Utilisateur :");
System.out.println("Coordonées x, y: " + user.get_location().get_x() + ", " + user.get_location().get_y()); System.out.println("Coordonées x, y: " + user.get_location().get_x() + ", " + user.get_location().get_y());
System.out.println("Date possible :"); System.out.println("Date possible :");
user.get_calendar().forEach((d) -> System.out.println(d.get_day() + "/" + d.get_month() + "/" + d.get_year())); user.get_calendar().forEach((d) -> System.out.println(parseDate.format(d.get_date())));
System.out.println(); System.out.println();
} }
...@@ -67,7 +70,7 @@ public class Meeting{ ...@@ -67,7 +70,7 @@ public class Meeting{
private static void print_calendar(ArrayList<MyDate> cal){ private static void print_calendar(ArrayList<MyDate> cal){
System.out.println("--------------------------------------------------"); System.out.println("--------------------------------------------------");
System.out.println("General calendar"); System.out.println("General calendar");
cal.forEach((d) -> System.out.println(d.get_day() + "/" + d.get_month() + "/" + d.get_year())); cal.forEach((d) -> System.out.println(parseDate.format(d.get_date())));
System.out.println("Fini"); System.out.println("Fini");
} }
...@@ -76,7 +79,7 @@ public class Meeting{ ...@@ -76,7 +79,7 @@ public class Meeting{
* their location, * their location,
* their calendar * their calendar
*/ */
private static void set_t_user(){ private static void set_t_user() throws Exception{
System.out.println("Bonjour, veuillez entrer les informations utilisateur:"); System.out.println("Bonjour, veuillez entrer les informations utilisateur:");
boolean end = false; boolean end = false;
...@@ -106,26 +109,26 @@ public class Meeting{ ...@@ -106,26 +109,26 @@ public class Meeting{
* Set table of date's user * Set table of date's user
* @return ArrayList of date * @return ArrayList of date
*/ */
private static ArrayList<MyDate> set_date(){ private static ArrayList<MyDate> set_date() throws Exception{
ArrayList<MyDate> t_date = new ArrayList<MyDate>(); ArrayList<MyDate> t_date = new ArrayList<MyDate>();
boolean end = false; boolean end = false;
Scanner sc = new Scanner(System.in); Scanner sc = new Scanner(System.in);
while(!end){ while(!end){
System.out.println("Date possible (jour/mois heure:min heure:min):"); System.out.println("Date possible (jour/mois/année heure:min heure:min):");
String[] line = sc.nextLine().split(" "); String[] line = sc.nextLine().split(" ");
if(line.length == 3){ if(line.length == 3){
String[] date = line[0].split("/"); //String[] date = line[0].split("/");
String[] from = line[1].split(":"); String[] from = line[1].split(":");
String[] to = line[2].split(":"); String[] to = line[2].split(":");
System.out.println("Vous avez saisi : " + System.out.println("Vous avez saisi : " + line[0] + " de " +
date[0] + "/" + date[1] + "/2019 de " +
from[0] + ":" + from[1] + " à " + from[0] + ":" + from[1] + " à " +
to[0] + ":" + to[1]); to[0] + ":" + to[1]);
MyDate d = new MyDate(new int[]{Integer.parseInt(date[0]), Integer.parseInt(date[1]), 2019}, MyDate d = new MyDate(parseDate.parse(line[0]),
new int[]{Integer.parseInt(from[0]), Integer.parseInt(from[1])}, new int[]{Integer.parseInt(from[0]), Integer.parseInt(from[1])},
new int[]{Integer.parseInt(to[0]), Integer.parseInt(to[1])}); new int[]{Integer.parseInt(to[0]), Integer.parseInt(to[1])});
...@@ -168,14 +171,14 @@ public class Meeting{ ...@@ -168,14 +171,14 @@ public class Meeting{
return calendar; return calendar;
} }
private static Boolean date_validity(String d1){ private static Boolean date_validity(Date d1){
Boolean error = false; Boolean error = false;
Date d2 = new Date(); // this object contains the current date value Date d2 = new Date(); // this object contains the current date value
SimpleDateFormat formatter = new SimpleDateFormat("dd/MM/yyyy");
Date date = new SimpleDateFormat("dd/MM/yyyy").parse(d1);
return new Date().before(date); //Date date = new SimpleDateFormat("dd/MM/yyyy").parse(d1);
return d2.before(d1);
} }
/* /*
......
import java.util.Date;
public class MyDate{ public class MyDate{
private int day; private Date date;
private int month;
private int year;
private Time from; private Time from;
private Time to; private Time to;
public MyDate(int[] date, int[] from, int[] to){ public MyDate(Date date, int[] from, int[] to){
this.day = date[0]; this.date = date;
this.month = date[1];
this.year = date[2];
this.from = new Time(from[0], from[1]); this.from = new Time(from[0], from[1]);
this.to = new Time(to[0], to[1]); this.to = new Time(to[0], to[1]);
} }
public int get_day(){ public Date get_date(){
return this.day; return this.date;
}
public int get_month(){
return this.month;
}
public int get_year(){
return this.year;
} }
public int[] get_t_from(){ public int[] get_t_from(){
......
import java.util.*; import java.util.*;
import java.net.*; import java.net.*;
import java.io.*; import java.io.*;
import java.util.Date;
public class User { public class User {
...@@ -51,7 +52,7 @@ public class User { ...@@ -51,7 +52,7 @@ public class User {
* @param from int[] * @param from int[]
* @param to int[] * @param to int[]
*/ */
public void add_Date(int[] date, int[] from, int[] to){ public void add_Date(Date date, int[] from, int[] to){
MyDate d = new MyDate(date, from, to); MyDate d = new MyDate(date, from, to);
this.calendar.add(d); this.calendar.add(d);
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment