agirstatool/src/org/april/agirstatool/core/Issue.java

167 lines
3.4 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 int id;
private Integer projectId;
private LocalDateTime createdOn;
private LocalDateTime closedOn;
/**
* Instantiates a new issue.
*
* @param id
* the id
* @param createdOn
* the created on
*/
public Issue(final int id, final Integer projectId, final LocalDateTime createdOn)
{
this(id, projectId, createdOn, null);
}
/**
* Instantiates a new issue.
*
* @param id
* the id
* @param createdOn
* the created on
* @param closedOn
* the closed on
*/
public Issue(final int id, final Integer 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 int getId()
{
return this.id;
}
public Integer getProjectId()
{
return this.projectId;
}
public void setClosedOn(final LocalDateTime closedOn)
{
this.closedOn = closedOn;
}
public void setCreatedOn(final LocalDateTime createdOn)
{
this.createdOn = createdOn;
}
public void setId(final int id)
{
this.id = id;
}
public void setProjectId(final Integer projectId)
{
this.projectId = projectId;
}
}