Java Code Examples for java.util.Calendar.set()

The following are Jave code examples for showing how to use set() of the java.util.Calendar class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: Swap   File: DateUtil.java   View Source Code Vote up 7 votes
/**
 * 日期加上天数
 * @param date
 * @param dateFormat
 * @param numDay
 * @return
 */
public String addDayOfMonth(String date, DateFormat dateFormat, int numDay){

    SimpleDateFormat df = new SimpleDateFormat(dateFormat.getValue());
    Calendar c = Calendar.getInstance();
    try {
        c.setTime(df.parse(date));
        c.set(Calendar.DAY_OF_MONTH, c.get(Calendar.DAY_OF_MONTH) + numDay);

        return df.format(c.getTime());
    } catch (ParseException e) {
        e.printStackTrace();
        System.err.print(e);
        return null;
    }
}
 
Example 2
Project: boohee_v5.6   File: SportRemindReceiver.java   View Source Code Vote up 7 votes
public static void start(Context ctx) {
    AlarmManager manager = (AlarmManager) ctx.getSystemService("alarm");
    PendingIntent pending = PendingIntent.getBroadcast(ctx, 152, new Intent(ctx,
            SportRemindReceiver.class), 134217728);
    Helper.showLog(TAG, "SportRemindReceiver start");
    Calendar calNow = Calendar.getInstance();
    Calendar calSet = (Calendar) calNow.clone();
    calSet.setTimeInMillis(System.currentTimeMillis());
    int remindHour = 20;
    int remindMinute = 30;
    if (!TextUtil.isEmpty(OnePreference.getPrefSportRemindTime())) {
        String[] times = OnePreference.getPrefSportRemindTime().split("#");
        if (times.length == 2) {
            remindHour = Integer.parseInt(times[0]);
            remindMinute = Integer.parseInt(times[1]);
        }
    }
    calSet.set(11, remindHour);
    calSet.set(12, remindMinute);
    calSet.set(13, 0);
    calSet.set(14, 0);
    if (calSet.compareTo(calNow) <= 0) {
        calSet.add(5, 1);
    }
    manager.setRepeating(0, calSet.getTimeInMillis(), a.h, pending);
}
 
Example 3
Project: EsperantoRadio   File: Alarms.java   View Source Code Vote up 7 votes
/**
 * Given an alarm in hours and minutes, return a time suitable for
 * setting in AlarmManager.
 */
static Calendar calculateAlarm(int hour, int minute,
                               Alarm.DaysOfWeek daysOfWeek) {

  // start with now
  Calendar c = Calendar.getInstance();
  c.setTimeInMillis(System.currentTimeMillis());

  int nowHour = c.get(Calendar.HOUR_OF_DAY);
  int nowMinute = c.get(Calendar.MINUTE);

  // if alarm is behind current time, advance one day
  if (hour < nowHour
      || hour == nowHour && minute <= nowMinute) {
    c.add(Calendar.DAY_OF_YEAR, 1);
  }
  c.set(Calendar.HOUR_OF_DAY, hour);
  c.set(Calendar.MINUTE, minute);
  c.set(Calendar.SECOND, 0);
  c.set(Calendar.MILLISECOND, 0);

  int addDays = daysOfWeek.getNextAlarm(c);
  if (addDays > 0) c.add(Calendar.DAY_OF_WEEK, addDays);
  return c;
}
 
Example 4
Project: AssistantBySDK   File: TimeUtils.java   View Source Code Vote up 6 votes
/**
 * 获取本日的n个月前的日期,如本日=2015-03-01,n=3,则输出2014-12-01
 *
 * @param n
 * @return
 */
