kandi background
Explore Kits

ThreeTenABP | An adaptation of the JSR310 backport for Android.

 by   JakeWharton Java Version: Current License: Apache-2.0

 by   JakeWharton Java Version: Current License: Apache-2.0

Download this library from

kandi X-RAY | ThreeTenABP Summary

ThreeTenABP is a Java library. ThreeTenABP has no bugs, it has no vulnerabilities, it has build file available, it has a Permissive License and it has medium support. You can download it from GitHub.
An adaptation of the JSR-310 backport for Android. Attention: Development on this library is winding down. Please consider switching to Android Gradle plugin 4.0, java.time.*, and its [core library desugaring](https://developer.android.com/studio/write/java8-support#library-desugaring) feature in the coming months.
Support
Support
Quality
Quality
Security
Security
License
License
Reuse
Reuse

kandi-support Support

  • ThreeTenABP has a medium active ecosystem.
  • It has 3450 star(s) with 131 fork(s). There are 62 watchers for this library.
  • It had no major release in the last 12 months.
  • There are 4 open issues and 80 have been closed. On average issues are closed in 157 days. There are no pull requests.
  • It has a neutral sentiment in the developer community.
  • The latest version of ThreeTenABP is current.
ThreeTenABP Support
Best in #Java
Average in #Java
ThreeTenABP Support
Best in #Java
Average in #Java

quality kandi Quality

  • ThreeTenABP has 0 bugs and 0 code smells.
ThreeTenABP Quality
Best in #Java
Average in #Java
ThreeTenABP Quality
Best in #Java
Average in #Java

securitySecurity

  • ThreeTenABP has no vulnerabilities reported, and its dependent libraries have no vulnerabilities reported.
  • ThreeTenABP code analysis shows 0 unresolved vulnerabilities.
  • There are 0 security hotspots that need review.
ThreeTenABP Security
Best in #Java
Average in #Java
ThreeTenABP Security
Best in #Java
Average in #Java

license License

  • ThreeTenABP is licensed under the Apache-2.0 License. This license is Permissive.
  • Permissive licenses have the least restrictions, and you can use them in most projects.
ThreeTenABP License
Best in #Java
Average in #Java
ThreeTenABP License
Best in #Java
Average in #Java

buildReuse

  • ThreeTenABP releases are not available. You will need to build from source code and install.
  • Build file is available. You can build the component from source.
  • Installation instructions, examples and code snippets are available.
  • It has 186 lines of code, 16 functions and 9 files.
  • It has low code complexity. Code complexity directly impacts maintainability of the code.
ThreeTenABP Reuse
Best in #Java
Average in #Java
ThreeTenABP Reuse
Best in #Java
Average in #Java
Top functions reviewed by kandi - BETA

kandi has reviewed ThreeTenABP and discovered the below as its top functions. This is intended to give you an instant insight into ThreeTenABP implemented functionality, and help decide if they suit your requirements.

  • Registers the provider .
  • Creates the text view .
  • Initializes the ZoneRules initializer .
  • Returns the current time .
  • Convenience method to format a date and time .

ThreeTenABP Key Features

An adaptation of the JSR-310 backport for Android.

Usage

copy iconCopydownload iconDownload
@Override public void onCreate() {
  super.onCreate();
  AndroidThreeTen.init(this);
}

Download

copy iconCopydownload iconDownload
implementation 'com.jakewharton.threetenabp:threetenabp:1.3.1'

License

copy iconCopydownload iconDownload
Copyright (C) 2015 Jake Wharton

InvocationTargetException with Android Studio Arctic Fox on M1 Apple silicon

copy iconCopydownload iconDownload
kotlinVersion = '1.4.20'
nstack_version = '3.2.8'

// Library versions
dagger_version = '2.29.1'
leak_canary_version = '1.6.3'
okhttp_version = '4.9.0'
moshi_version = '1.11.0'
retrofit_version = '2.9.0'
lifecycle_version = "2.2.0"
room_version = '2.4.0-alpha04'
work_version = '2.4.0'
navigation_version = '2.3.1'
glide_version = '4.11.0'
billing_version = '3.0.1'
coroutines_version = '1.4.3'
exoplayer_version = '2.14.0'

Could not find android.arch.navigation:navigation-safe-args-gradle-plugin:2.3.5.?

copy iconCopydownload iconDownload
classpath "androidx.navigation:navigation-safe-args-gradle-plugin:$version_navigation"
// Navigation
implementation "androidx.navigation:navigation-fragment-ktx:$version_navigation"
implementation "androidx.navigation:navigation-ui-ktx:$version_navigation"
-----------------------
classpath "androidx.navigation:navigation-safe-args-gradle-plugin:$version_navigation"
// Navigation
implementation "androidx.navigation:navigation-fragment-ktx:$version_navigation"
implementation "androidx.navigation:navigation-ui-ktx:$version_navigation"

Cannot resolve external dependency com.android.tools:desugar_jdk_libs:1.0.9 because no repositories are defined

copy iconCopydownload iconDownload
allprojects {
    repositories {
        google()
        mavenCentral()
    }
}
dependencyResolutionManagement {
    repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
    repositories {
        google()
        mavenCentral()
    }
}
-----------------------
allprojects {
    repositories {
        google()
        mavenCentral()
    }
}
dependencyResolutionManagement {
    repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
    repositories {
        google()
        mavenCentral()
    }
}

date and time show parse error at specific index

copy iconCopydownload iconDownload
    String dates = "2021-03-05 09:18:07";
    DateTimeFormatter formatter 
            = DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ss", Locale.ROOT);
    
    OffsetDateTime expectedResult
            = OffsetDateTime.of(2021, 3, 5, 9, 18, 7, 0, ZoneOffset.ofHours(1));
    
    System.out.println("Parsing:   " + dates);
    System.out.println("Formatted: " + expectedResult.format(formatter));
Parsing:   2021-03-05 09:18:07
Formatted: 2021-03-05T09:18:07
    // Put a space in the format pattern string
    DateTimeFormatter formatter 
            = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss", Locale.ROOT);
    
    OffsetDateTime odt = OffsetDateTime.parse(dates, formatter);
    ZoneId zoneAssumedByApi = ZoneId.of("Antarctica/Troll");
    long  timeInMilliseconds = LocalDateTime.parse(dates, formatter)
            .atZone(zoneAssumedByApi)
            .toInstant()
            .toEpochMilli();
    System.out.println("Date in milli :: USING ThreeTenABP >>> "
            + timeInMilliseconds);
-----------------------
    String dates = "2021-03-05 09:18:07";
    DateTimeFormatter formatter 
            = DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ss", Locale.ROOT);
    
    OffsetDateTime expectedResult
            = OffsetDateTime.of(2021, 3, 5, 9, 18, 7, 0, ZoneOffset.ofHours(1));
    
    System.out.println("Parsing:   " + dates);
    System.out.println("Formatted: " + expectedResult.format(formatter));
Parsing:   2021-03-05 09:18:07
Formatted: 2021-03-05T09:18:07
    // Put a space in the format pattern string
    DateTimeFormatter formatter 
            = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss", Locale.ROOT);
    
    OffsetDateTime odt = OffsetDateTime.parse(dates, formatter);
    ZoneId zoneAssumedByApi = ZoneId.of("Antarctica/Troll");
    long  timeInMilliseconds = LocalDateTime.parse(dates, formatter)
            .atZone(zoneAssumedByApi)
            .toInstant()
            .toEpochMilli();
    System.out.println("Date in milli :: USING ThreeTenABP >>> "
            + timeInMilliseconds);
-----------------------
    String dates = "2021-03-05 09:18:07";
    DateTimeFormatter formatter 
            = DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ss", Locale.ROOT);
    
    OffsetDateTime expectedResult
            = OffsetDateTime.of(2021, 3, 5, 9, 18, 7, 0, ZoneOffset.ofHours(1));
    
    System.out.println("Parsing:   " + dates);
    System.out.println("Formatted: " + expectedResult.format(formatter));
Parsing:   2021-03-05 09:18:07
Formatted: 2021-03-05T09:18:07
    // Put a space in the format pattern string
    DateTimeFormatter formatter 
            = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss", Locale.ROOT);
    
    OffsetDateTime odt = OffsetDateTime.parse(dates, formatter);
    ZoneId zoneAssumedByApi = ZoneId.of("Antarctica/Troll");
    long  timeInMilliseconds = LocalDateTime.parse(dates, formatter)
            .atZone(zoneAssumedByApi)
            .toInstant()
            .toEpochMilli();
    System.out.println("Date in milli :: USING ThreeTenABP >>> "
            + timeInMilliseconds);
-----------------------
    String dates = "2021-03-05 09:18:07";
    DateTimeFormatter formatter 
            = DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ss", Locale.ROOT);
    
    OffsetDateTime expectedResult
            = OffsetDateTime.of(2021, 3, 5, 9, 18, 7, 0, ZoneOffset.ofHours(1));
    
    System.out.println("Parsing:   " + dates);
    System.out.println("Formatted: " + expectedResult.format(formatter));
Parsing:   2021-03-05 09:18:07
Formatted: 2021-03-05T09:18:07
    // Put a space in the format pattern string
    DateTimeFormatter formatter 
            = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss", Locale.ROOT);
    
    OffsetDateTime odt = OffsetDateTime.parse(dates, formatter);
    ZoneId zoneAssumedByApi = ZoneId.of("Antarctica/Troll");
    long  timeInMilliseconds = LocalDateTime.parse(dates, formatter)
            .atZone(zoneAssumedByApi)
            .toInstant()
            .toEpochMilli();
    System.out.println("Date in milli :: USING ThreeTenABP >>> "
            + timeInMilliseconds);
-----------------------
import java.time.OffsetDateTime;
import java.time.ZoneOffset;
import java.time.format.DateTimeFormatter;
import java.util.Locale;

public class Main {
    public static void main(String[] args) {
        String strDateTime = "2021-03-05 09:18:07";
        
        DateTimeFormatter formatter = DateTimeFormatter
                                        .ofPattern("uuuu-MM-dd HH:mm:ss", Locale.ENGLISH)
                                        .withZone(ZoneOffset.UTC);
        
        long millis = OffsetDateTime
                        .parse(strDateTime, formatter)
                        .toInstant()
                        .toEpochMilli();
        
        System.out.println(millis);
    }
}
1614935887000
import java.util.Locale;

import org.threeten.bp.LocalDateTime;
import org.threeten.bp.ZoneOffset;
import org.threeten.bp.format.DateTimeFormatter;

public class Main {
    public static void main(String[] args) {
        String strDateTime = "2021-03-05 09:18:07";
        
        DateTimeFormatter formatter = DateTimeFormatter
                                        .ofPattern("uuuu-MM-dd HH:mm:ss", Locale.ENGLISH);
        
        long millis = LocalDateTime
                        .parse(strDateTime, formatter)
                        .toInstant(ZoneOffset.UTC)
                        .toEpochMilli();
        
        System.out.println(millis);
    }
}
1614935887000
-----------------------
import java.time.OffsetDateTime;
import java.time.ZoneOffset;
import java.time.format.DateTimeFormatter;
import java.util.Locale;

public class Main {
    public static void main(String[] args) {
        String strDateTime = "2021-03-05 09:18:07";
        
        DateTimeFormatter formatter = DateTimeFormatter
                                        .ofPattern("uuuu-MM-dd HH:mm:ss", Locale.ENGLISH)
                                        .withZone(ZoneOffset.UTC);
        
        long millis = OffsetDateTime
                        .parse(strDateTime, formatter)
                        .toInstant()
                        .toEpochMilli();
        
        System.out.println(millis);
    }
}
1614935887000
import java.util.Locale;

import org.threeten.bp.LocalDateTime;
import org.threeten.bp.ZoneOffset;
import org.threeten.bp.format.DateTimeFormatter;

public class Main {
    public static void main(String[] args) {
        String strDateTime = "2021-03-05 09:18:07";
        
        DateTimeFormatter formatter = DateTimeFormatter
                                        .ofPattern("uuuu-MM-dd HH:mm:ss", Locale.ENGLISH);
        
        long millis = LocalDateTime
                        .parse(strDateTime, formatter)
                        .toInstant(ZoneOffset.UTC)
                        .toEpochMilli();
        
        System.out.println(millis);
    }
}
1614935887000
-----------------------
import java.time.OffsetDateTime;
import java.time.ZoneOffset;
import java.time.format.DateTimeFormatter;
import java.util.Locale;

public class Main {
    public static void main(String[] args) {
        String strDateTime = "2021-03-05 09:18:07";
        
        DateTimeFormatter formatter = DateTimeFormatter
                                        .ofPattern("uuuu-MM-dd HH:mm:ss", Locale.ENGLISH)
                                        .withZone(ZoneOffset.UTC);
        
        long millis = OffsetDateTime
                        .parse(strDateTime, formatter)
                        .toInstant()
                        .toEpochMilli();
        
        System.out.println(millis);
    }
}
1614935887000
import java.util.Locale;

import org.threeten.bp.LocalDateTime;
import org.threeten.bp.ZoneOffset;
import org.threeten.bp.format.DateTimeFormatter;

public class Main {
    public static void main(String[] args) {
        String strDateTime = "2021-03-05 09:18:07";
        
        DateTimeFormatter formatter = DateTimeFormatter
                                        .ofPattern("uuuu-MM-dd HH:mm:ss", Locale.ENGLISH);
        
        long millis = LocalDateTime
                        .parse(strDateTime, formatter)
                        .toInstant(ZoneOffset.UTC)
                        .toEpochMilli();
        
        System.out.println(millis);
    }
}
1614935887000
-----------------------
import java.time.OffsetDateTime;
import java.time.ZoneOffset;
import java.time.format.DateTimeFormatter;
import java.util.Locale;

public class Main {
    public static void main(String[] args) {
        String strDateTime = "2021-03-05 09:18:07";
        
        DateTimeFormatter formatter = DateTimeFormatter
                                        .ofPattern("uuuu-MM-dd HH:mm:ss", Locale.ENGLISH)
                                        .withZone(ZoneOffset.UTC);
        
        long millis = OffsetDateTime
                        .parse(strDateTime, formatter)
                        .toInstant()
                        .toEpochMilli();
        
        System.out.println(millis);
    }
}
1614935887000
import java.util.Locale;

import org.threeten.bp.LocalDateTime;
import org.threeten.bp.ZoneOffset;
import org.threeten.bp.format.DateTimeFormatter;

public class Main {
    public static void main(String[] args) {
        String strDateTime = "2021-03-05 09:18:07";
        
        DateTimeFormatter formatter = DateTimeFormatter
                                        .ofPattern("uuuu-MM-dd HH:mm:ss", Locale.ENGLISH);
        
        long millis = LocalDateTime
                        .parse(strDateTime, formatter)
                        .toInstant(ZoneOffset.UTC)
                        .toEpochMilli();
        
        System.out.println(millis);
    }
}
1614935887000

ThreeTenABP DateTime parser giving exception for yyyy-MM-ddTHH:mm:ss formate

copy iconCopydownload iconDownload
fun main() {
    // example String
    val givenDateString = "2020-09-22T20:35:00"
    // determine the zone id of the device (you can alternatively set a fix one here)
    val localZoneId: ZoneId = ZoneId.systemDefault()
    // parse the String to a LocalDateTime
    val localDateTime = LocalDateTime.parse(givenDateString)
    // then create a ZonedDateTime by adding the zone id and convert it to an OffsetDateTime
    val odt: OffsetDateTime = localDateTime.atZone(zoneId).toOffsetDateTime()
    // get the time in epoch milliseconds
    val timeInMillis = odt.toInstant().toEpochMilli()
    // and print it
    println("$odt ==> $timeInMillis")
}
2020-09-22T20:35Z ==> 1600806900000
-----------------------
fun main() {
    // example String
    val givenDateString = "2020-09-22T20:35:00"
    // determine the zone id of the device (you can alternatively set a fix one here)
    val localZoneId: ZoneId = ZoneId.systemDefault()
    // parse the String to a LocalDateTime
    val localDateTime = LocalDateTime.parse(givenDateString)
    // then create a ZonedDateTime by adding the zone id and convert it to an OffsetDateTime
    val odt: OffsetDateTime = localDateTime.atZone(zoneId).toOffsetDateTime()
    // get the time in epoch milliseconds
    val timeInMillis = odt.toInstant().toEpochMilli()
    // and print it
    println("$odt ==> $timeInMillis")
}
2020-09-22T20:35Z ==> 1600806900000

Android error "org.threeten.bp.temporal.UnsupportedTemporalTypeException: Unsupported unit: Seconds"

copy iconCopydownload iconDownload
import java.time.Instant;
import java.time.temporal.ChronoUnit;

public class Main {
    public static void main(String[] args) {
        // Test
        System.out.println(secondsBetween("2020-07-23T00:00:00.000Z", "2020-07-23T00:10:20.000Z"));
    }

    public static long secondsBetween(String startDateTime, String endDateTime) {
        return ChronoUnit.SECONDS.between(Instant.parse(startDateTime), Instant.parse(endDateTime));
    }
}
620
-----------------------
import java.time.Instant;
import java.time.temporal.ChronoUnit;

public class Main {
    public static void main(String[] args) {
        // Test
        System.out.println(secondsBetween("2020-07-23T00:00:00.000Z", "2020-07-23T00:10:20.000Z"));
    }

    public static long secondsBetween(String startDateTime, String endDateTime) {
        return ChronoUnit.SECONDS.between(Instant.parse(startDateTime), Instant.parse(endDateTime));
    }
}
620

Android Crashlytics - Unable to upload symbols

copy iconCopydownload iconDownload
[DEBUG] (Execution worker for ':' Thread 6) com.crashlytics  - Manifest and properties apiKey is empty. Looking for google_app_id
[DEBUG] (Execution worker for ':' Thread 6) com.crashlytics  - Google-services res dir: /Users/xxx/AndroidStudioProjects/Looper/app/build/generated/res/google-services/release/values/values.xml
[DEBUG] (Execution worker for ':' Thread 6) com.crashlytics  - Found google_app_id: 1:12341234123:android:34h43h2k423342kb
[DEBUG] (Execution worker for ':' Thread 6) com.crashlytics  - apiKey is 123412341234fdsfds12312321321dsfsd
[DEBUG] (Execution worker for ':' Thread 6) com.crashlytics  - Crashlytics attempting to upload cSYM files.
[DEBUG] (Execution worker for ':' Thread 6) com.crashlytics  - POST file: /Users/xxx/Library/Caches/com.crashlytics/com.crashlytics.tools/app-afdsfdsfdsfds/release/csyms/superpowered-aarch64-b4jk32bkl2b5b4b543.cSYM.gz to URL: https://cm.crashlytics.com/api/v3/platforms/android/code_mappings
[DEBUG] (Execution worker for ':' Thread 6) com.crashlytics  - POST response: [reqId= 123412341234fdsfds12312321321dsfsd] 202
[DEBUG] (Execution worker for ':' Thread 6) com.crashlytics  - POST file: /Users/xxx/Library/Caches/com.crashlytics/com.crashlytics.tools/app-af3ed5c17e31fe86dd60a032b9674cb18b65334d/release/csyms/superpowered-x86_64-123412341234fdsfds12312321321dsfsd.cSYM.gz to URL: https://cm.crashlytics.com/api/v3/platforms/android/code_mappings
[DEBUG] (Execution worker for ':' Thread 6) com.crashlytics  - POST response: [reqId=123412341234fdsfds12312321321dsfsd] 202
[DEBUG] (Execution worker for ':' Thread 6) com.crashlytics  - POST file: /Users/xxx/Library/Caches/com.crashlytics/com.crashlytics.tools/app-af3ed5c17e31fe86dd60a032b9674cb18b65334d/release/csyms/superpowered-x86-123412341234fdsfds12312321321dsfsd.cSYM.gz to URL: https://cm.crashlytics.com/api/v3/platforms/android/code_mappings
[DEBUG] (Execution worker for ':' Thread 6) com.crashlytics  - POST response: [reqId=123412341234fdsfds12312321321dsfsd] 202
[DEBUG] (Execution worker for ':' Thread 6) com.crashlytics  - POST file: /Users/xxx/Library/Caches/com.crashlytics/com.crashlytics.tools/app-123412341234fdsfds12312321321dsfsd/release/csyms/superpowered-armv7-123412341234fdsfds12312321321dsfsd to URL: https://cm.crashlytics.com/api/v3/platforms/android/code_mappings
[DEBUG] (Execution worker for ':' Thread 6) com.crashlytics  - POST response: [reqId=123412341234fdsfds12312321321dsfsd] 202
[DEBUG] (Execution worker for ':' Thread 6) com.crashlytics  - cSYM file(s) uploaded.
android.bundle.enableUncompressedNativeLibs=false
-----------------------
[DEBUG] (Execution worker for ':' Thread 6) com.crashlytics  - Manifest and properties apiKey is empty. Looking for google_app_id
[DEBUG] (Execution worker for ':' Thread 6) com.crashlytics  - Google-services res dir: /Users/xxx/AndroidStudioProjects/Looper/app/build/generated/res/google-services/release/values/values.xml
[DEBUG] (Execution worker for ':' Thread 6) com.crashlytics  - Found google_app_id: 1:12341234123:android:34h43h2k423342kb
[DEBUG] (Execution worker for ':' Thread 6) com.crashlytics  - apiKey is 123412341234fdsfds12312321321dsfsd
[DEBUG] (Execution worker for ':' Thread 6) com.crashlytics  - Crashlytics attempting to upload cSYM files.
[DEBUG] (Execution worker for ':' Thread 6) com.crashlytics  - POST file: /Users/xxx/Library/Caches/com.crashlytics/com.crashlytics.tools/app-afdsfdsfdsfds/release/csyms/superpowered-aarch64-b4jk32bkl2b5b4b543.cSYM.gz to URL: https://cm.crashlytics.com/api/v3/platforms/android/code_mappings
[DEBUG] (Execution worker for ':' Thread 6) com.crashlytics  - POST response: [reqId= 123412341234fdsfds12312321321dsfsd] 202
[DEBUG] (Execution worker for ':' Thread 6) com.crashlytics  - POST file: /Users/xxx/Library/Caches/com.crashlytics/com.crashlytics.tools/app-af3ed5c17e31fe86dd60a032b9674cb18b65334d/release/csyms/superpowered-x86_64-123412341234fdsfds12312321321dsfsd.cSYM.gz to URL: https://cm.crashlytics.com/api/v3/platforms/android/code_mappings
[DEBUG] (Execution worker for ':' Thread 6) com.crashlytics  - POST response: [reqId=123412341234fdsfds12312321321dsfsd] 202
[DEBUG] (Execution worker for ':' Thread 6) com.crashlytics  - POST file: /Users/xxx/Library/Caches/com.crashlytics/com.crashlytics.tools/app-af3ed5c17e31fe86dd60a032b9674cb18b65334d/release/csyms/superpowered-x86-123412341234fdsfds12312321321dsfsd.cSYM.gz to URL: https://cm.crashlytics.com/api/v3/platforms/android/code_mappings
[DEBUG] (Execution worker for ':' Thread 6) com.crashlytics  - POST response: [reqId=123412341234fdsfds12312321321dsfsd] 202
[DEBUG] (Execution worker for ':' Thread 6) com.crashlytics  - POST file: /Users/xxx/Library/Caches/com.crashlytics/com.crashlytics.tools/app-123412341234fdsfds12312321321dsfsd/release/csyms/superpowered-armv7-123412341234fdsfds12312321321dsfsd to URL: https://cm.crashlytics.com/api/v3/platforms/android/code_mappings
[DEBUG] (Execution worker for ':' Thread 6) com.crashlytics  - POST response: [reqId=123412341234fdsfds12312321321dsfsd] 202
[DEBUG] (Execution worker for ':' Thread 6) com.crashlytics  - cSYM file(s) uploaded.
android.bundle.enableUncompressedNativeLibs=false

Format remaining time untill date

copy iconCopydownload iconDownload
    val futureDate = LocalDate.of(2020,2,20)
    val todayDate = LocalDate.now()
    val remainingYears = futureDate.year - todayDate.year //output 0
    val remainingMonth = futureDate.monthValue - todayDate.monthValue //output 0
    val remainingDays = futureDate.dayOfMonth - todayDate.dayOfMonth // output 16
-----------------------
private fun getMillisFromNow(futureTime: Date): Long {
    val futureTimeMillis = futureTime.time
    val nowMillis = System.currentTimeMillis()
    return futureTimeMillis - nowMillis
}
 fun format(timestamp: Date): String {
    val millisFromNow = getMillisFromNow(timestamp)

    val minutesFromNow = TimeUnit.MILLISECONDS.toMinutes(millisFromNow)
    if (minutesFromNow < 1) {
        return "about now"
    }
    val hoursFromNow = TimeUnit.MILLISECONDS.toHours(millisFromNow)
    if (hoursFromNow < 1) {
        return formatMinutes(minutesFromNow)
    }
    val daysFromNow = TimeUnit.MILLISECONDS.toDays(millisFromNow)
    if (daysFromNow < 1) {
        return formatHours(hoursFromNow)
    }
    val weeksFromNow = TimeUnit.MILLISECONDS.toDays(millisFromNow) / 7
    if (weeksFromNow < 1) {
        return formatDays(daysFromNow)
    }
    val monthsFromNow = TimeUnit.MILLISECONDS.toDays(millisFromNow) / 30
    if (monthsFromNow < 1) {
        return formatWeeks(weeksFromNow)
    }
    val yearsFromNow = TimeUnit.MILLISECONDS.toDays(millisFromNow) / 365
    return if (yearsFromNow < 1) {
        formatMonths(monthsFromNow)
    } else formatYears(yearsFromNow)
}

 private fun getMillisFromNow(futureTime: Date): Long {
    val futureTimeMillis = futureTime.time
    val nowMillis = System.currentTimeMillis()
    return futureTimeMillis - nowMillis
}

private fun formatMinutes(minutes: Long): String {
    return format(minutes, " minute to go", " minutes to go")
}

private fun formatHours(hours: Long): String {
    return format(hours, " hour to go", " hours to go")
}

private fun formatDays(days: Long): String {
    return format(days, " day to go", " days to go")
}

private fun formatWeeks(weeks: Long): String {
    return format(weeks, " week to go", " weeks to go")
}

private fun formatMonths(months: Long): String {
    return format(months, " month to go", " months to go")
}

private fun formatYears(years: Long): String {
    return format(years, " year to go", " years to go")
}

private fun format(hand: Long, singular: String, plural: String): String {
    return if (hand == 1L) {
        hand.toString() + singular
    } else {
        hand.toString() + plural
    }
}
@Test
fun test() {
    val twoDaysInMillisInstant = Instant.now().plusMillis(TimeUnit.HOURS.toMillis(50))
    val result = format(Date.from(twoDaysInMillisInstant))

    assertEquals("2 days to go", result)
}
-----------------------
private fun getMillisFromNow(futureTime: Date): Long {
    val futureTimeMillis = futureTime.time
    val nowMillis = System.currentTimeMillis()
    return futureTimeMillis - nowMillis
}
 fun format(timestamp: Date): String {
    val millisFromNow = getMillisFromNow(timestamp)

    val minutesFromNow = TimeUnit.MILLISECONDS.toMinutes(millisFromNow)
    if (minutesFromNow < 1) {
        return "about now"
    }
    val hoursFromNow = TimeUnit.MILLISECONDS.toHours(millisFromNow)
    if (hoursFromNow < 1) {
        return formatMinutes(minutesFromNow)
    }
    val daysFromNow = TimeUnit.MILLISECONDS.toDays(millisFromNow)
    if (daysFromNow < 1) {
        return formatHours(hoursFromNow)
    }
    val weeksFromNow = TimeUnit.MILLISECONDS.toDays(millisFromNow) / 7
    if (weeksFromNow < 1) {
        return formatDays(daysFromNow)
    }
    val monthsFromNow = TimeUnit.MILLISECONDS.toDays(millisFromNow) / 30
    if (monthsFromNow < 1) {
        return formatWeeks(weeksFromNow)
    }
    val yearsFromNow = TimeUnit.MILLISECONDS.toDays(millisFromNow) / 365
    return if (yearsFromNow < 1) {
        formatMonths(monthsFromNow)
    } else formatYears(yearsFromNow)
}

 private fun getMillisFromNow(futureTime: Date): Long {
    val futureTimeMillis = futureTime.time
    val nowMillis = System.currentTimeMillis()
    return futureTimeMillis - nowMillis
}

private fun formatMinutes(minutes: Long): String {
    return format(minutes, " minute to go", " minutes to go")
}

private fun formatHours(hours: Long): String {
    return format(hours, " hour to go", " hours to go")
}

private fun formatDays(days: Long): String {
    return format(days, " day to go", " days to go")
}

private fun formatWeeks(weeks: Long): String {
    return format(weeks, " week to go", " weeks to go")
}

private fun formatMonths(months: Long): String {
    return format(months, " month to go", " months to go")
}

private fun formatYears(years: Long): String {
    return format(years, " year to go", " years to go")
}

private fun format(hand: Long, singular: String, plural: String): String {
    return if (hand == 1L) {
        hand.toString() + singular
    } else {
        hand.toString() + plural
    }
}
@Test
fun test() {
    val twoDaysInMillisInstant = Instant.now().plusMillis(TimeUnit.HOURS.toMillis(50))
    val result = format(Date.from(twoDaysInMillisInstant))

    assertEquals("2 days to go", result)
}
-----------------------
private fun getMillisFromNow(futureTime: Date): Long {
    val futureTimeMillis = futureTime.time
    val nowMillis = System.currentTimeMillis()
    return futureTimeMillis - nowMillis
}
 fun format(timestamp: Date): String {
    val millisFromNow = getMillisFromNow(timestamp)

    val minutesFromNow = TimeUnit.MILLISECONDS.toMinutes(millisFromNow)
    if (minutesFromNow < 1) {
        return "about now"
    }
    val hoursFromNow = TimeUnit.MILLISECONDS.toHours(millisFromNow)
    if (hoursFromNow < 1) {
        return formatMinutes(minutesFromNow)
    }
    val daysFromNow = TimeUnit.MILLISECONDS.toDays(millisFromNow)
    if (daysFromNow < 1) {
        return formatHours(hoursFromNow)
    }
    val weeksFromNow = TimeUnit.MILLISECONDS.toDays(millisFromNow) / 7
    if (weeksFromNow < 1) {
        return formatDays(daysFromNow)
    }
    val monthsFromNow = TimeUnit.MILLISECONDS.toDays(millisFromNow) / 30
    if (monthsFromNow < 1) {
        return formatWeeks(weeksFromNow)
    }
    val yearsFromNow = TimeUnit.MILLISECONDS.toDays(millisFromNow) / 365
    return if (yearsFromNow < 1) {
        formatMonths(monthsFromNow)
    } else formatYears(yearsFromNow)
}

 private fun getMillisFromNow(futureTime: Date): Long {
    val futureTimeMillis = futureTime.time
    val nowMillis = System.currentTimeMillis()
    return futureTimeMillis - nowMillis
}

private fun formatMinutes(minutes: Long): String {
    return format(minutes, " minute to go", " minutes to go")
}

private fun formatHours(hours: Long): String {
    return format(hours, " hour to go", " hours to go")
}

private fun formatDays(days: Long): String {
    return format(days, " day to go", " days to go")
}

private fun formatWeeks(weeks: Long): String {
    return format(weeks, " week to go", " weeks to go")
}

private fun formatMonths(months: Long): String {
    return format(months, " month to go", " months to go")
}

private fun formatYears(years: Long): String {
    return format(years, " year to go", " years to go")
}

private fun format(hand: Long, singular: String, plural: String): String {
    return if (hand == 1L) {
        hand.toString() + singular
    } else {
        hand.toString() + plural
    }
}
@Test
fun test() {
    val twoDaysInMillisInstant = Instant.now().plusMillis(TimeUnit.HOURS.toMillis(50))
    val result = format(Date.from(twoDaysInMillisInstant))

    assertEquals("2 days to go", result)
}

DateTimeParseException at index 0 with ThreeTenABP

copy iconCopydownload iconDownload
    DateTimeFormatter instantFormatter = DateTimeFormatter.ofPattern("uuuuMMdd'T'HHmmss.SSSX");
    String s = "20200117T172638.000Z";
    Instant instant = instantFormatter.parse(s, Instant.FROM);
    System.out.println(instant);

Community Discussions

Trending Discussions on ThreeTenABP
  • Why Android Studio fails to apply plugin 'com.cinnober.gradle.semver-git'?
  • A failure occurred while executing org.jetbrains.kotlin.gradle.internal.KaptWithoutKotlincTask$KaptExecutionWorkAction?java.lang.reflect.Invocation?
  • InvocationTargetException with Android Studio Arctic Fox on M1 Apple silicon
  • Could not find com.huawei.hms:hwid:5.3.0.301 &amp; push kit when adding HMS alongside GMS using HMS Toolkit
  • Could not find android.arch.navigation:navigation-safe-args-gradle-plugin:2.3.5.?
  • Cannot resolve external dependency com.android.tools:desugar_jdk_libs:1.0.9 because no repositories are defined
  • date and time show parse error at specific index
  • ThreeTenABP DateTime parser giving exception for yyyy-MM-ddTHH:mm:ss formate
  • Android error &quot;org.threeten.bp.temporal.UnsupportedTemporalTypeException: Unsupported unit: Seconds&quot;
  • Android + (Java Time or ThirteenTenABP) ZonedDateTime.of yields unexpected result
Trending Discussions on ThreeTenABP

QUESTION

Why Android Studio fails to apply plugin 'com.cinnober.gradle.semver-git'?

Asked 2022-Mar-11 at 22:01

Could some sharp eye find what has been bugging me for the last week? I cloned this repo but build fails with this exception:

FAILURE: Build failed with an exception.

  • Where: Script "C:\Users\MyUser\Desktop\repos\project\Launcher\git.gradle" line: 4

  • What went wrong: A problem occurred evaluating script. Failed to apply plugin 'com.cinnober.gradle.semver-git'

Cannot run program "git" (in directory "C:\Users\MyUser\Desktop\repos\project\Launcher"): CreateProcess error=2, System cannot find specified file

My build.gradle:

apply from: "check.gradle"

buildscript {

    ext.buildConfig = [
            "sdkCompile" : 31,
            "sdkMinimum" : 19,
            "sdkTarget"  : 28,
            "tools"      : "30.0.2",
            "versionCode": 1549,
            "versionName": "1.0.14",
    ]

    ext.versions = [
            "kotlin"  : "1.3.72",
            "okhttp"  : "3.12.12", // This version is the latest supporting API 19
            "retrofit": "2.6.4", // This version is the latest supporting API 19
            "room"    : "2.2.5",
    ]

    ext.lib = [
            "androidx": [
                    "appcompat"    : "androidx.appcompat:appcompat:1.1.0",
                    "async_inflate": "androidx.asynclayoutinflater:asynclayoutinflater:1.0.0",
                    "cardview"     : "androidx.cardview:cardview:1.0.0",
                    "constraint"   : "androidx.constraintlayout:constraintlayout:1.1.3",
                    "core"         : "androidx.core:core-ktx:1.3.1",
                    "fragment"     : "androidx.fragment:fragment-ktx:1.2.5",
                    "material"     : "com.google.android.material:material:1.1.0",
                    "multidex"     : "androidx.multidex:multidex:2.0.1",
                    "preference"   : "androidx.preference:preference-ktx:1.1.1",
                    "swipe_refresh": "androidx.swiperefreshlayout:swiperefreshlayout:1.1.0",
                    "work"         : "androidx.work:work-runtime-ktx:2.4.0",
            ],
            "date"    : [
                    "core": "com.jakewharton.threetenabp:threetenabp:1.2.4",
            ],
            "debug_db": "com.amitshekhar.android:debug-db:1.0.6",
            "firebase": [
                    "analytics": "com.google.firebase:firebase-analytics:17.4.4",
                    "crash"    : "com.google.firebase:firebase-crashlytics:17.1.1@aar",
            ],
            "glide"   : "com.github.bumptech.glide:glide:4.11.0",
            "viewpage": [
                    "indicator": "com.romandanylyk:pageindicatorview:1.0.3@aar",
            ],
            "kotlin"  : "org.jetbrains.kotlin:kotlin-stdlib-jdk7:${versions.kotlin}",
            "kb_event": "net.yslibrary.keyboardvisibilityevent:keyboardvisibilityevent:2.3.0",
            "okhttp"  : [
                    "core"   : "com.squareup.okhttp3:okhttp:${versions.okhttp}",
                    "curl"   : "com.github.mrmike:ok2curl:0.4.5",
                    "logging": "com.squareup.okhttp3:logging-interceptor:${versions.okhttp}",
            ],
            "play"    : [
                    "location": "com.google.android.gms:play-services-location:17.0.0",
            ],
            "retrofit": [
                    "core": "com.squareup.retrofit2:retrofit:${versions.retrofit}",
                    "gson": "com.squareup.retrofit2:converter-gson:${versions.retrofit}",
            ],
            "room"    : [
                    "compiler"  : "androidx.room:room-compiler:${versions.room}",
                    "core"      : "androidx.room:room-runtime:${versions.room}",
                    "coroutines": "androidx.room:room-ktx:${versions.room}",
            ],
            "timber"  : "com.jakewharton.timber:timber:4.7.1",
    ]

    repositories {
        google()
        mavenCentral()
        jcenter()
        maven { url 'https://jitpack.io' }
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:4.2.2'
        classpath "com.google.gms:google-services:4.3.3"
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:${versions.kotlin}"
        classpath "com.cinnober.gradle:semver-git:2.5.0"
        classpath "com.google.firebase:firebase-crashlytics-gradle:2.2.0"
        classpath "com.google.firebase:firebase-appdistribution-gradle:2.0.0"
        classpath "com.github.ben-manes:gradle-versions-plugin:0.29.0"
    }
}

allprojects {
    repositories {
        google()
        mavenCentral()
        jcenter()
        flatDir {
            dirs "${rootProject.rootDir}/libs"
        }
        maven { url 'https://jitpack.io' }
    }
}

task sendHomologToFirebase {
    group = "Firebase"
    dependsOn "Launcher:assembleHomologRelease"
    finalizedBy "Launcher:appDistributionUploadHomologRelease"
}

task sendProductionToFirebase {
    group = "Firebase"
    dependsOn "Launcher:assembleProductionRelease"
    finalizedBy "Launcher:appDistributionUploadProductionRelease"
}

task clean(type: Delete) {
    delete rootProject.buildDir
}

This is my git.gradle:

ext.nextVersion = "patch"
ext.snapshotSuffix = "<count><dirty>"
ext.dirtyMarker = ".d"
apply plugin: "com.cinnober.gradle.semver-git"

task git_count {
    def process = ("git rev-list --count HEAD").execute(null, project.rootDir)
    process.waitFor()
    if (process.exitValue() != 0) {
        ext.count = 0
        return
    }
    ext.count = process.text.trim().toInteger()
}

Things I've tried:

Both solutions described in this Gradle semver-git plugin page

buildscript {
  repositories {
    maven {
      url "https://plugins.gradle.org/m2/"
    }
  }
  dependencies {
    classpath "gradle.plugin.com.cinnober.gradle:semver-git:2.5.0"
  }
}

apply plugin: "com.cinnober.gradle.semver-git"

And:

plugins {
  id "com.cinnober.gradle.semver-git" version "2.5.0"
}

Also tried directly downloading the .pom file and loading it locally using:

flatDir {
    dirs "${rootProject.rootDir}/libs"
}

I even tried this solution from another SO answer:

Including this on my build.gradle

plugins {
    id 'com.cinnober.gradle.semver-git'
}

And including this on my settings.gradle

pluginManagement {
    buildscript {
        repositories {
            flatDir {
                dirs '/libs'
            }
        }
        dependencies {
            classpath ':semver-git:2.5.0'
        }
    }
}

ANSWER

Answered 2022-Mar-11 at 22:01

The relevant part of the error message is likely the end:

Cannot run program "git" (in directory "C:\Users\MyUser\Desktop\repos\project\Launcher"): CreateProcess error=2, System cannot find specified file

It's saying that it tried to run the program git but couldn't find it. It seems the plugin tries to run git as part of the process of applying it and it failed while doing so.

You already have git somewhere on your system since you cloned the repo, but it likely hasn't been added to your PATH so the script can't find it when it tries to run the command git

  1. The first step is to find where the git executable is on your system.
  2. Assuming that you're on windows, you will want to edit your system environment variables. It should be under Windows Settings -> System Environment Variables -> Path. Edit the Path variable by appending the full path to the folder your git executable is in.
    i.e: C:\Program Files\Git\bin if that's where your git.exe lives.
  3. Restart android studio afterwards to force it to load the new environment variables.

Here is a related question which has more detailed instructions about how to add git to the PATH with detailed examples.

Source https://stackoverflow.com/questions/71271206

Community Discussions, Code Snippets contain sources that include Stack Exchange Network

Vulnerabilities

No vulnerabilities reported

Install ThreeTenABP

Snapshots of the development version are available in [Sonatype’s snapshots repository][snap].

Support

For any new features, suggestions and bugs create an issue on GitHub. If you have any questions check and ask questions on community page Stack Overflow .

DOWNLOAD this Library from

Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from
over 430 million Knowledge Items
Find more libraries
Reuse Solution Kits and Libraries Curated by Popular Use Cases

Save this library and start creating your kit

Share this Page

share link
Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from
over 430 million Knowledge Items
Find more libraries
Reuse Solution Kits and Libraries Curated by Popular Use Cases

Save this library and start creating your kit

  • © 2022 Open Weaver Inc.