Skip to content

Commit

Permalink
added more extension for date and time
Browse files Browse the repository at this point in the history
  • Loading branch information
02gaurav committed Sep 8, 2024
1 parent ca53548 commit c45f89a
Show file tree
Hide file tree
Showing 5 changed files with 373 additions and 8 deletions.
1 change: 1 addition & 0 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -67,4 +67,5 @@ dependencies {
androidTestImplementation(libs.androidx.ui.test.junit4)
debugImplementation(libs.androidx.ui.tooling)
debugImplementation(libs.androidx.ui.test.manifest)
// implementation ("com.github.02gaurav:DateExtension:v1.0.0")
}
127 changes: 122 additions & 5 deletions app/src/main/java/com/gaurav/dateextension/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,30 @@ import android.os.Bundle
import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
import androidx.activity.enableEdgeToEdge
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.material3.Scaffold
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.tooling.preview.Preview
import com.gaurav.date_extensions.changeToDateFormat
import com.gaurav.date_extensions.getDayWithSuffix
import com.gaurav.date_extensions.getHourMinFormatString
import com.gaurav.date_extensions.getTime
import com.gaurav.date_extensions.getTimeInString
import com.gaurav.date_extensions.isDateLastMinuteOrBefore
import com.gaurav.date_extensions.isDateThisWeek
import com.gaurav.date_extensions.isDateToday
import com.gaurav.date_extensions.isDateYesterday
import com.gaurav.date_extensions.isDateYesterdayOrBefore
import com.gaurav.date_extensions.isMoreThanSevenDays
import com.gaurav.date_extensions.parseRemainingTimeDifference
import com.gaurav.date_extensions.parseTimeDifference
import com.gaurav.date_extensions.parseTimeTo_dd_MMM
import com.gaurav.date_extensions.timeDayOfWeek
import com.gaurav.dateextension.ui.theme.DateExtensionTheme

class MainActivity : ComponentActivity() {
Expand All @@ -33,12 +49,113 @@ class MainActivity : ComponentActivity() {

@Composable
fun Greeting(name: String, modifier: Modifier = Modifier) {
val currentTime = System.currentTimeMillis()
val currentTime = System.currentTimeMillis() - 1000*60*24
val currentTime1 = System.currentTimeMillis()
Text(
text = "Hello $name! ${currentTime1.changeToDateFormat("yyyy-MM-dd")}",
modifier = modifier
)
val currentTime2 = System.currentTimeMillis()- 1000*60*24*12
val currentTime3 = System.currentTimeMillis()- 1000*60*60*24*8
LazyColumn {
item {
Text(
text = "Date format ${
(1694157381L).changeToDateFormat(
true,
"yyyy-MM-dd HH:mm:ss"
)
}",
modifier = modifier
)
}
item {
Text(
text = "Time diff ${(currentTime1-currentTime).parseTimeDifference()}",
modifier = modifier
)
}
item {
Text(
text = "Rem time diff ${(currentTime1-currentTime2).parseRemainingTimeDifference()}",
modifier = modifier
)
}
item {
Text(
text = "Is today ${currentTime1.isDateToday()}",
modifier = modifier
)
}
item {
Text(
text = "Is Yesterday ${currentTime2.isDateYesterday()}",
modifier = modifier
)
}
item {
Text(
text = "Get Time ${currentTime1.getTime()}",
modifier = modifier
)
}
item {
Text(
text = "Yesterday or before ${currentTime1.isDateYesterdayOrBefore()}",
modifier = modifier
)
}
item {
Text(
text = "Last min or before ${currentTime1.isDateLastMinuteOrBefore()}",
modifier = modifier
)
}
item {
Text(
text = "parseTimeTo_dd_MMM = ${(1694157381L).parseTimeTo_dd_MMM(true)}",
modifier = modifier
)
}
item {
Text(
text = "timeDayOfWeek${currentTime1.timeDayOfWeek()}",
modifier = modifier
)
}
item {

Text(
text = "isMoreThanSevenDays ${currentTime3.isMoreThanSevenDays()}",
modifier = modifier
)
}
item {
Text(
text = "isDateThisWeek ${currentTime2.isDateThisWeek()}",
modifier = modifier
)
}
item {
Text(
text = "getTimeInString ${(127L).getTimeInString()}",
modifier = modifier
)
}
item {

Text(
text = "getHourMinFormatString ${currentTime1.getHourMinFormatString()}",
modifier = modifier
)
}
item {

Text(
text = "getDayWithSuffix ${currentTime3.getDayWithSuffix()}",
modifier = modifier
)
}

//parseTimeTo_dd_MMM
}

}

@Preview(showBackground = true)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
package com.gaurav.date_extensions

data class CustomDate(val days: Long, val hours: Long, val minutes: Long, val seconds: Long)
Loading

0 comments on commit c45f89a

Please sign in to comment.