250 lines
4.8 KiB
Java
250 lines
4.8 KiB
Java
/*
|
|
* Copyright (C) 2020 Christian Pierre MOMON <christian.momon@devinsy.fr>
|
|
*
|
|
* This file is part of AgirStatool, simple key value database.
|
|
*
|
|
* AgirStatool is free software: you can redistribute it and/or modify
|
|
* it under the terms of the GNU Affero General Public License as
|
|
* published by the Free Software Foundation, either version 3 of the
|
|
* License, or (at your option) any later version.
|
|
*
|
|
* AgirStatool is distributed in the hope that it will be useful,
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
* GNU Affero General Public License for more details.
|
|
*
|
|
* You should have received a copy of the GNU Affero General Public License
|
|
* along with AgirStatool. If not, see <http://www.gnu.org/licenses/>.
|
|
*/
|
|
package org.april.agirstatool.core;
|
|
|
|
import java.time.LocalDate;
|
|
import java.time.LocalDateTime;
|
|
import java.time.LocalTime;
|
|
import java.time.ZoneOffset;
|
|
|
|
/**
|
|
* The Class Issue.
|
|
*/
|
|
public class Issue
|
|
{
|
|
private long id;
|
|
private Long projectId;
|
|
private LocalDateTime createdOn;
|
|
private LocalDateTime closedOn;
|
|
|
|
/**
|
|
* Instantiates a new issue.
|
|
*
|
|
* @param id
|
|
* the id
|
|
* @param projectId
|
|
* the project id
|
|
* @param createdOn
|
|
* the created on
|
|
*/
|
|
public Issue(final long id, final Long projectId, final LocalDateTime createdOn)
|
|
{
|
|
this(id, projectId, createdOn, null);
|
|
}
|
|
|
|
/**
|
|
* Instantiates a new issue.
|
|
*
|
|
* @param id
|
|
* the id
|
|
* @param projectId
|
|
* the project id
|
|
* @param createdOn
|
|
* the created on
|
|
* @param closedOn
|
|
* the closed on
|
|
*/
|
|
public Issue(final long id, final Long projectId, final LocalDateTime createdOn, final LocalDateTime closedOn)
|
|
{
|
|
this.id = id;
|
|
this.projectId = projectId;
|
|
this.createdOn = createdOn;
|
|
this.closedOn = closedOn;
|
|
}
|
|
|
|
/**
|
|
* Age in days.
|
|
*
|
|
* @return the int
|
|
*/
|
|
public int getAgeInDays()
|
|
{
|
|
int result;
|
|
|
|
long start = this.createdOn.toEpochSecond(ZoneOffset.UTC);
|
|
long end;
|
|
if (this.closedOn == null)
|
|
{
|
|
end = LocalDateTime.now().toEpochSecond(ZoneOffset.UTC);
|
|
}
|
|
else
|
|
{
|
|
end = this.closedOn.toEpochSecond(ZoneOffset.UTC);
|
|
}
|
|
|
|
result = (int) ((end - start) / (24 * 60 * 60));
|
|
|
|
//
|
|
return result;
|
|
}
|
|
|
|
/**
|
|
* Gets the age in days.
|
|
*
|
|
* @param date
|
|
* the date
|
|
* @return the age in days
|
|
*/
|
|
public int getAgeInDays(final LocalDate date)
|
|
{
|
|
int result;
|
|
|
|
if (date == null)
|
|
{
|
|
result = 0;
|
|
}
|
|
else if ((this.closedOn != null) && (this.closedOn.isBefore(LocalDateTime.of(date, LocalTime.MAX))))
|
|
{
|
|
long start = this.createdOn.toEpochSecond(ZoneOffset.UTC);
|
|
long end = this.closedOn.toEpochSecond(ZoneOffset.UTC);
|
|
|
|
result = (int) ((end - start) / (24 * 60 * 60));
|
|
}
|
|
else
|
|
{
|
|
long start = this.createdOn.toEpochSecond(ZoneOffset.UTC);
|
|
long end = LocalDateTime.of(date, LocalTime.MAX).toEpochSecond(ZoneOffset.UTC);
|
|
|
|
result = (int) ((end - start) / (24 * 60 * 60));
|
|
}
|
|
|
|
//
|
|
return result;
|
|
}
|
|
|
|
public LocalDateTime getClosedOn()
|
|
{
|
|
return this.closedOn;
|
|
}
|
|
|
|
public LocalDateTime getCreatedOn()
|
|
{
|
|
return this.createdOn;
|
|
}
|
|
|
|
public long getId()
|
|
{
|
|
return this.id;
|
|
}
|
|
|
|
public Long getProjectId()
|
|
{
|
|
return this.projectId;
|
|
}
|
|
|
|
/**
|
|
* Checks if is active at.
|
|
*
|
|
* @param date
|
|
* the date
|
|
* @return true, if is active at
|
|
*/
|
|
public boolean isActiveAt(final LocalDate date)
|
|
{
|
|
boolean result;
|
|
|
|
LocalDate createdDate = this.createdOn.toLocalDate();
|
|
LocalDate closedDate;
|
|
if (this.closedOn == null)
|
|
{
|
|
closedDate = null;
|
|
}
|
|
else
|
|
{
|
|
closedDate = this.closedOn.toLocalDate();
|
|
}
|
|
|
|
if ((!createdDate.isAfter(date)) && ((closedDate == null) || (date.isBefore(closedDate))))
|
|
{
|
|
result = true;
|
|
}
|
|
else
|
|
{
|
|
result = false;
|
|
}
|
|
|
|
//
|
|
return result;
|
|
}
|
|
|
|
/**
|
|
* Checks if is active between.
|
|
*
|
|
* @param start
|
|
* the start
|
|
* @param end
|
|
* the end
|
|
* @return true, if is active between
|
|
*/
|
|
public boolean isActiveBetween(final LocalDate start, final LocalDate end)
|
|
{
|
|
boolean result;
|
|
|
|
if ((start == null) || (end == null))
|
|
{
|
|
result = false;
|
|
}
|
|
else
|
|
{
|
|
LocalDate createdDate = this.createdOn.toLocalDate();
|
|
LocalDate closedDate;
|
|
if (this.closedOn == null)
|
|
{
|
|
closedDate = null;
|
|
}
|
|
else
|
|
{
|
|
closedDate = this.closedOn.toLocalDate();
|
|
}
|
|
|
|
if ((!createdDate.isAfter(start)) && ((closedDate == null) || (end.isBefore(closedDate))))
|
|
{
|
|
result = true;
|
|
}
|
|
else
|
|
{
|
|
result = false;
|
|
}
|
|
}
|
|
|
|
//
|
|
return result;
|
|
}
|
|
|
|
public void setClosedOn(final LocalDateTime closedOn)
|
|
{
|
|
this.closedOn = closedOn;
|
|
}
|
|
|
|
public void setCreatedOn(final LocalDateTime createdOn)
|
|
{
|
|
this.createdOn = createdOn;
|
|
}
|
|
|
|
public void setId(final long id)
|
|
{
|
|
this.id = id;
|
|
}
|
|
|
|
public void setProjectId(final Long projectId)
|
|
{
|
|
this.projectId = projectId;
|
|
}
|
|
}
|