Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

06 date and time #5

Open
wants to merge 2 commits into
base: 06-date-and-time
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/test/java/java8/ex01/DateAndTime_01_Test.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public class DateAndTime_01_Test {
public void test_date() {

// TODO modifier les paramètres du constructeur pour que le test soit passant
Date date = new Date(0, 0, 0, 0, 0, 0);
Date date = new Date(5, 02, 24, 01, 02, 03);

assertThat(date.toString(), is("Fri Mar 24 01:02:03 CET 2017"));

Expand All @@ -35,6 +35,7 @@ public void test_calendar() throws Exception {
Calendar calendar = Calendar.getInstance();

// TODO modifier l'objet calendar pour que le test soit passant
calendar.getTimeZone();

assertThat(calendar.getTime().toString(), is("Fri Mar 24 01:02:03 CET 2017"));

Expand Down
33 changes: 19 additions & 14 deletions src/test/java/java8/ex02/DateAndTime_02_Test.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,16 @@
import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertThat;

import java.sql.Date;
import java.text.Format;
import java.time.DayOfWeek;
import java.time.LocalDate;
import java.time.Month;
import java.time.format.DateTimeFormatter;
import java.time.temporal.UnsupportedTemporalTypeException;

import javax.naming.spi.DirStateFactory.Result;

import org.junit.Test;

/**
Expand All @@ -19,15 +24,15 @@ public class DateAndTime_02_Test {
public void test_localDate_of() {

// TODO créer un objet LocalDate à la date 24/12/2050
LocalDate result = null;
LocalDate result = LocalDate.of(2050, 12, 24);

// TODO En exploitant les méthodes de l'objet result, valoriser les
// différentes variables afin de rendre le test passant.
int year = 0;
Month month = null;
int dayOfMonth = 0;
DayOfWeek dayOfWeek = null;
int dayOfYear = 0;
int year = result.getYear();
Month month = result.getMonth();
int dayOfMonth = result.getDayOfMonth();
DayOfWeek dayOfWeek = result.getDayOfWeek();
int dayOfYear = result.getDayOfYear();

assertThat(year, is(2050));
assertThat(month, is(Month.DECEMBER));
Expand All @@ -41,13 +46,13 @@ public void test_localDate_parse() {

// TODO créer un objet LocalDate à la date 10/01/1990
// TODO utiliser la méthode parse
LocalDate result = null;
LocalDate result = LocalDate.parse("10-01-1990", DateTimeFormatter.ofPattern("dd-MM-yyyy"));

// TODO En exploitant les méthodes de l'objet result, valoriser les
// différentes variables afin de rendre le test passant.
int year = 0;
Month month = null;
int dayOfMonth = 0;
int year = result.getYear();
Month month = result.getMonth();
int dayOfMonth = result.getDayOfMonth();

assertThat(year, is(1990));
assertThat(month, is(Month.JANUARY));
Expand All @@ -59,10 +64,10 @@ public void test_localDate_format() {

// TODO créer un objet LocalDate à la date 11/03/2015
// en utilisant la méthode of
LocalDate localDate = null;
LocalDate localDate = LocalDate.of(11,03,2015);

// TODO Formatter la date pour que le test soit passant
String result = null;
String result = localDate.format(DateTimeFormatter.ISO_LOCAL_DATE) ;

assertThat(result, is("11 - 03 - 2015"));
}
Expand All @@ -72,10 +77,10 @@ public void test_localDate_format_with_hour() {

// TODO créer un objet LocalDate à la date 11/03/2015
// TODO utiliser la méthode of
LocalDate localDate = null;
LocalDate localDate = LocalDate.of(11,03,2015);

// TODO Formatter la date pour avoir l'affichage suivant : "11/03/2015 00:00:00"
localDate.format(null);
localDate.format(DateTimeFormatter.ofPattern("dd/MM/yyyy HH:mm:ss"));
}

@Test
Expand Down
22 changes: 12 additions & 10 deletions src/test/java/java8/ex03/DateAndTime_03_Test.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
import java.time.LocalTime;
import java.time.format.DateTimeFormatter;

import javax.naming.spi.DirStateFactory.Result;

import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertThat;

Expand All @@ -17,12 +19,12 @@ public class DateAndTime_03_Test {
public void test_localTime_of() {

// TODO créer un objet LocalTime à l'heure 15h24m02s
LocalTime result = null;
LocalTime result = LocalTime.of(15,24,2);

// TODO valoriser les différentes variables afin de rendre le test passant
int hour = 0;
int minutes = 0;
int second = 0;
int hour = result.getHour();
int minutes = result.getMinute();
int second = result.getSecond();

assertThat(hour, is(15));
assertThat(minutes, is(24));
Expand All @@ -33,13 +35,13 @@ public void test_localTime_of() {
public void test_localTime_parse() {

// TODO créer un objet LocalTime à l'heure 09h30m00s à l'aide de la méthode parse
LocalTime result = null;
LocalTime result = LocalTime.parse("09:30:00");


// TODO valoriser les différentes variables afin de rendre le test passant
int hour = 0;
int minutes = 0;
int second = 0;
int hour = result.getHour();
int minutes = result.getMinute();
int second = result.getSecond();

assertThat(hour, is(9));
assertThat(minutes, is(30));
Expand All @@ -51,10 +53,10 @@ public void test_localTime_format() {

// TODO créer un objet localTime à l'heure 12h00m00s
// TODO utiliser la méthode of
LocalTime localTime = null;
LocalTime localTime = LocalTime.of(12, 00, 00);

// TODO Formatter l'heure pour que le test soit passant
String result = null;
String result = localTime.format(DateTimeFormatter.ofPattern("HH:mm"));

assertThat(result, is("12:00"));
}
Expand Down
4 changes: 2 additions & 2 deletions src/test/java/java8/ex05/DateAndTime_05_Test.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@ public class DateAndTime_05_Test {
public void test_duration() throws Exception {

// TODO créer une heure à 12h30
LocalTime time1 = null;
LocalTime time1 = LocalTime.of(12, 30);

// TODO créer une heure à 16h32
LocalTime time2 = null;
LocalTime time2 = LocalTime.of(16, 32);

// TODO créer une durée (classe java.time.Duration) qui représente le temps entre les heures précédentes
Duration duration = null;
Expand Down