Created
April 23, 2014 04:07
-
-
Save Centaur/11202461 to your computer and use it in GitHub Desktop.
transform date
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.time.LocalDate | |
import java.time.format.DateTimeFormatter | |
import java.util.Locale | |
import scala.util.matching.Regex.Match | |
val extractor = """<Current Date \+ (\d+) days>""".r | |
def transform(src: String): String = { | |
def calc(matched: Match) = { | |
LocalDate.now().plusDays(matched.group(1).toInt).format(DateTimeFormatter.ofPattern("MMMM dd, YYYY", Locale.US)) | |
} | |
extractor.replaceAllIn(src, calc _) | |
} | |
val data = " Your dadadadada <Current Date + 6 days>.\r\nYou dadadadadatrtrton <Current Date + 22 days>." | |
val target = " Your dadadadada April 29, 2014.\r\nYou dadadadadatrtrton May 15, 2014." | |
assert(transform(data) == target) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment