Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Split methods into logical units and change JVM usage #5

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
211 changes: 0 additions & 211 deletions simpledate/src/main/java/com/parassidhu/simpledate/SimpleDate.kt

This file was deleted.

67 changes: 67 additions & 0 deletions simpledate/src/main/kotlin/com/parassidhu/simpledate/Date.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
@file:JvmMultifileClass
@file:JvmName("SimpleDate")

package com.parassidhu.simpledate

import java.util.*


fun Date?.toDateStandard(): String {
val pattern = "dd MMMM YYYY"
return dateAsString(this, pattern)
}

fun Date?.toDateStandardConcise(): String {
val pattern = "dd MMM yyyy"
return dateAsString(this, pattern)
}

fun Date?.toDateStandardInDigits(): String {
val pattern = "dd-MM-yyyy"
return dateAsString(this, pattern)
}

fun Date?.toDateYY(): String {
val pattern = "dd MMMM yy"
return dateAsString(this, pattern)
}

fun Date?.toDateYYConcise(): String {
val pattern = "dd MMM yy"
return dateAsString(this, pattern)
}

fun Date?.toDateYYInDigits(): String {
val pattern = "dd-MM-yy"
return dateAsString(this, pattern)
}

fun Date?.toDateYMD(): String {
val pattern = "yyyy MMMM dd"
return dateAsString(this, pattern)
}

fun Date?.toDateYMDConcise(): String {
val pattern = "yyyy MMM dd"
return dateAsString(this, pattern)
}

fun Date?.toDateYMDInDigits(): String {
val pattern = "yyyy-MM-dd"
return dateAsString(this, pattern)
}

fun Date?.toDateEMd(): String {
val pattern = "EEE, MMM dd"
return dateAsString(this, pattern)
}

fun Date?.toDateEMYShort(): String {
val pattern = "EEE, MMM YY"
return dateAsString(this, pattern)
}

fun Date?.toDateEMY(): String {
val pattern = "EEEE, MMMM YYYY"
return dateAsString(this, pattern)
}
72 changes: 72 additions & 0 deletions simpledate/src/main/kotlin/com/parassidhu/simpledate/DateTime.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
@file:JvmMultifileClass
@file:JvmName("SimpleDate")

package com.parassidhu.simpledate

import java.util.*

fun Date?.toDateTimeStandard(): String {
val pattern = "dd MMMM yyyy HH:mm:ss"

return dateAsString(this, pattern)
}

fun Date?.toDateTimeStandardIn12Hours(): String {
val pattern = "dd MMMM yyyy h:mm:ss a"
return dateAsString(this, pattern)
}

fun Date?.toDateTimeStandardInDigits(): String {
val pattern = "dd-MM-yyyy HH:mm:ss"
return dateAsString(this, pattern)
}

fun Date?.toDateTimeStandardInDigitsAnd12Hours(): String {
val pattern = "dd-MM-yyyy h:mm:ss a"
return dateAsString(this, pattern)
}

fun Date?.toDateTimeStandardConcise(): String {
val pattern = "dd MMM yyyy HH:mm:ss"
return dateAsString(this, pattern)
}

fun Date?.toDateTimeStandardConciseIn12Hours(): String {
val pattern = "dd MMM yyyy h:mm:ss a"
return dateAsString(this, pattern)
}

fun Date?.toDateTimeYY(): String {
val pattern = "dd MMMM yy HH:mm:ss"
return dateAsString(this, pattern)
}

fun Date?.toDateTimeYYIn12Hours(): String {
val pattern = "dd MMMM yy h:mm:ss a"
return dateAsString(this, pattern)
}

fun Date?.toDateTimeYYInDigits(): String {
val pattern = "dd-MM-yy HH:mm:ss"
return dateAsString(this, pattern)
}

fun Date?.toDateTimeYYInDigitsAnd12Hours(): String {
val pattern = "dd-MM-yy h:mm:ss a"
return dateAsString(this, pattern)
}

fun Date?.toDateTimeYYConcise(): String {
val pattern = "dd MMM yy HH:mm:ss"
return dateAsString(this, pattern)
}

fun Date?.toDateTimeYYConciseIn12Hours(): String {
val pattern = "dd MMM yy h:mm:ss a"
return dateAsString(this, pattern)
}

fun Date?.toZuluFormat(): String {
val pattern = "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'"
return dateAsString(this, pattern)
}
11 changes: 11 additions & 0 deletions simpledate/src/main/kotlin/com/parassidhu/simpledate/Day.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
@file:JvmMultifileClass
@file:JvmName("SimpleDate")

package com.parassidhu.simpledate

import java.util.*

fun Date?.toDay(): String {
val pattern = "EEEE"
return dateAsString(this, pattern)
}
17 changes: 17 additions & 0 deletions simpledate/src/main/kotlin/com/parassidhu/simpledate/SimpleDate.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
@file:JvmMultifileClass
@file:JvmName("SimpleDate")

package com.parassidhu.simpledate

import java.text.SimpleDateFormat
import java.util.*

private lateinit var simpleDateFormat: SimpleDateFormat

internal fun dateAsString(date: Date?, pattern: String): String {
simpleDateFormat = SimpleDateFormat(pattern, Locale.getDefault())
if (date != null)
return simpleDateFormat.format(date)
else
throw NullPointerException("Date can't be null")
}
Loading