Skip to content

Commit

Permalink
DateUtils added
Browse files Browse the repository at this point in the history
  • Loading branch information
ignatov committed Jul 20, 2011
1 parent b974ba2 commit 11d70b9
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 15 deletions.
38 changes: 38 additions & 0 deletions src/main/scala/scala/tools/colladoc/lib/util/DateUtils.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/*
* Copyright (c) 2011, Sergey Ignatov. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification, are permitted provided
* that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of conditions and
* the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions
* and the following disclaimer in the documentation and/or other materials provided with the
* distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COLLABORATIVE SCALADOC PROJECT ``AS IS'' AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
* AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COLLABORATIVE SCALADOC
* PROJECT OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package scala.tools.colladoc.lib.util

import java.util.Date
import java.text.SimpleDateFormat

/**
* Date utilities.
* @author Sergey Ignatov
*/
object DateUtils {
def dateFormatter(d: Date) = new SimpleDateFormat("HH:mm:ss dd MMMM yyyy").format(d)

def atomDateFormatter(d: Date) = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'").format(d)

def iso8601Formatter(d: Date) = new SimpleDateFormat("yyyy-MM-dd").format(d)
}
15 changes: 5 additions & 10 deletions src/main/scala/scala/tools/colladoc/model/mapper/Comment.scala
Original file line number Diff line number Diff line change
Expand Up @@ -23,18 +23,19 @@
package scala.tools.colladoc {
package model {
package mapper {
import lib.util.Helpers._

import java.util.Date

import lib.util.NameUtils._
import lib.util.Helpers._
import lib.util.DateUtils.{atomDateFormatter, dateFormatter, iso8601Formatter}

import net.liftweb.common._
import net.liftweb.mapper._
import net.liftweb.util.Helpers._

import tools.nsc.doc.model.MemberEntity

import java.text.SimpleDateFormat
import java.util.Date

/**
* Mapper for comment table storing documentation changes.
* @author Petr Hosek
Expand Down Expand Up @@ -72,12 +73,6 @@ class Comment extends LongKeyedMapper[Comment] with IdPK {
case _ => ""
}

def dateFormatter(d: Date) = new SimpleDateFormat("HH:mm:ss dd MMMM yyyy").format(d)

def atomDateFormatter(d: Date) = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'").format(d)

def iso8601Formatter(d: Date) = new SimpleDateFormat("yyyy-MM-dd").format(d)

/** Get change author's username and date. */
def userNameDate: String =
"%s by %s".format(dateFormatter(dateTime.is), userName)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@
* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package scala.tools.colladoc.model.mapper
package scala.tools.colladoc
package model.mapper

import net.liftweb.mapper._
import net.liftweb.common.Full
import java.util.Date
import java.text.SimpleDateFormat
import lib.util.DateUtils.dateFormatter

/**
* Comment of discussion thread.
Expand Down Expand Up @@ -59,8 +59,6 @@ class Discussion extends LongKeyedMapper[Discussion] with IdPK {
case _ => ""
}

def dateFormatter(d: Date) = new SimpleDateFormat("HH:mm:ss dd MMMM yyyy").format(d)

/** Get change author's username and date. */
def userNameDate: String = "%s by %s".format(dateFormatter(dateTime.is), userName)
}
Expand Down

0 comments on commit 11d70b9

Please sign in to comment.