public static Date getSomeMonthsBefore(int n) {
    Calendar cl = Calendar.getInstance();
    cl.set(Calendar.HOUR_OF_DAY, 0);
    cl.set(Calendar.MINUTE, 0);
    cl.set(Calendar.SECOND, 0);
    cl.set(Calendar.MILLISECOND, 0);

    int year = cl.get(Calendar.YEAR);
    int month = cl.get(Calendar.MONTH);
    int day = cl.get(Calendar.DAY_OF_MONTH);
    int by = n / 12;
    int bm = n % 12;
    if (by > 0) {
        year -= by;
    }
    if (bm > month) {
        year--;
    }
    month = (12 + month - bm) % 12;
    cl.set(Calendar.YEAR, year);
    cl.set(Calendar.MONTH, month);
    cl.set(Calendar.DAY_OF_MONTH, 1);
    if (day > cl.getActualMaximum(Calendar.DAY_OF_MONTH)) {//cl为n个月前的1号,如果该月的最大日数比现在的日数小,则取当月的最大日数
        cl.set(Calendar.DAY_OF_MONTH, cl.getActualMaximum(Calendar.DAY_OF_MONTH));
    } else {
        cl.set(Calendar.DAY_OF_MONTH, day);
    }
    return cl.getTime();
}
 
Example 5
Project: Spring-Boot-Server   File: DateUtils.java   View Source Code Vote up 6 votes
/**
 * 获取最近1年所有月份数据
 * 
 * @return
 */
public static List<String> getLastYearMonths() {
	List<String> list_res = new ArrayList<String>();
	Calendar cal = Calendar.getInstance();
	cal.set(Calendar.MONTH, cal.get(Calendar.MONTH) + 1); // 要先+1,才能把本月的算进去</span>
	for (int i = 0; i < 12; i++) {
		cal.set(Calendar.MONTH, cal.get(Calendar.MONTH) - 1); // 逐次往前推1个月
		list_res.add(cal.get(Calendar.YEAR) + "-" + fillZero((cal.get(Calendar.MONTH) + 1) + "", 2));
	}
	return list_res;
}
 
Example 6
Project: rmq4note   File: MessageClientIDSetter.java   View Source Code Vote up 6 votes
private synchronized static void setStartTime(long millis) {
    Calendar cal = Calendar.getInstance();
    cal.setTimeInMillis(millis);
    cal.set(Calendar.DAY_OF_MONTH, 1);
    cal.set(Calendar.HOUR, 0);
    cal.set(Calendar.MINUTE, 0);
    cal.set(Calendar.SECOND, 0);
    cal.set(Calendar.MILLISECOND, 0);
    startTime = cal.getTimeInMillis();
    cal.add(Calendar.MONTH, 1);
    nextStartTime = cal.getTimeInMillis();
}
 
Example 7
Project: wcs-android-sdk   File: DateUtil.java   View Source Code Vote up 6 votes
public static Date hourEndTime(Date date) {
    Calendar calendar = Calendar.getInstance();
    calendar.setTime(date);
    calendar.set(Calendar.MINUTE, 59);
    calendar.set(Calendar.SECOND, 59);
    calendar.set(Calendar.MILLISECOND, 0);
    return calendar.getTime();
}
 
Example 8
Project: Material-Calendar-View   File: CalendarPageAdapter.java   View Source Code Vote up 6 votes
/**
 * This method fill calendar GridView with days
 *
 * @param position Position of current page in ViewPager
 */
private void loadMonth(int position) {
    ArrayList<Date> days = new ArrayList<>();

    // Get Calendar object instance
    Calendar calendar = (Calendar) mCalendarProperties.getCurrentDate().clone();

    // Add months to Calendar (a number of months depends on ViewPager position)
    calendar.add(Calendar.MONTH, position);

    // Set day of month as 1
    calendar.set(Calendar.DAY_OF_MONTH, 1);

    // Get a number of the first day of the week
    int dayOfWeek = calendar.get(Calendar.DAY_OF_WEEK);

    // Count when month is beginning
    int monthBeginningCell = dayOfWeek + (dayOfWeek == 1 ? 5 : -2);

    // Subtract a number of beginning days, it will let to load a part of a previous month
    calendar.add(Calendar.DAY_OF_MONTH, -monthBeginningCell);

    /*
    Get all days of one page (42 is a number of all possible cells in one page
    (a part of previous month, current month and a part of next month))
     */
    while (days.size() < 42) {
        days.add(calendar.getTime());
        calendar.add(Calendar.DAY_OF_MONTH, 1);
    }

    mPageMonth = calendar.get(Calendar.MONTH) - 1;
    CalendarDayAdapter calendarDayAdapter = new CalendarDayAdapter(this, mContext,
            mCalendarProperties, days, mPageMonth);

    mCalendarGridView.setAdapter(calendarDayAdapter);
}
 
