Last active
May 26, 2023 13:39
-
-
Save AkshayChordiya/b1c9788d24e62d92e3e20778288e64a8 to your computer and use it in GitHub Desktop.
Revisions
-
AkshayChordiya revised this gist
Jan 24, 2018 . 2 changed files with 38 additions and 2 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -1,3 +1,5 @@ import org.joda.time.LocalDate /** * @return true if the supplied date is in the future else false */ @@ -30,12 +32,12 @@ fun isYesterday(millis: Long): Boolean { * @return true if the supplied when is this week else false */ fun isThisWeek(millis: Long): Boolean { return LocalDate.now().minusWeeks(1) <= LocalDate(millis) } /** * @return true if the supplied when is this month else false */ fun isThisMonth(millis: Long): Boolean { return LocalDate.now().minusMonths(1) <= LocalDate(millis) } 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,34 @@ import org.junit.Assert.assertEquals import org.junit.Test import org.junit.runner.RunWith import org.junit.runners.JUnit4 @RunWith(JUnit4::class) class TimeHelperTest { @Test fun isTodayTest() { // 21/01/2018 : 14:22 assertEquals(true, isToday(1516524740355)) } @Test fun isYesterdayTest() { // 20/01/2018 : 20:00 assertEquals(true, isYesterday(1516458600000)) } @Test fun isThisWeekTest() { // 18/01/2018 : 20:00 assertEquals(true, isThisWeek(1516285800000)) } @Test fun isThisMonthTest() { // 11/01/2018 : 20:00 assertEquals(true, isThisMonth(1515681000000)) } } -
AkshayChordiya revised this gist
Jan 10, 2018 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -8,5 +8,5 @@ or older to show sections in [my app](play.google.com/store/apps/details?id=com. PS: I used [SectionedRecyclerView](https://github.com/afollestad/sectioned-recyclerview) library to show sections in my app. Dependency: - [Joda-time](https://github.com/dlew/joda-time-android) -
AkshayChordiya revised this gist
Jan 10, 2018 . 1 changed file with 4 additions and 1 deletion.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -6,4 +6,7 @@ There are several apps which show a list with sections like "Today", "Yesterday" I wrote few top-level functions which are helpful to check if the date is upcoming, tomorrow, today, yesterday, this month, this week or older to show sections in [my app](play.google.com/store/apps/details?id=com.bitfurther.notigo.student) PS: I used [SectionedRecyclerView](https://github.com/afollestad/sectioned-recyclerview) library to show sections in my app. Dependecy: - [Joda-time](https://github.com/dlew/joda-time-android) -
AkshayChordiya revised this gist
Jan 10, 2018 . 1 changed file with 3 additions and 3 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -1,9 +1,9 @@ # Date header top-level Kotlin functions There are several apps which show a list with sections like "Today", "Yesterday" and so on like [Inbox Android app](https://lh3.googleusercontent.com/Oz13JGyH0H2XBd_sflttWnAK_LRafyHW_P59Wfc4kqasiAMLhHLyZgKBTz2MpwZbJg=h900-rw) I wrote few top-level functions which are helpful to check if the date is upcoming, tomorrow, today, yesterday, this month, this week or older to show sections in [my app](play.google.com/store/apps/details?id=com.bitfurther.notigo.student) PS: I used [SectionedRecyclerView](https://github.com/afollestad/sectioned-recyclerview) library to show sections in my app. -
AkshayChordiya created this gist
Jan 10, 2018 .There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,41 @@ /** * @return true if the supplied date is in the future else false */ fun isUpcoming(millis: Long): Boolean { return !isTomorrow(millis) && LocalDate(millis).isAfter(LocalDate.now()) } /** * @return true if the supplied date is tomorrow else false */ fun isTomorrow(millis: Long): Boolean { return LocalDate.now().plusDays(1).compareTo(LocalDate(millis)) == 0 } /** * @return true if the supplied date is today else false */ fun isToday(millis: Long): Boolean { return LocalDate.now().compareTo(LocalDate(millis)) == 0 } /** * @return true if the supplied when is yesterday else false */ fun isYesterday(millis: Long): Boolean { return LocalDate.now().minusDays(1).compareTo(LocalDate(millis)) == 0 } /** * @return true if the supplied when is this week else false */ fun isThisWeek(millis: Long): Boolean { return LocalDate.now().minusWeeks(1).compareTo(LocalDate(millis)) == 0 } /** * @return true if the supplied when is this month else false */ fun isThisMonth(millis: Long): Boolean { return LocalDate.now().minusMonths(1).compareTo(LocalDate(millis)) == 0 } 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,9 @@ # Date header top-level Kotlin functions There are several apps which show a list with sections like "Today", "Yesterday" and so on like (Inbox Android app)[https://lh3.googleusercontent.com/Oz13JGyH0H2XBd_sflttWnAK_LRafyHW_P59Wfc4kqasiAMLhHLyZgKBTz2MpwZbJg=h900-rw] I wrote few top-level functions which are helpful to check if the date is upcoming, tomorrow, today, yesterday, this month, this week or older to show sections in (my app)[play.google.com/store/apps/details?id=com.bitfurther.notigo.student] PS: I used (SectionedRecyclerView)[https://github.com/afollestad/sectioned-recyclerview] library to show sections in my app. 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,12 @@ // Example usage when { isUpcoming(time) -> {} isTomorrow(time) -> {} isToday(time) -> {} isYesterday(time) -> {} isThisWeek(time) -> {} isThisMonth(time) -> {} else -> { // Else branch means the date is older } }