Skip to content

Commit

Permalink
conference: smarter date formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
gicmo committed Mar 10, 2016
1 parent db08498 commit 3772880
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 15 deletions.
25 changes: 25 additions & 0 deletions app/models/Conference.scala
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,31 @@ class Conference extends Model with Owned {
var abstracts: JSet[Abstract] = new JTreeSet[Abstract]()
@OneToMany(mappedBy = "conference", cascade = Array(CascadeType.ALL), orphanRemoval = true)
var topics: JSet[Topic] = new JTreeSet[Topic]()


def formatDuration : String = {
if (startDate == null || endDate == null) {
return ""
}

if (startDate.year.get == endDate.year.get) {
if (startDate.monthOfYear.get == endDate.monthOfYear.get) {
if (startDate.dayOfMonth.get == endDate.dayOfMonth.get) {
val dateFormatter = DateTimeFormat.forPattern("d MMMM yyyy")
startDate.toString(dateFormatter)
} else {
startDate.monthOfYear.getAsText + " " + startDate.dayOfMonth.get + " - " + endDate.dayOfMonth.get + ", " + endDate.year.get
}
} else {
val fmtDayMonth = DateTimeFormat.forPattern("MMMM, d")
startDate.toString(fmtDayMonth) + " - " + endDate.toString(fmtDayMonth) + ", " + endDate.year.get
}
} else {
val dateFormatter = DateTimeFormat.forPattern("MMMM d, yyyy")
startDate.toString(dateFormatter) + " - " + endDate.toString(dateFormatter)
}
}

}

object Conference extends Model {
Expand Down
6 changes: 1 addition & 5 deletions app/views/conference.scala.html
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,7 @@ <h1>@conference.name</h1>
@conference.description
</div>
}
@if(conference.startDate != null && conference.endDate != null) {
<p>
@conference.startDate.toString(conference.dateFormatter) - @conference.endDate.toString(conference.dateFormatter)
</p>
}
<p>@conference.formatDuration</p>
<!-- user/conference options depending on the conference state -->
@if(conference.isOpen) {
<p>
Expand Down
14 changes: 4 additions & 10 deletions app/views/conferencelist.scala.html
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,9 @@ <h3>
@conference.description
</div>
}
@if(conference.startDate != null && conference.endDate != null) {
<p>
@conference.startDate.toString(conference.dateFormatter) - @conference.endDate.toString(conference.dateFormatter)
</p>
}

<p>@conference.formatDuration</p>

@if(account.isDefined && (conference.isOwner(account.get) || account.get.isAdmin)) {
<div class="form-group">
<a href="@routes.Application.adminConference(conference.uuid)" class="btn btn-danger">
Expand Down Expand Up @@ -65,11 +63,7 @@ <h2>Past conferences</h2>
<a href="@routes.Application.abstractsPublic(conference.short)">
<h4 class="media-heading">@conference.name</h4>
</a>
@if(conference.startDate != null && conference.endDate != null) {
<p>
@conference.startDate.toString(conference.dateFormatter) - @conference.endDate.toString(conference.dateFormatter)
</p>
}
<p>@conference.formatDuration</p>
@if(account.isDefined && (conference.isOwner(account.get) || account.get.isAdmin)) {
<div class="form-group">
<a href="@routes.Application.adminConference(conference.uuid)" class="btn btn-danger">
Expand Down

0 comments on commit 3772880

Please sign in to comment.