Example 9
Project: android-project-gallery   File: DateUtils.java   View Source Code Vote up 6 votes
/**
 * 返回月的第一天
 * 
 * @return
 */
public static long getFirstDayOfMonth()
{
	Calendar calendar = new GregorianCalendar();

	calendar.set(Calendar.DAY_OF_MONTH, 1);

	calendar.set(Calendar.HOUR_OF_DAY, 0);
	calendar.set(Calendar.MINUTE, 0);
	calendar.set(Calendar.SECOND, 0);
	calendar.set(Calendar.MILLISECOND, 0);

	Log.D(TAG, "getFirstDayOfMonth: " + calendar.getTime());
	return calendar.getTimeInMillis();
}
 
Example 10
Project: ProyectoPacientes   File: ResultSetRegressionTest.java   View Source Code Vote up 6 votes
public void testBug15604() throws Exception {
    createTable("testBug15604_date_cal", "(field1 DATE)");
    Properties props = new Properties();
    props.setProperty("useLegacyDatetimeCode", "false");
    props.setProperty("sessionVariables", "time_zone='America/Chicago'");

    Connection nonLegacyConn = getConnectionWithProps(props);

    Calendar cal = Calendar.getInstance(TimeZone.getTimeZone("GMT"));

    cal.set(Calendar.YEAR, 2005);
    cal.set(Calendar.MONTH, 4);
    cal.set(Calendar.DAY_OF_MONTH, 15);
    cal.set(Calendar.HOUR_OF_DAY, 0);
    cal.set(Calendar.MINUTE, 0);
    cal.set(Calendar.SECOND, 0);
    cal.set(Calendar.MILLISECOND, 0);

    java.sql.Date sqlDate = new java.sql.Date(cal.getTime().getTime());

    Calendar cal2 = Calendar.getInstance();
    cal2.setTime(sqlDate);
    System.out.println(new java.sql.Date(cal2.getTime().getTime()));
    this.pstmt = nonLegacyConn.prepareStatement("INSERT INTO testBug15604_date_cal VALUES (?)");

    this.pstmt.setDate(1, sqlDate, cal);
    this.pstmt.executeUpdate();
    this.rs = nonLegacyConn.createStatement().executeQuery("SELECT field1 FROM testBug15604_date_cal");
    this.rs.next();

    assertEquals(sqlDate.getTime(), this.rs.getDate(1, cal).getTime());
}
 
Example 11
Project: engine   File: ByteBufferUtil.java   View Source Code Vote up 6 votes
/**
 * Translate bcd buffer to GMT time
 *
 * @param buffer byte[]{year-2000,month,day_of_month,hour_of_day,minute,seconds}
 * @param offset The postion where buffer to translate from
 * @return The GMT time encode by bcd
 * @throws Exception The time need 6 unsigned8bit at least, if the buffer avaible size less than 6, this will happen
 */
public static long bcdbuf2Date(byte[] buffer, int offset) throws Exception {
    if (buffer.length - offset < 6) {
        throw new Exception("buffer length is not enough");
    }
    Calendar now = Calendar.getInstance();
    now.set(Calendar.YEAR, BCDUtil.bcd2value(buffer, offset + 0, 1) + 2000);
    now.set(Calendar.MONTH, BCDUtil.bcd2value(buffer, offset + 1, 1) - 1);
    now.set(Calendar.DAY_OF_MONTH, BCDUtil.bcd2value(buffer, offset + 2, 1));
    now.set(Calendar.HOUR_OF_DAY, BCDUtil.bcd2value(buffer, offset + 3, 1));
    now.set(Calendar.MINUTE, BCDUtil.bcd2value(buffer, offset + 4, 1));
    now.set(Calendar.SECOND, BCDUtil.bcd2value(buffer, offset + 5, 1));
    now.set(Calendar.MILLISECOND, 0);
    return now.getTimeInMillis();
}
 
