Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
V
VIPSCommon
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Container registry
Model registry
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
VIPS
VIPSCommon
Commits
960f59f3
Commit
960f59f3
authored
7 years ago
by
Tor-Einar Skog
Browse files
Options
Downloads
Patches
Plain Diff
First commit of DateTimeInterval class
parent
e82f699c
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/main/java/no/nibio/vips/util/DateTimeInterval.java
+101
-0
101 additions, 0 deletions
src/main/java/no/nibio/vips/util/DateTimeInterval.java
with
101 additions
and
0 deletions
src/main/java/no/nibio/vips/util/DateTimeInterval.java
0 → 100644
+
101
−
0
View file @
960f59f3
/*
* Copyright (c) 2018 NIBIO <http://www.nibio.no/>.
*
* This file is part of VIPSCommon.
* VIPSCommon is free software: you can redistribute it and/or modify
* it under the terms of the NIBIO Open Source License as published by
* NIBIO, either version 1 of the License, or (at your option) any
* later version.
*
* VIPSCommon 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
* NIBIO Open Source License for more details.
*
* You should have received a copy of the NIBIO Open Source License
* along with VIPSCommon. If not, see <http://www.nibio.no/licenses/>.
*
*/
package
no.nibio.vips.util
;
import
java.util.Date
;
import
java.util.List
;
import
java.util.OptionalLong
;
/**
* Util for simple treatment of DateTime interval/period
* ...meaning a period that starts with a date and ends with a date
* @copyright 2018 <a href="http://www.nibio.no/">NIBIO</a>
* @author Tor-Einar Skog <tor-einar.skog@nibio.no>
*/
public
class
DateTimeInterval
{
private
Date
start
,
end
;
public
DateTimeInterval
(
Date
start
,
Date
end
){
this
.
start
=
start
;
this
.
end
=
end
;
}
public
Boolean
isDateInInterval
(
Date
aDate
){
return
aDate
.
compareTo
(
this
.
start
)
>=
0
&&
aDate
.
compareTo
(
this
.
end
)
<=
0
;
}
public
Boolean
isDateAfterInterval
(
Date
aDate
){
return
aDate
.
compareTo
(
this
.
end
)
>=
0
;
}
public
Boolean
isDateBeforeInterval
(
Date
aDate
){
return
aDate
.
compareTo
(
this
.
start
)
<=
0
;
}
/**
* Given a list of periods, finds the last end date of all periods
* @param intervals the set of periods to compare
* @return
*/
public
static
Date
getLastEndDate
(
List
<
DateTimeInterval
>
intervals
)
{
OptionalLong
max
=
intervals
.
stream
().
mapToLong
(
i
->
i
.
getEnd
().
getTime
()).
max
();
return
max
.
isPresent
()
?
new
Date
(
max
.
getAsLong
())
:
null
;
}
/**
* Given a list of periods, finds the last end date of all periods
* @param intervals the set of periods to compare
* @return
*/
public
static
Date
getFirstStartDate
(
List
<
DateTimeInterval
>
intervals
)
{
OptionalLong
min
=
intervals
.
stream
().
mapToLong
(
i
->
i
.
getStart
().
getTime
()).
min
();
return
min
.
isPresent
()
?
new
Date
(
min
.
getAsLong
())
:
null
;
}
/**
* @return the start
*/
public
Date
getStart
()
{
return
start
;
}
/**
* @param start the start to set
*/
public
void
setStart
(
Date
start
)
{
this
.
start
=
start
;
}
/**
* @return the end
*/
public
Date
getEnd
()
{
return
end
;
}
/**
* @param end the end to set
*/
public
void
setEnd
(
Date
end
)
{
this
.
end
=
end
;
}
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment