Add formatted date placeholder
This commit is contained in:
parent
e5041d1822
commit
4b542a2677
|
|
@ -6,6 +6,7 @@ import com.intellij.openapi.actionSystem.Constraints
|
||||||
import com.intellij.openapi.actionSystem.DefaultActionGroup
|
import com.intellij.openapi.actionSystem.DefaultActionGroup
|
||||||
import com.intellij.openapi.project.Project
|
import com.intellij.openapi.project.Project
|
||||||
import com.intellij.openapi.startup.StartupActivity
|
import com.intellij.openapi.startup.StartupActivity
|
||||||
|
import de.idetools.filename_template.placeholders.DatePlaceholder
|
||||||
import de.idetools.filename_template.placeholders.DefaultPlaceholder
|
import de.idetools.filename_template.placeholders.DefaultPlaceholder
|
||||||
import de.idetools.filename_template.placeholders.EpochPlaceholder
|
import de.idetools.filename_template.placeholders.EpochPlaceholder
|
||||||
import de.idetools.filename_template.placeholders.PlaceholderProcessor
|
import de.idetools.filename_template.placeholders.PlaceholderProcessor
|
||||||
|
|
@ -21,6 +22,7 @@ class InitializeFilenameTemplateActivity : StartupActivity {
|
||||||
|
|
||||||
val placeholders = listOf(
|
val placeholders = listOf(
|
||||||
EpochPlaceholder(),
|
EpochPlaceholder(),
|
||||||
|
DatePlaceholder(),
|
||||||
DefaultPlaceholder()
|
DefaultPlaceholder()
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,20 @@
|
||||||
|
package de.idetools.filename_template.placeholders
|
||||||
|
|
||||||
|
import java.time.LocalDateTime
|
||||||
|
import java.time.format.DateTimeFormatter
|
||||||
|
|
||||||
|
class DatePlaceholder : Placeholder {
|
||||||
|
override fun supports(placeholder: String): Boolean = placeholder.startsWith("DATE")
|
||||||
|
|
||||||
|
override fun process(placeholder: String, context: PlaceholderContext): String {
|
||||||
|
val date = LocalDateTime.now()
|
||||||
|
val datePattern = placeholder.substringAfter(":", "")
|
||||||
|
val formatter =
|
||||||
|
if (datePattern.isBlank()) {
|
||||||
|
DateTimeFormatter.ISO_DATE
|
||||||
|
} else {
|
||||||
|
DateTimeFormatter.ofPattern(datePattern)
|
||||||
|
}
|
||||||
|
return date.format(formatter)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -35,6 +35,12 @@
|
||||||
<br/>
|
<br/>
|
||||||
<p>A template might contain following place holders:</p>
|
<p>A template might contain following place holders:</p>
|
||||||
<dl>
|
<dl>
|
||||||
|
<dt>{DATE:FORMAT}</dt>
|
||||||
|
<dd>
|
||||||
|
The formatted date. If the format is omitted "yyyy-MM-dd" is used by default.<br />
|
||||||
|
See the java documentation for supported patterns: <a href="https://docs.oracle.com/en/java/javase/15/docs/api/java.base/java/time/format/DateTimeFormatter.html">Patterns for Formatting and Parsing</a>
|
||||||
|
</dd>
|
||||||
|
|
||||||
<dt>{EPOCH}</dt>
|
<dt>{EPOCH}</dt>
|
||||||
<dd>The current unix time stamp: Seconds since the Unix Epoch on January 1st, 1970 at UTC.</dd>
|
<dd>The current unix time stamp: Seconds since the Unix Epoch on January 1st, 1970 at UTC.</dd>
|
||||||
</dl>
|
</dl>
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user