Example 12
Project: jdk8u-jdk   File: TimestampTests.java   View Source Code Vote up 6 votes
@Test
public void test50() {
    Calendar cal = Calendar.getInstance();
    Timestamp ts1 = new Timestamp(System.currentTimeMillis());
    cal.setTimeInMillis(ts1.getTime());
    cal.add(Calendar.MONTH, -1);
    cal.set(Calendar.DAY_OF_MONTH, cal.getActualMaximum(Calendar.DAY_OF_MONTH));
    Timestamp ts2 = new Timestamp(cal.getTimeInMillis());
    assertTrue(!ts1.equals(ts2) && ts1.equals(ts1));
}
 
Example 13
Project: lams   File: CalendarIntervalTriggerImpl.java   View Source Code Vote up 6 votes
private boolean daylightSavingHourShiftOccurredAndAdvanceNeeded(Calendar newTime, int initialHourOfDay, Date afterTime) {
    if(isPreserveHourOfDayAcrossDaylightSavings() && newTime.get(Calendar.HOUR_OF_DAY) != initialHourOfDay) {
        newTime.set(Calendar.HOUR_OF_DAY, initialHourOfDay);
        if (newTime.get(Calendar.HOUR_OF_DAY) != initialHourOfDay) {
            return isSkipDayIfHourDoesNotExist();
        } else {
            return !newTime.getTime().after(afterTime);
        }
    }
    return false;
}
 
Example 14
Project: BaseCore   File: TimeUtils.java   View Source Code Vote up 6 votes
/**
 * 获取本月的第一天
 *
 * @return
 */
public static String getMonthStartDate() {
    SimpleDateFormat dateFormater = new SimpleDateFormat("yyyy-MM-dd");
    Calendar cal = Calendar.getInstance();
    cal.set(Calendar.DAY_OF_MONTH, 1);
    cal.getTime();
    return dateFormater.format(cal.getTime()) + "";
}
 
Example 15
Project: Mvp-Retrofit-Rxjava-Rxbus   File: DateUtils.java   View Source Code Vote up 6 votes
/**
 * 根据年月日时分秒毫秒获取时间
 * @param year
 * @param month
 * @param date
 * @param hour
 * @param minute
 * @param second
 * @param millisecond
 * @return
 */
public static long getTime(int year, int month, int date, int hour, int minute, int second, int millisecond) {
	Calendar calendar = Calendar.getInstance();
	calendar.set(Calendar.YEAR, year);
	calendar.set(Calendar.MONTH, month - 1 + Calendar.JANUARY);
	calendar.set(Calendar.DATE, date);
	calendar.set(Calendar.HOUR_OF_DAY, hour);
	calendar.set(Calendar.MINUTE, minute);
	calendar.set(Calendar.SECOND, second);
	calendar.set(Calendar.MILLISECOND, millisecond);
	return calendar.getTimeInMillis();
}
 
Example 16
Project: Planchester   File: DateHelper.java   View Source Code Vote up 6 votes
/**
 * @param  dayOfWeek            date in the week you would like to get the end date from
 * @param  weekStartDayIndex    index of the day the weeks ends at. ATTENTION: sunday = 1, monday = 2, ...
 * @return                      date of the last day of week
 */
public static Calendar getEndOfWeek(Calendar dayOfWeek, int weekStartDayIndex) {
    Calendar endDay = (Calendar) dayOfWeek.clone();
    while (endDay.get(Calendar.DAY_OF_WEEK) != weekStartDayIndex) {
        endDay.add(Calendar.DATE, +1);
    }
    endDay.set(Calendar.HOUR_OF_DAY, 23);
    endDay.set(Calendar.MINUTE, 59);
    endDay.set(Calendar.SECOND, 59);
    endDay.set(Calendar.MILLISECOND, 999);
    return endDay;
}
 
Example 17
Project: classchecks   File: BasicService.java   View Source Code Vote up 5 votes
/**
 * 计算指定时刻属于那一堂课
 * 
 * @param list
 *            学校上课时间列表
 * @param time
 *            指定时刻
 * @return 节次 出现异常或者不存在返回-1
 */
private Integer getSection(List<SchoolCourseTimeVo> list, Calendar time) {
	if (!StringUtils.notNull(list) || list.isEmpty() || !StringUtils.notNull(time)) {
		return -1;
	}
	boolean flag = false;
	Integer section = -1;

	Calendar tmpTime = null;
	Calendar tmpEndTime = null;
	Long startMilliSecond = 0L;
	Long endMilliSecond = 0L;
	Long timeMilliSecond = time.getTimeInMillis();

	int duringMilliSecond = 5 * 60 * 1000;

	for (SchoolCourseTimeVo schoolCourseTimeVo : list) {
		tmpTime = Calendar.getInstance();
		tmpEndTime = Calendar.getInstance();
		try {
			BeanUtils.copyProperties(tmpTime, time);
			tmpTime.set(Calendar.HOUR_OF_DAY, schoolCourseTimeVo.getHour());
			tmpTime.set(Calendar.MINUTE, schoolCourseTimeVo.getMiniute());
			tmpTime.set(Calendar.SECOND, 0);
			tmpEndTime.set(Calendar.HOUR_OF_DAY, schoolCourseTimeVo.getEndHour());
			tmpEndTime.set(Calendar.MINUTE, schoolCourseTimeVo.getEndMiniute());
			tmpEndTime.set(Calendar.SECOND, 0);

			startMilliSecond = tmpTime.getTimeInMillis() - duringMilliSecond;
			endMilliSecond = tmpEndTime.getTimeInMillis() + duringMilliSecond;
			if (timeMilliSecond > startMilliSecond && timeMilliSecond < endMilliSecond) {
				section = schoolCourseTimeVo.getSection();
				flag = true;
			}
		} catch (IllegalAccessException | InvocationTargetException e) {
			LOG.debug("判断时间是哪一堂课时出现异常  SchoolCourseTimeVo:{0}", e);
			flag = true;
		}
		if (flag) {
			break;
		}
	}
	return section;
}
 
Example 18
Project: asura   File: DailyCalendar.java   View Source Code Vote up 5 votes
/**
 * Sets the time range for the <CODE>DailyCalendar</CODE> to the times
 * represented in the specified values.  
 * 
 * @param rangeStartingHourOfDay the hour of the start of the time range
 * @param rangeStartingMinute    the minute of the start of the time range
 * @param rangeStartingSecond    the second of the start of the time range
 * @param rangeStartingMillis    the millisecond of the start of the time
 *                               range
 * @param rangeEndingHourOfDay   the hour of the end of the time range
 * @param rangeEndingMinute      the minute of the end of the time range
 * @param rangeEndingSecond      the second of the end of the time range
 * @param rangeEndingMillis      the millisecond of the start of the time 
 *                               range
 */
public void setTimeRange(int rangeStartingHourOfDay,
                          int rangeStartingMinute,
                          int rangeStartingSecond,
                          int rangeStartingMillis,
                          int rangeEndingHourOfDay,
                          int rangeEndingMinute,
                          int rangeEndingSecond,
                          int rangeEndingMillis) {
    validate(rangeStartingHourOfDay,
             rangeStartingMinute,
             rangeStartingSecond,
             rangeStartingMillis);
    
    validate(rangeEndingHourOfDay,
             rangeEndingMinute,
             rangeEndingSecond,
             rangeEndingMillis);
    
    Calendar startCal = createJavaCalendar();
    startCal.set(Calendar.HOUR_OF_DAY, rangeStartingHourOfDay);
    startCal.set(Calendar.MINUTE, rangeStartingMinute);
    startCal.set(Calendar.SECOND, rangeStartingSecond);
    startCal.set(Calendar.MILLISECOND, rangeStartingMillis);
    
    Calendar endCal = createJavaCalendar();
    endCal.set(Calendar.HOUR_OF_DAY, rangeEndingHourOfDay);
    endCal.set(Calendar.MINUTE, rangeEndingMinute);
    endCal.set(Calendar.SECOND, rangeEndingSecond);
    endCal.set(Calendar.MILLISECOND, rangeEndingMillis);
    
    if (!startCal.before(endCal)) {
        throw new IllegalArgumentException(invalidTimeRange +
                rangeStartingHourOfDay + ":" +
                rangeStartingMinute + ":" +
                rangeStartingSecond + ":" +
                rangeStartingMillis + separator +
                rangeEndingHourOfDay + ":" +
                rangeEndingMinute + ":" +
                rangeEndingSecond + ":" +
                rangeEndingMillis);
    }
    
    this.rangeStartingHourOfDay = rangeStartingHourOfDay;
    this.rangeStartingMinute = rangeStartingMinute;
    this.rangeStartingSecond = rangeStartingSecond;
    this.rangeStartingMillis = rangeStartingMillis;
    this.rangeEndingHourOfDay = rangeEndingHourOfDay;
    this.rangeEndingMinute = rangeEndingMinute;
    this.rangeEndingSecond = rangeEndingSecond;
    this.rangeEndingMillis = rangeEndingMillis;
}
 
Example 19
Project: flume-release-1.7.0   File: TestHDFSEventSink.java   View Source Code Vote up 5 votes
@Test
public void testSlowAppendFailure() throws InterruptedException,
    LifecycleException, EventDeliveryException, IOException {

  LOG.debug("Starting...");
  final String fileName = "FlumeData";
  final long rollCount = 5;
  final long batchSize = 2;
  final int numBatches = 2;
  String newPath = testPath + "/singleBucket";
  int i = 1, j = 1;

  // clear the test directory
  Configuration conf = new Configuration();
  FileSystem fs = FileSystem.get(conf);
  Path dirPath = new Path(newPath);
  fs.delete(dirPath, true);
  fs.mkdirs(dirPath);

  // create HDFS sink with slow writer
  HDFSTestWriterFactory badWriterFactory = new HDFSTestWriterFactory();
  sink = new HDFSEventSink(badWriterFactory);

  Context context = new Context();
  context.put("hdfs.path", newPath);
  context.put("hdfs.filePrefix", fileName);
  context.put("hdfs.rollCount", String.valueOf(rollCount));
  context.put("hdfs.batchSize", String.valueOf(batchSize));
  context.put("hdfs.fileType", HDFSTestWriterFactory.TestSequenceFileType);
  context.put("hdfs.callTimeout", Long.toString(1000));
  Configurables.configure(sink, context);

  Channel channel = new MemoryChannel();
  Configurables.configure(channel, context);

  sink.setChannel(channel);
  sink.start();

  Calendar eventDate = Calendar.getInstance();

  // push the event batches into channel
  for (i = 0; i < numBatches; i++) {
    Transaction txn = channel.getTransaction();
    txn.begin();
    for (j = 1; j <= batchSize; j++) {
      Event event = new SimpleEvent();
      eventDate.clear();
      eventDate.set(2011, i, i, i, 0); // yy mm dd
      event.getHeaders().put("timestamp",
          String.valueOf(eventDate.getTimeInMillis()));
      event.getHeaders().put("hostname", "Host" + i);
      event.getHeaders().put("slow", "1500");
      event.setBody(("Test." + i + "." + j).getBytes());
      channel.put(event);
    }
    txn.commit();
    txn.close();

    // execute sink to process the events
    Status satus = sink.process();

    // verify that the append returned backoff due to timeotu
    Assert.assertEquals(satus, Status.BACKOFF);
  }

  sink.stop();
}
 
Example 20
Project: word-clock-raspberry-pi-zero-neopixels   File: WordClockTest.java   View Source Code Vote up 5 votes
@Test
public void testGetMatrixByDate() throws Exception {
    Calendar calendar = Calendar.getInstance();
    calendar.set(Calendar.HOUR_OF_DAY,1);
    calendar.set(Calendar.MINUTE,0);
    
    WordClock wordClock = new WordClock();
    int[][] matrix1 = new int[4][1];
    matrix1[0][0] = 1;
    matrix1[1][0] = 1;
    matrix1[2][0] = 1;
    matrix1[3][0] = 1;
    wordClock.addInterval(new WordClock.Interval(1,1, 0, 59, matrix1));
    
    int[][] matrix = wordClock.getMatrixByDate(calendar.getTime());
    
    assertThat("Should have a 4x1 matrix equal to matrix 1",matrix.length,CoreMatchers.equalTo(4));
    assertThat("Should have a 4x1 matrix equal to matrix 1",matrix[0].length,CoreMatchers.equalTo(1));
    assertThat("Should have the correct copied values",matrix[0][0],CoreMatchers.equalTo(1));
    assertThat("Should have the correct copied values",matrix[1][0],CoreMatchers.equalTo(1));
    assertThat("Should have the correct copied values",matrix[2][0],CoreMatchers.equalTo(1));
    assertThat("Should have the correct copied values",matrix[3][0],CoreMatchers.equalTo(1));

    int[][] matrix2 = new int[4][4];
    matrix2[0][0] = 0;
    matrix2[1][3] = 1;
    matrix2[2][3] = 1;
    matrix2[3][3] = 1;
    wordClock.addInterval(new WordClock.Interval(1,1, 0, 59, matrix2));

    matrix = wordClock.getMatrixByDate(calendar.getTime());

    assertThat("Should have a 4x4 matrix equal to matrix 2",matrix.length,CoreMatchers.equalTo(4));
    assertThat("Should have a 4x4 matrix equal to matrix 2",matrix[0].length,CoreMatchers.equalTo(4));
    assertThat("Should have the correct copied values",matrix[0][0],CoreMatchers.equalTo(1));
    assertThat("Should have the correct copied values",matrix[1][0],CoreMatchers.equalTo(1));
    assertThat("Should have the correct copied values",matrix[2][0],CoreMatchers.equalTo(1));
    assertThat("Should have the correct copied values",matrix[3][0],CoreMatchers.equalTo(1));
    assertThat("Should have the correct copied values",matrix[1][3],CoreMatchers.equalTo(1));
    assertThat("Should have the correct copied values",matrix[2][3],CoreMatchers.equalTo(1));
    assertThat("Should have the correct copied values",matrix[3][3],CoreMatchers.equalTo(1));


    int[][] matrix3 = new int[5][4];
    matrix3[4][0] = 1;
    wordClock.addInterval(new WordClock.Interval(1,1, 0, 59, matrix3));

    matrix = wordClock.getMatrixByDate(calendar.getTime());

    assertThat("Should have a 4x4 matrix equal to matrix 2",matrix.length,CoreMatchers.equalTo(5));
    assertThat("Should have a 4x4 matrix equal to matrix 2",matrix[0].length,CoreMatchers.equalTo(4));
    assertThat("Should have the correct copied values",matrix[0][0],CoreMatchers.equalTo(1));
    assertThat("Should have the correct copied values",matrix[1][0],CoreMatchers.equalTo(1));
    assertThat("Should have the correct copied values",matrix[2][0],CoreMatchers.equalTo(1));
    assertThat("Should have the correct copied values",matrix[3][0],CoreMatchers.equalTo(1));
    assertThat("Should have the correct copied values",matrix[1][3],CoreMatchers.equalTo(1));
    assertThat("Should have the correct copied values",matrix[2][3],CoreMatchers.equalTo(1));
    assertThat("Should have the correct copied values",matrix[3][3],CoreMatchers.equalTo(1));
    assertThat("Should have the correct copied values",matrix[4][0],CoreMatchers.equalTo(1));
}