├── .github └── workflows │ ├── build.yaml │ └── upgrade.yaml ├── .gitignore ├── CHANGELOG.md ├── LICENSE.txt ├── README.md ├── RELEASING.md ├── build.gradle ├── gradle.properties ├── gradle ├── gradle-mvn-push.gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── sample ├── build.gradle ├── src │ ├── androidTest │ │ └── java │ │ │ └── com │ │ │ └── jakewharton │ │ │ └── threetenabp │ │ │ └── sample │ │ │ └── ExamplesTest.java │ ├── main │ │ ├── AndroidManifest.xml │ │ └── java │ │ │ └── com │ │ │ └── jakewharton │ │ │ └── threetenabp │ │ │ └── sample │ │ │ ├── Examples.java │ │ │ └── ExamplesApp.java │ └── test │ │ └── java │ │ └── com │ │ └── jakewharton │ │ └── threetenabp │ │ └── sample │ │ └── ExamplesTest.java └── test-rules.pro ├── settings.gradle ├── threetenabp ├── .gitignore ├── build.gradle ├── consumer-rules.pro ├── gradle.properties └── src │ ├── androidTest │ └── java │ │ └── com │ │ └── jakewharton │ │ └── threetenabp │ │ └── AndroidThreeTenTest.java │ └── main │ ├── AndroidManifest.xml │ ├── assets │ └── org │ │ └── threeten │ │ └── bp │ │ └── TZDB.dat │ └── java │ └── com │ └── jakewharton │ └── threetenabp │ ├── AndroidThreeTen.java │ └── AssetsZoneRulesInitializer.java └── update.sh /.github/workflows/build.yaml: -------------------------------------------------------------------------------- 1 | name: build 2 | 3 | on: 4 | pull_request: {} 5 | workflow_dispatch: {} 6 | push: 7 | branches: 8 | - 'trunk' 9 | tags-ignore: 10 | - '**' 11 | 12 | env: 13 | GRADLE_OPTS: "-Dorg.gradle.jvmargs=-Xmx6g -Dorg.gradle.daemon=false -Dkotlin.incremental=false" 14 | 15 | jobs: 16 | build: 17 | runs-on: macos-latest 18 | steps: 19 | - uses: actions/checkout@v3 20 | - uses: actions/setup-java@v3.11.0 21 | with: 22 | distribution: 'zulu' 23 | java-version: 8 24 | 25 | - uses: gradle/gradle-build-action@v2 26 | 27 | - run: ./gradlew build 28 | 29 | - name: Run integration tests 30 | uses: reactivecircus/android-emulator-runner@v2 31 | with: 32 | api-level: 24 33 | script: ./gradlew connectedCheck 34 | -------------------------------------------------------------------------------- /.github/workflows/upgrade.yaml: -------------------------------------------------------------------------------- 1 | name: upgrade 2 | 3 | on: 4 | schedule: 5 | - cron: '0 */3 * * *' 6 | workflow_dispatch: 7 | 8 | jobs: 9 | upgrade: 10 | runs-on: ubuntu-latest 11 | steps: 12 | - uses: actions/checkout@v3 13 | 14 | - run: ./update.sh 15 | 16 | - uses: peter-evans/create-pull-request@v4 17 | with: 18 | token: ${{ secrets.GH_PR_TOKEN }} 19 | commit-message: Bump ThreeTenBP dependency and embedded TZDB. 20 | title: Upgrade ThreeTenBP 21 | body: Bump dependency and embedded timezone database. 22 | branch: upgrade 23 | delete-branch: true 24 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # IntelliJ IDEA 2 | .idea 3 | *.iml 4 | 5 | # Gradle 6 | .gradle 7 | gradlew.bat 8 | build 9 | local.properties 10 | reports 11 | jacoco.exec 12 | 13 | .DS_Store 14 | 15 | -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | Change Log 2 | ========== 3 | 4 | Version 1.4.9 *(2025-03-12)* 5 | ---------------------------- 6 | 7 | * Update ThreeTenBP dependency to 1.7.1 ([change log][threeten171]) 8 | * Update time zone data to 2025a(gtz). 9 | 10 | Version 1.4.8 *(2024-11-26)* 11 | ---------------------------- 12 | 13 | * Update ThreeTenBP dependency to 1.7.0 ([change log][threeten170]) 14 | * Update time zone data to 2024b(gtz). 15 | 16 | Version 1.4.7 *(2024-03-27)* 17 | ---------------------------- 18 | 19 | * Update ThreeTenBP dependency to 1.6.9 ([change log][threeten169]) 20 | * Update time zone data to 2024a(gtz). 21 | 22 | Version 1.4.6 *(2023-03-31)* 23 | ---------------------------- 24 | 25 | * Update ThreeTenBP dependency to 1.6.8 ([change log][threeten168]) 26 | * Update time zone data to 2023c(gtz). 27 | 28 | Version 1.4.5 *(2023-03-30)* 29 | ---------------------------- 30 | 31 | * Update ThreeTenBP dependency to 1.6.7 ([change log][threeten167]) 32 | * Update time zone data to 2023b(gtz). 33 | 34 | Version 1.4.4 *(2022-11-03)* 35 | ---------------------------- 36 | 37 | * Update ThreeTenBP dependency to 1.6.5 ([change log][threeten165]) 38 | * Update time zone data to 2022g(gtz). 39 | 40 | 41 | Version 1.4.3 *(2022-11-03)* 42 | ---------------------------- 43 | 44 | * Update ThreeTenBP dependency to 1.6.4 ([change log][threeten164]) 45 | * Update time zone data to 2022f(gtz). 46 | 47 | 48 | Version 1.4.2 *(2022-10-13)* 49 | ---------------------------- 50 | 51 | * Update ThreeTenBP dependency to 1.6.3 ([change log][threeten163]) 52 | * Update time zone data to 2022e(gtz). 53 | 54 | 55 | Version 1.4.1 *(2022-09-26)* 56 | ---------------------------- 57 | 58 | * Update ThreeTenBP dependency to 1.6.2 ([change log][threeten162]) 59 | * Update time zone data to 2022d(gtz). 60 | 61 | 62 | Version 1.4.0 *(2022-03-21)* 63 | ---------------------------- 64 | 65 | * Update ThreeTenBP dependency to 1.6.0 ([change log][threeten160]) 66 | * Update time zone data to 2022a(gtz). 67 | 68 | 69 | Version 1.3.1 *(2021-04-20)* 70 | ---------------------------- 71 | 72 | * Update ThreeTenBP dependency to 1.5.1 ([change log][threeten151]) 73 | * Update time zone data to 2021a. 74 | 75 | 76 | Version 1.3.0 *(2020-10-26)* 77 | ---------------------------- 78 | 79 | * Update ThreeTenBP dependency to 1.5.0 ([change log][threeten150]) 80 | * Update time zone data to 2020d. 81 | 82 | 83 | Version 1.2.4 *(2020-04-24)* 84 | ---------------------------- 85 | 86 | * Update ThreeTenBP dependency to 1.4.4 ([change log][threeten144]) 87 | 88 | This adds Japanese Reiwa era. 89 | 90 | * Update time zone data to 2020a. 91 | 92 | 93 | Version 1.2.3 *(2020-03-27)* 94 | ---------------------------- 95 | 96 | * Update ThreeTenBP dependency to 1.4.2 ([change log][threeten142]). 97 | 98 | This fixes a crash when attempting to deserialize a library type when using Java serialization 99 | and when your app is minified using R8's full mode. 100 | 101 | 102 | Version 1.2.2 *(2020-01-13)* 103 | ---------------------------- 104 | 105 | * Update ThreeTenBP dependency to 1.4.1 ([change log][threeten141]). 106 | * Update time zone data to 2019c. 107 | 108 | 109 | Version 1.2.1 *(2019-06-03)* 110 | ---------------------------- 111 | 112 | * Update ThreeTenBP dependency to 1.4.0 ([change log][threeten140]). 113 | * Update time zone data to 2019a. 114 | * Fix: Embed consumer R8/ProGuard rules to ensure serialization (e.g., through Parcelable) does not 115 | lose any information. 116 | 117 | 118 | Version 1.2.0 *(2019-03-06)* 119 | ---------------------------- 120 | 121 | * Add `AndroidThreeTen.init(Context, String)` overload for supplying a path to a custom timezone 122 | database stored in assets. 123 | 124 | 125 | Version 1.1.2 *(2019-02-15)* 126 | ---------------------------- 127 | 128 | * Update ThreeTenBP dependency to 1.3.8 ([change log][threeten138]). 129 | * Update time zone data to 2018g. 130 | 131 | 132 | Version 1.1.1 *(2018-10-12)* 133 | ---------------------------- 134 | 135 | * Update ThreeTenBP dependency to 1.3.7 ([change log][threeten137]). 136 | 137 | 138 | Version 1.1.0 *(2018-04-20)* 139 | ---------------------------- 140 | 141 | * Update ThreeTenBP dependency to 1.3.6 ([change log][threeten136]). 142 | * Update time zone data to 2017b. 143 | * New: Timezone database is now lazily initialized and no longer blocks application startup. 144 | * Fix: Useless `BuildConfig` class is no longer included. 145 | 146 | 147 | Version 1.0.5 *(2017-02-02)* 148 | ---------------------------- 149 | 150 | * Update ThreeTenBP dependency to 1.3.3 ([change log][threeten133]). 151 | 152 | 153 | Version 1.0.4 *(2016-08-27)* 154 | ---------------------------- 155 | 156 | * New: Initialization method over which accepts a `Context`. 157 | * Update time zone data to 2016e. 158 | * Update ThreeTenBP dependency to 1.3.2. 159 | * Fix: Ensure native resource is freed after reading the time zone data. 160 | 161 | 162 | Version 1.0.3 *(2015-11-11)* 163 | ---------------------------- 164 | 165 | Update time zone data to 2015g. 166 | 167 | 168 | Version 1.0.2 *(2015-08-02)* 169 | ---------------------------- 170 | 171 | * Include a ProGuard rules file in the library which automatically suppresses harmless warnings 172 | from the library. 173 | * Fix: Correct logic which would incorrectly allow initialization to happen twice. 174 | 175 | 176 | Version 1.0.1 *(2015-07-15)* 177 | ---------------------------- 178 | 179 | Update time zone data to 2015e. 180 | 181 | 182 | Version 1.0.0 *(2015-07-15)* 183 | ---------------------------- 184 | 185 | Initial release. 186 | 187 | 188 | 189 | 190 | 191 | [threeten133]: https://www.threeten.org/threetenbp/changes-report.html#a1.3.3 192 | [threeten136]: https://www.threeten.org/threetenbp/changes-report.html#a1.3.6 193 | [threeten137]: https://www.threeten.org/threetenbp/changes-report.html#a1.3.7 194 | [threeten138]: https://www.threeten.org/threetenbp/changes-report.html#a1.3.8 195 | [threeten140]: https://www.threeten.org/threetenbp/changes-report.html#a1.4.0 196 | [threeten141]: https://www.threeten.org/threetenbp/changes-report.html#a1.4.1 197 | [threeten142]: https://www.threeten.org/threetenbp/changes-report.html#a1.4.2 198 | [threeten144]: https://www.threeten.org/threetenbp/changes-report.html#a1.4.4 199 | [threeten150]: https://www.threeten.org/threetenbp/changes-report.html#a1.5.0 200 | [threeten151]: https://www.threeten.org/threetenbp/changes-report.html#a1.5.1 201 | [threeten160]: https://www.threeten.org/threetenbp/changes-report.html#a1.6.0 202 | [threeten162]: https://www.threeten.org/threetenbp/changes-report.html#a1.6.2 203 | [threeten163]: https://www.threeten.org/threetenbp/changes-report.html#a1.6.3 204 | [threeten164]: https://www.threeten.org/threetenbp/changes-report.html#a1.6.4 205 | [threeten165]: https://www.threeten.org/threetenbp/changes-report.html#a1.6.5 206 | [threeten167]: https://www.threeten.org/threetenbp/changes-report.html#a1.6.7 207 | [threeten168]: https://www.threeten.org/threetenbp/changes-report.html#a1.6.8 208 | [threeten169]: https://www.threeten.org/threetenbp/changes-report.html#a1.6.9 209 | [threeten170]: https://www.threeten.org/threetenbp/changes-report.html#a1.7.0 210 | [threeten171]: https://www.threeten.org/threetenbp/changes-report.html#a1.7.1 211 | 212 | -------------------------------------------------------------------------------- /LICENSE.txt: -------------------------------------------------------------------------------- 1 | 2 | Apache License 3 | Version 2.0, January 2004 4 | http://www.apache.org/licenses/ 5 | 6 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 7 | 8 | 1. Definitions. 9 | 10 | "License" shall mean the terms and conditions for use, reproduction, 11 | and distribution as defined by Sections 1 through 9 of this document. 12 | 13 | "Licensor" shall mean the copyright owner or entity authorized by 14 | the copyright owner that is granting the License. 15 | 16 | "Legal Entity" shall mean the union of the acting entity and all 17 | other entities that control, are controlled by, or are under common 18 | control with that entity. For the purposes of this definition, 19 | "control" means (i) the power, direct or indirect, to cause the 20 | direction or management of such entity, whether by contract or 21 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 22 | outstanding shares, or (iii) beneficial ownership of such entity. 23 | 24 | "You" (or "Your") shall mean an individual or Legal Entity 25 | exercising permissions granted by this License. 26 | 27 | "Source" form shall mean the preferred form for making modifications, 28 | including but not limited to software source code, documentation 29 | source, and configuration files. 30 | 31 | "Object" form shall mean any form resulting from mechanical 32 | transformation or translation of a Source form, including but 33 | not limited to compiled object code, generated documentation, 34 | and conversions to other media types. 35 | 36 | "Work" shall mean the work of authorship, whether in Source or 37 | Object form, made available under the License, as indicated by a 38 | copyright notice that is included in or attached to the work 39 | (an example is provided in the Appendix below). 40 | 41 | "Derivative Works" shall mean any work, whether in Source or Object 42 | form, that is based on (or derived from) the Work and for which the 43 | editorial revisions, annotations, elaborations, or other modifications 44 | represent, as a whole, an original work of authorship. For the purposes 45 | of this License, Derivative Works shall not include works that remain 46 | separable from, or merely link (or bind by name) to the interfaces of, 47 | the Work and Derivative Works thereof. 48 | 49 | "Contribution" shall mean any work of authorship, including 50 | the original version of the Work and any modifications or additions 51 | to that Work or Derivative Works thereof, that is intentionally 52 | submitted to Licensor for inclusion in the Work by the copyright owner 53 | or by an individual or Legal Entity authorized to submit on behalf of 54 | the copyright owner. For the purposes of this definition, "submitted" 55 | means any form of electronic, verbal, or written communication sent 56 | to the Licensor or its representatives, including but not limited to 57 | communication on electronic mailing lists, source code control systems, 58 | and issue tracking systems that are managed by, or on behalf of, the 59 | Licensor for the purpose of discussing and improving the Work, but 60 | excluding communication that is conspicuously marked or otherwise 61 | designated in writing by the copyright owner as "Not a Contribution." 62 | 63 | "Contributor" shall mean Licensor and any individual or Legal Entity 64 | on behalf of whom a Contribution has been received by Licensor and 65 | subsequently incorporated within the Work. 66 | 67 | 2. Grant of Copyright License. Subject to the terms and conditions of 68 | this License, each Contributor hereby grants to You a perpetual, 69 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 70 | copyright license to reproduce, prepare Derivative Works of, 71 | publicly display, publicly perform, sublicense, and distribute the 72 | Work and such Derivative Works in Source or Object form. 73 | 74 | 3. Grant of Patent License. Subject to the terms and conditions of 75 | this License, each Contributor hereby grants to You a perpetual, 76 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 77 | (except as stated in this section) patent license to make, have made, 78 | use, offer to sell, sell, import, and otherwise transfer the Work, 79 | where such license applies only to those patent claims licensable 80 | by such Contributor that are necessarily infringed by their 81 | Contribution(s) alone or by combination of their Contribution(s) 82 | with the Work to which such Contribution(s) was submitted. If You 83 | institute patent litigation against any entity (including a 84 | cross-claim or counterclaim in a lawsuit) alleging that the Work 85 | or a Contribution incorporated within the Work constitutes direct 86 | or contributory patent infringement, then any patent licenses 87 | granted to You under this License for that Work shall terminate 88 | as of the date such litigation is filed. 89 | 90 | 4. Redistribution. You may reproduce and distribute copies of the 91 | Work or Derivative Works thereof in any medium, with or without 92 | modifications, and in Source or Object form, provided that You 93 | meet the following conditions: 94 | 95 | (a) You must give any other recipients of the Work or 96 | Derivative Works a copy of this License; and 97 | 98 | (b) You must cause any modified files to carry prominent notices 99 | stating that You changed the files; and 100 | 101 | (c) You must retain, in the Source form of any Derivative Works 102 | that You distribute, all copyright, patent, trademark, and 103 | attribution notices from the Source form of the Work, 104 | excluding those notices that do not pertain to any part of 105 | the Derivative Works; and 106 | 107 | (d) If the Work includes a "NOTICE" text file as part of its 108 | distribution, then any Derivative Works that You distribute must 109 | include a readable copy of the attribution notices contained 110 | within such NOTICE file, excluding those notices that do not 111 | pertain to any part of the Derivative Works, in at least one 112 | of the following places: within a NOTICE text file distributed 113 | as part of the Derivative Works; within the Source form or 114 | documentation, if provided along with the Derivative Works; or, 115 | within a display generated by the Derivative Works, if and 116 | wherever such third-party notices normally appear. The contents 117 | of the NOTICE file are for informational purposes only and 118 | do not modify the License. You may add Your own attribution 119 | notices within Derivative Works that You distribute, alongside 120 | or as an addendum to the NOTICE text from the Work, provided 121 | that such additional attribution notices cannot be construed 122 | as modifying the License. 123 | 124 | You may add Your own copyright statement to Your modifications and 125 | may provide additional or different license terms and conditions 126 | for use, reproduction, or distribution of Your modifications, or 127 | for any such Derivative Works as a whole, provided Your use, 128 | reproduction, and distribution of the Work otherwise complies with 129 | the conditions stated in this License. 130 | 131 | 5. Submission of Contributions. Unless You explicitly state otherwise, 132 | any Contribution intentionally submitted for inclusion in the Work 133 | by You to the Licensor shall be under the terms and conditions of 134 | this License, without any additional terms or conditions. 135 | Notwithstanding the above, nothing herein shall supersede or modify 136 | the terms of any separate license agreement you may have executed 137 | with Licensor regarding such Contributions. 138 | 139 | 6. Trademarks. This License does not grant permission to use the trade 140 | names, trademarks, service marks, or product names of the Licensor, 141 | except as required for reasonable and customary use in describing the 142 | origin of the Work and reproducing the content of the NOTICE file. 143 | 144 | 7. Disclaimer of Warranty. Unless required by applicable law or 145 | agreed to in writing, Licensor provides the Work (and each 146 | Contributor provides its Contributions) on an "AS IS" BASIS, 147 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 148 | implied, including, without limitation, any warranties or conditions 149 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 150 | PARTICULAR PURPOSE. You are solely responsible for determining the 151 | appropriateness of using or redistributing the Work and assume any 152 | risks associated with Your exercise of permissions under this License. 153 | 154 | 8. Limitation of Liability. In no event and under no legal theory, 155 | whether in tort (including negligence), contract, or otherwise, 156 | unless required by applicable law (such as deliberate and grossly 157 | negligent acts) or agreed to in writing, shall any Contributor be 158 | liable to You for damages, including any direct, indirect, special, 159 | incidental, or consequential damages of any character arising as a 160 | result of this License or out of the use or inability to use the 161 | Work (including but not limited to damages for loss of goodwill, 162 | work stoppage, computer failure or malfunction, or any and all 163 | other commercial damages or losses), even if such Contributor 164 | has been advised of the possibility of such damages. 165 | 166 | 9. Accepting Warranty or Additional Liability. While redistributing 167 | the Work or Derivative Works thereof, You may choose to offer, 168 | and charge a fee for, acceptance of support, warranty, indemnity, 169 | or other liability obligations and/or rights consistent with this 170 | License. However, in accepting such obligations, You may act only 171 | on Your own behalf and on Your sole responsibility, not on behalf 172 | of any other Contributor, and only if You agree to indemnify, 173 | defend, and hold each Contributor harmless for any liability 174 | incurred by, or claims asserted against, such Contributor by reason 175 | of your accepting any such warranty or additional liability. 176 | 177 | END OF TERMS AND CONDITIONS 178 | 179 | APPENDIX: How to apply the Apache License to your work. 180 | 181 | To apply the Apache License to your work, attach the following 182 | boilerplate notice, with the fields enclosed by brackets "[]" 183 | replaced with your own identifying information. (Don't include 184 | the brackets!) The text should be enclosed in the appropriate 185 | comment syntax for the file format. We also recommend that a 186 | file or class name and description of purpose be included on the 187 | same "printed page" as the copyright notice for easier 188 | identification within third-party archives. 189 | 190 | Copyright [yyyy] [name of copyright owner] 191 | 192 | Licensed under the Apache License, Version 2.0 (the "License"); 193 | you may not use this file except in compliance with the License. 194 | You may obtain a copy of the License at 195 | 196 | http://www.apache.org/licenses/LICENSE-2.0 197 | 198 | Unless required by applicable law or agreed to in writing, software 199 | distributed under the License is distributed on an "AS IS" BASIS, 200 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 201 | See the License for the specific language governing permissions and 202 | limitations under the License. 203 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ThreeTen Android Backport 2 | ========================= 3 | 4 | An adaptation of the JSR-310 backport for Android. 5 | 6 | **Attention**: Development on this library is winding down. Please consider switching to 7 | Android Gradle plugin 4.0, `java.time.*`, and its 8 | [core library desugaring](https://developer.android.com/studio/write/java8-support#library-desugaring) feature 9 | in the coming months. 10 | 11 | 12 | 13 | Usage 14 | ----- 15 | 16 | Initialize the timezone information in your `Application.onCreate()` method: 17 | ```java 18 | @Override public void onCreate() { 19 | super.onCreate(); 20 | AndroidThreeTen.init(this); 21 | } 22 | ``` 23 | 24 | That's it. Otherwise usage is the exact same as the ThreeTenBP library and you should consult 25 | its website for usage information: https://www.threeten.org/threetenbp/. 26 | 27 | 28 | 29 | Why JSR-310? 30 | ------------ 31 | 32 | JSR-310 was included in Java 8 as [the `java.time.*` package][time]. It is a full replacement 33 | for the ailing `Date` and `Calendar` APIs in both Java and Android. JSR-310 was backported to 34 | Java 6 by its creator, Stephen Colebourne, from which this library is adapted. 35 | 36 | 37 | 38 | Why not use ThreeTenBP? 39 | ----------------------- 40 | 41 | Similar to the problems with using [Joda-Time on Android][joda-android], the [threetenbp][ttbp] 42 | uses a JAR resource for loading timezone information. This is an extremely [inefficient mechanism 43 | on Android][slow]. 44 | 45 | This library places the timezone information as a standard Android asset and provides a custom 46 | loader for parsing it efficiently. 47 | 48 | 49 | 50 | Why not use Joda-Time? 51 | ---------------------- 52 | 53 | Joda-Time has a very large API which brings with it a very large binary size and large method 54 | count. The creator of both JSR-310 and Joda-Time has also said that while Joda-Time isn't broken, 55 | it does [have design flaws][flaws]. 56 | 57 | If you are using Joda-Time already, there's little reason to switch unless its size or method 58 | count is relevant to you. For new projects, however, this library offers the standard APIs in 59 | Java 8 as a much smaller package in not only binary size and method count, but also in API size. 60 | 61 | 62 | 63 | Download 64 | -------- 65 | 66 | ```groovy 67 | implementation 'com.jakewharton.threetenabp:threetenabp:1.4.9' 68 | ``` 69 | 70 | Snapshots of the development version are available in [Sonatype's `snapshots` repository][snap]. 71 | 72 | 73 | 74 | License 75 | ------- 76 | 77 | Copyright (C) 2015 Jake Wharton 78 | 79 | Licensed under the Apache License, Version 2.0 (the "License"); 80 | you may not use this file except in compliance with the License. 81 | You may obtain a copy of the License at 82 | 83 | http://www.apache.org/licenses/LICENSE-2.0 84 | 85 | Unless required by applicable law or agreed to in writing, software 86 | distributed under the License is distributed on an "AS IS" BASIS, 87 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 88 | See the License for the specific language governing permissions and 89 | limitations under the License. 90 | 91 | 92 | 93 | 94 | [snap]: https://oss.sonatype.org/content/repositories/snapshots/ 95 | [time]: https://docs.oracle.com/javase/8/docs/api/java/time/package-summary.html 96 | [joda-android]: https://github.com/dlew/joda-time-android#why-this-library 97 | [ttbp]: https://github.com/ThreeTen/threetenbp 98 | [flaws]: http://blog.joda.org/2009/11/why-jsr-310-isn-joda-time_4941.html 99 | [slow]: http://blog.danlew.net/2013/08/20/joda_time_s_memory_issue_in_android/ 100 | -------------------------------------------------------------------------------- /RELEASING.md: -------------------------------------------------------------------------------- 1 | Releasing 2 | ======== 3 | 4 | 1. Change the version in `gradle.properties` to a non-SNAPSHOT verson. 5 | 2. Update the `CHANGELOG.md` for the impending release. 6 | 3. Update the `README.md` with the new version. 7 | 4. `git commit -am "Prepare for release X.Y.Z."` (where X.Y.Z is the new version) 8 | 5. `git tag -a X.Y.X -m "Version X.Y.Z"` (where X.Y.Z is the new version) 9 | 6. `./gradlew clean uploadArchives` 10 | 7. Update the `gradle.properties` to the next SNAPSHOT version. 11 | 8. `git commit -am "Prepare next development version."` 12 | 9. `git push && git push --tags` 13 | 10. Visit [Sonatype Nexus](https://oss.sonatype.org/) and promote the artifact. 14 | -------------------------------------------------------------------------------- /build.gradle: -------------------------------------------------------------------------------- 1 | buildscript { 2 | repositories { 3 | mavenCentral() 4 | google() 5 | jcenter { 6 | // Required for a dependency of Android lint. 7 | content { 8 | includeGroup 'org.jetbrains.trove4j' 9 | } 10 | } 11 | } 12 | dependencies { 13 | classpath 'com.android.tools.build:gradle:3.6.3' 14 | } 15 | } 16 | 17 | allprojects { 18 | repositories { 19 | mavenCentral() 20 | google() 21 | jcenter { 22 | // Required for a dependency of Android lint. 23 | content { 24 | includeGroup 'org.jetbrains.trove4j' 25 | } 26 | } 27 | } 28 | } 29 | 30 | ext { 31 | minSdkVersion = 15 32 | compileSdkVersion = 29 33 | 34 | junit = 'junit:junit:4.13' 35 | truth = 'com.google.truth:truth:1.0.1' 36 | testOrchestrator = 'androidx.test:orchestrator:1.1.1' 37 | testRunner = 'androidx.test:runner:1.1.1' 38 | testRules = 'androidx.test:rules:1.1.1' 39 | robolectric = 'org.robolectric:robolectric:3.7.1' 40 | threetenbp = 'org.threeten:threetenbp:1.7.1:no-tzdb' 41 | } 42 | -------------------------------------------------------------------------------- /gradle.properties: -------------------------------------------------------------------------------- 1 | GROUP=com.jakewharton.threetenabp 2 | VERSION_NAME=1.5.0-SNAPSHOT 3 | 4 | POM_DESCRIPTION=An adaptation of the JSR-310 backport for Android. 5 | 6 | POM_URL=https://github.com/JakeWharton/ThreeTenABP/ 7 | POM_SCM_URL=https://github.com/JakeWharton/ThreeTenABP/ 8 | POM_SCM_CONNECTION=scm:git:git://github.com/JakeWharton/ThreeTenABP.git 9 | POM_SCM_DEV_CONNECTION=scm:git:ssh://git@github.com/JakeWharton/ThreeTenABP.git 10 | 11 | POM_LICENCE_NAME=The Apache Software License, Version 2.0 12 | POM_LICENCE_URL=http://www.apache.org/licenses/LICENSE-2.0.txt 13 | POM_LICENCE_DIST=repo 14 | 15 | POM_DEVELOPER_ID=jakewharton 16 | POM_DEVELOPER_NAME=Jake Wharton 17 | 18 | android.useAndroidX=true 19 | 20 | # Without this, R8 enters ProGuard-compatibility mode which infers more keep rules from those 21 | # which are specified. Enabling full mode treats the rules as exact which removes more and thus 22 | # exercises the serialization code more thoroughly. 23 | # See https://github.com/JakeWharton/ThreeTenABP/issues/122. 24 | android.enableR8.fullMode=true 25 | -------------------------------------------------------------------------------- /gradle/gradle-mvn-push.gradle: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2013 Chris Banes 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | apply plugin: 'maven' 18 | apply plugin: 'signing' 19 | 20 | def isReleaseBuild() { 21 | return VERSION_NAME.contains("SNAPSHOT") == false 22 | } 23 | 24 | def getReleaseRepositoryUrl() { 25 | return hasProperty('RELEASE_REPOSITORY_URL') ? RELEASE_REPOSITORY_URL 26 | : "https://oss.sonatype.org/service/local/staging/deploy/maven2/" 27 | } 28 | 29 | def getSnapshotRepositoryUrl() { 30 | return hasProperty('SNAPSHOT_REPOSITORY_URL') ? SNAPSHOT_REPOSITORY_URL 31 | : "https://oss.sonatype.org/content/repositories/snapshots/" 32 | } 33 | 34 | def getRepositoryUsername() { 35 | return hasProperty('SONATYPE_NEXUS_USERNAME') ? SONATYPE_NEXUS_USERNAME : "" 36 | } 37 | 38 | def getRepositoryPassword() { 39 | return hasProperty('SONATYPE_NEXUS_PASSWORD') ? SONATYPE_NEXUS_PASSWORD : "" 40 | } 41 | 42 | afterEvaluate { project -> 43 | uploadArchives { 44 | repositories { 45 | mavenDeployer { 46 | beforeDeployment { MavenDeployment deployment -> signing.signPom(deployment) } 47 | 48 | pom.groupId = GROUP 49 | pom.artifactId = POM_ARTIFACT_ID 50 | pom.version = VERSION_NAME 51 | 52 | repository(url: getReleaseRepositoryUrl()) { 53 | authentication(userName: getRepositoryUsername(), password: getRepositoryPassword()) 54 | } 55 | snapshotRepository(url: getSnapshotRepositoryUrl()) { 56 | authentication(userName: getRepositoryUsername(), password: getRepositoryPassword()) 57 | } 58 | 59 | pom.project { 60 | name POM_NAME 61 | packaging POM_PACKAGING 62 | description POM_DESCRIPTION 63 | url POM_URL 64 | 65 | scm { 66 | url POM_SCM_URL 67 | connection POM_SCM_CONNECTION 68 | developerConnection POM_SCM_DEV_CONNECTION 69 | } 70 | 71 | licenses { 72 | license { 73 | name POM_LICENCE_NAME 74 | url POM_LICENCE_URL 75 | distribution POM_LICENCE_DIST 76 | } 77 | } 78 | 79 | developers { 80 | developer { 81 | id POM_DEVELOPER_ID 82 | name POM_DEVELOPER_NAME 83 | } 84 | } 85 | } 86 | } 87 | } 88 | } 89 | 90 | signing { 91 | required { isReleaseBuild() && gradle.taskGraph.hasTask("uploadArchives") } 92 | sign configurations.archives 93 | } 94 | 95 | task androidJavadocs(type: Javadoc) { 96 | source = android.sourceSets.main.java.srcDirs 97 | classpath += project.files(android.getBootClasspath().join(File.pathSeparator)) 98 | 99 | if (JavaVersion.current().isJava8Compatible()) { 100 | allprojects { 101 | tasks.withType(Javadoc) { 102 | options.addStringOption('Xdoclint:none', '-quiet') 103 | } 104 | } 105 | } 106 | } 107 | 108 | task androidJavadocsJar(type: Jar, dependsOn: androidJavadocs) { 109 | classifier = 'javadoc' 110 | from androidJavadocs.destinationDir 111 | } 112 | 113 | task androidSourcesJar(type: Jar) { 114 | classifier = 'sources' 115 | from android.sourceSets.main.java.sourceFiles 116 | } 117 | 118 | artifacts { 119 | archives androidSourcesJar 120 | archives androidJavadocsJar 121 | } 122 | } 123 | -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JakeWharton/ThreeTenABP/546b614642fde8caee93fe5f9da909c34d87257e/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionBase=GRADLE_USER_HOME 2 | distributionPath=wrapper/dists 3 | distributionUrl=https\://services.gradle.org/distributions/gradle-5.6.4-all.zip 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | -------------------------------------------------------------------------------- /gradlew: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env sh 2 | 3 | # 4 | # Copyright 2015 the original author or authors. 5 | # 6 | # Licensed under the Apache License, Version 2.0 (the "License"); 7 | # you may not use this file except in compliance with the License. 8 | # You may obtain a copy of the License at 9 | # 10 | # http://www.apache.org/licenses/LICENSE-2.0 11 | # 12 | # Unless required by applicable law or agreed to in writing, software 13 | # distributed under the License is distributed on an "AS IS" BASIS, 14 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | # See the License for the specific language governing permissions and 16 | # limitations under the License. 17 | # 18 | 19 | ############################################################################## 20 | ## 21 | ## Gradle start up script for UN*X 22 | ## 23 | ############################################################################## 24 | 25 | # Attempt to set APP_HOME 26 | # Resolve links: $0 may be a link 27 | PRG="$0" 28 | # Need this for relative symlinks. 29 | while [ -h "$PRG" ] ; do 30 | ls=`ls -ld "$PRG"` 31 | link=`expr "$ls" : '.*-> \(.*\)$'` 32 | if expr "$link" : '/.*' > /dev/null; then 33 | PRG="$link" 34 | else 35 | PRG=`dirname "$PRG"`"/$link" 36 | fi 37 | done 38 | SAVED="`pwd`" 39 | cd "`dirname \"$PRG\"`/" >/dev/null 40 | APP_HOME="`pwd -P`" 41 | cd "$SAVED" >/dev/null 42 | 43 | APP_NAME="Gradle" 44 | APP_BASE_NAME=`basename "$0"` 45 | 46 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 47 | DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' 48 | 49 | # Use the maximum available, or set MAX_FD != -1 to use that value. 50 | MAX_FD="maximum" 51 | 52 | warn () { 53 | echo "$*" 54 | } 55 | 56 | die () { 57 | echo 58 | echo "$*" 59 | echo 60 | exit 1 61 | } 62 | 63 | # OS specific support (must be 'true' or 'false'). 64 | cygwin=false 65 | msys=false 66 | darwin=false 67 | nonstop=false 68 | case "`uname`" in 69 | CYGWIN* ) 70 | cygwin=true 71 | ;; 72 | Darwin* ) 73 | darwin=true 74 | ;; 75 | MINGW* ) 76 | msys=true 77 | ;; 78 | NONSTOP* ) 79 | nonstop=true 80 | ;; 81 | esac 82 | 83 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar 84 | 85 | # Determine the Java command to use to start the JVM. 86 | if [ -n "$JAVA_HOME" ] ; then 87 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 88 | # IBM's JDK on AIX uses strange locations for the executables 89 | JAVACMD="$JAVA_HOME/jre/sh/java" 90 | else 91 | JAVACMD="$JAVA_HOME/bin/java" 92 | fi 93 | if [ ! -x "$JAVACMD" ] ; then 94 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME 95 | 96 | Please set the JAVA_HOME variable in your environment to match the 97 | location of your Java installation." 98 | fi 99 | else 100 | JAVACMD="java" 101 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 102 | 103 | Please set the JAVA_HOME variable in your environment to match the 104 | location of your Java installation." 105 | fi 106 | 107 | # Increase the maximum file descriptors if we can. 108 | if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then 109 | MAX_FD_LIMIT=`ulimit -H -n` 110 | if [ $? -eq 0 ] ; then 111 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then 112 | MAX_FD="$MAX_FD_LIMIT" 113 | fi 114 | ulimit -n $MAX_FD 115 | if [ $? -ne 0 ] ; then 116 | warn "Could not set maximum file descriptor limit: $MAX_FD" 117 | fi 118 | else 119 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" 120 | fi 121 | fi 122 | 123 | # For Darwin, add options to specify how the application appears in the dock 124 | if $darwin; then 125 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" 126 | fi 127 | 128 | # For Cygwin, switch paths to Windows format before running java 129 | if $cygwin ; then 130 | APP_HOME=`cygpath --path --mixed "$APP_HOME"` 131 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` 132 | JAVACMD=`cygpath --unix "$JAVACMD"` 133 | 134 | # We build the pattern for arguments to be converted via cygpath 135 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` 136 | SEP="" 137 | for dir in $ROOTDIRSRAW ; do 138 | ROOTDIRS="$ROOTDIRS$SEP$dir" 139 | SEP="|" 140 | done 141 | OURCYGPATTERN="(^($ROOTDIRS))" 142 | # Add a user-defined pattern to the cygpath arguments 143 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then 144 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" 145 | fi 146 | # Now convert the arguments - kludge to limit ourselves to /bin/sh 147 | i=0 148 | for arg in "$@" ; do 149 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` 150 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option 151 | 152 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition 153 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` 154 | else 155 | eval `echo args$i`="\"$arg\"" 156 | fi 157 | i=$((i+1)) 158 | done 159 | case $i in 160 | (0) set -- ;; 161 | (1) set -- "$args0" ;; 162 | (2) set -- "$args0" "$args1" ;; 163 | (3) set -- "$args0" "$args1" "$args2" ;; 164 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;; 165 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; 166 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; 167 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; 168 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; 169 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; 170 | esac 171 | fi 172 | 173 | # Escape application args 174 | save () { 175 | for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done 176 | echo " " 177 | } 178 | APP_ARGS=$(save "$@") 179 | 180 | # Collect all arguments for the java command, following the shell quoting and substitution rules 181 | eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS" 182 | 183 | # by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong 184 | if [ "$(uname)" = "Darwin" ] && [ "$HOME" = "$PWD" ]; then 185 | cd "$(dirname "$0")" 186 | fi 187 | 188 | exec "$JAVACMD" "$@" 189 | -------------------------------------------------------------------------------- /sample/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.application' 2 | 3 | dependencies { 4 | implementation project(':threetenabp') 5 | 6 | androidTestImplementation rootProject.ext.junit 7 | androidTestImplementation rootProject.ext.testRunner 8 | androidTestImplementation rootProject.ext.testRules 9 | 10 | testImplementation rootProject.ext.junit 11 | testImplementation rootProject.ext.robolectric 12 | } 13 | 14 | android { 15 | compileSdkVersion rootProject.ext.compileSdkVersion 16 | 17 | defaultConfig { 18 | applicationId 'com.jakewharton.threetenabp.sample' 19 | minSdkVersion rootProject.ext.minSdkVersion 20 | targetSdkVersion rootProject.ext.compileSdkVersion 21 | versionCode 1 22 | versionName '1.0' 23 | 24 | testInstrumentationRunner 'androidx.test.runner.AndroidJUnitRunner' 25 | } 26 | 27 | buildTypes { 28 | debug { 29 | minifyEnabled true 30 | testProguardFiles file('test-rules.pro') 31 | } 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /sample/src/androidTest/java/com/jakewharton/threetenabp/sample/ExamplesTest.java: -------------------------------------------------------------------------------- 1 | package com.jakewharton.threetenabp.sample; 2 | 3 | import androidx.test.rule.ActivityTestRule; 4 | import java.io.ByteArrayInputStream; 5 | import java.io.ByteArrayOutputStream; 6 | import java.io.ObjectInputStream; 7 | import java.io.ObjectOutputStream; 8 | import org.junit.Rule; 9 | import org.junit.Test; 10 | import org.threeten.bp.Instant; 11 | import org.threeten.bp.ZonedDateTime; 12 | 13 | import static org.junit.Assert.assertEquals; 14 | import static org.junit.Assert.assertNotEquals; 15 | 16 | public final class ExamplesTest { 17 | @Rule public final ActivityTestRule examplesActivity = 18 | new ActivityTestRule<>(Examples.class); 19 | 20 | /** 21 | * Assert that ProGuard has run and obfuscated a library type. This implicitly also tests the 22 | * embedded ProGuard rules in the library are correct since currently ProGuard fails without them. 23 | */ 24 | @Test public void minificationHappened() { 25 | Examples activity = examplesActivity.getActivity(); 26 | Instant now = activity.now(); 27 | assertNotEquals("Instant", now.getClass().getSimpleName()); 28 | } 29 | 30 | /** Assert that date-time info is retained after serialization and deserialization. */ 31 | @Test public void minificationAllowsSerializationZonedDateTime() throws Exception { 32 | ZonedDateTime expected = examplesActivity.getActivity().hereAndNow(); 33 | 34 | ByteArrayOutputStream out = new ByteArrayOutputStream(); 35 | try (ObjectOutputStream os = new ObjectOutputStream(out)) { 36 | os.writeObject(expected); 37 | } 38 | byte[] bytes = out.toByteArray(); 39 | 40 | ObjectInputStream in = new ObjectInputStream(new ByteArrayInputStream(bytes)); 41 | ZonedDateTime actual = (ZonedDateTime) in.readObject(); 42 | 43 | // Difference is only reflected in toString and not just equals. 44 | assertEquals(expected.toString(), actual.toString()); 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /sample/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | -------------------------------------------------------------------------------- /sample/src/main/java/com/jakewharton/threetenabp/sample/Examples.java: -------------------------------------------------------------------------------- 1 | package com.jakewharton.threetenabp.sample; 2 | 3 | import android.app.Activity; 4 | import android.os.Bundle; 5 | import android.widget.TextView; 6 | import org.threeten.bp.Instant; 7 | import org.threeten.bp.ZoneId; 8 | import org.threeten.bp.ZonedDateTime; 9 | 10 | import static android.util.TypedValue.COMPLEX_UNIT_SP; 11 | import static android.view.Gravity.CENTER; 12 | 13 | public final class Examples extends Activity { 14 | @Override protected void onCreate(Bundle savedInstanceState) { 15 | super.onCreate(savedInstanceState); 16 | 17 | TextView tv = new TextView(this); 18 | tv.setGravity(CENTER); 19 | tv.setTextSize(COMPLEX_UNIT_SP, 20); 20 | tv.setText("NOW: " + hereAndNow()); 21 | setContentView(tv); 22 | } 23 | 24 | public Instant now() { 25 | return Instant.now(); 26 | } 27 | 28 | public ZonedDateTime hereAndNow() { 29 | return ZonedDateTime.ofInstant(now(), ZoneId.systemDefault()); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /sample/src/main/java/com/jakewharton/threetenabp/sample/ExamplesApp.java: -------------------------------------------------------------------------------- 1 | package com.jakewharton.threetenabp.sample; 2 | 3 | import android.app.Application; 4 | import com.jakewharton.threetenabp.AndroidThreeTen; 5 | 6 | public final class ExamplesApp extends Application { 7 | @Override public void onCreate() { 8 | super.onCreate(); 9 | AndroidThreeTen.init(this); 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /sample/src/test/java/com/jakewharton/threetenabp/sample/ExamplesTest.java: -------------------------------------------------------------------------------- 1 | package com.jakewharton.threetenabp.sample; 2 | 3 | import org.junit.Test; 4 | import org.junit.runner.RunWith; 5 | import org.robolectric.Robolectric; 6 | import org.robolectric.RobolectricTestRunner; 7 | import org.threeten.bp.Instant; 8 | 9 | import static org.junit.Assert.assertNotNull; 10 | 11 | /** This class has two tests to ensure that we can initialize the library multiple times. */ 12 | @RunWith(RobolectricTestRunner.class) 13 | public final class ExamplesTest { 14 | @Test public void one() { 15 | Examples activity = Robolectric.setupActivity(Examples.class); 16 | Instant now = activity.now(); 17 | assertNotNull(now); 18 | } 19 | 20 | @Test public void two() { 21 | Examples activity = Robolectric.setupActivity(Examples.class); 22 | Instant now = activity.now(); 23 | assertNotNull(now); 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /sample/test-rules.pro: -------------------------------------------------------------------------------- 1 | -dontwarn org.junit.** 2 | -dontwarn android.** 3 | -------------------------------------------------------------------------------- /settings.gradle: -------------------------------------------------------------------------------- 1 | include ':threetenabp' 2 | include ':sample' 3 | -------------------------------------------------------------------------------- /threetenabp/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /threetenabp/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.library' 2 | 3 | dependencies { 4 | api rootProject.ext.threetenbp 5 | 6 | androidTestImplementation rootProject.ext.junit 7 | androidTestImplementation rootProject.ext.testRunner 8 | androidTestImplementation rootProject.ext.truth 9 | androidTestUtil rootProject.ext.testOrchestrator 10 | } 11 | 12 | android { 13 | compileSdkVersion rootProject.ext.compileSdkVersion 14 | 15 | defaultConfig { 16 | minSdkVersion rootProject.ext.minSdkVersion 17 | 18 | testInstrumentationRunner 'androidx.test.runner.AndroidJUnitRunner' 19 | 20 | consumerProguardFiles 'consumer-rules.pro' 21 | } 22 | 23 | testOptions { 24 | execution 'ANDROIDX_TEST_ORCHESTRATOR' 25 | } 26 | 27 | compileOptions { 28 | sourceCompatibility JavaVersion.VERSION_1_7 29 | targetCompatibility JavaVersion.VERSION_1_7 30 | } 31 | 32 | lintOptions { 33 | textReport true 34 | textOutput 'stdout' 35 | } 36 | 37 | // TODO replace with https://issuetracker.google.com/issues/72050365 once released. 38 | libraryVariants.all { 39 | it.generateBuildConfig.enabled = false 40 | } 41 | } 42 | 43 | apply from: rootProject.file('gradle/gradle-mvn-push.gradle') 44 | -------------------------------------------------------------------------------- /threetenabp/consumer-rules.pro: -------------------------------------------------------------------------------- 1 | # Keep class members used for serialization 2 | # https://www.guardsquare.com/en/products/proguard/manual/examples#serializable 3 | -keepclassmembers class org.threeten.bp.** implements java.io.Serializable { 4 | private static final java.io.ObjectStreamField[] serialPersistentFields; 5 | private void writeObject(java.io.ObjectOutputStream); 6 | private void readObject(java.io.ObjectInputStream); 7 | java.lang.Object writeReplace(); 8 | java.lang.Object readResolve(); 9 | } 10 | -------------------------------------------------------------------------------- /threetenabp/gradle.properties: -------------------------------------------------------------------------------- 1 | POM_ARTIFACT_ID=threetenabp 2 | POM_NAME=ThreeTenAbp 3 | POM_PACKAGING=aar 4 | -------------------------------------------------------------------------------- /threetenabp/src/androidTest/java/com/jakewharton/threetenabp/AndroidThreeTenTest.java: -------------------------------------------------------------------------------- 1 | package com.jakewharton.threetenabp; 2 | 3 | import android.content.Context; 4 | import androidx.test.InstrumentationRegistry; 5 | import org.junit.Test; 6 | import org.threeten.bp.zone.ZoneRulesProvider; 7 | 8 | import static com.google.common.truth.Truth.assertThat; 9 | import static org.junit.Assert.fail; 10 | 11 | public final class AndroidThreeTenTest { 12 | private final Context context = 13 | InstrumentationRegistry.getTargetContext().getApplicationContext(); 14 | 15 | @Test public void litmus() { 16 | AndroidThreeTen.init(context); 17 | assertThat(ZoneRulesProvider.getAvailableZoneIds()).isNotEmpty(); 18 | } 19 | 20 | @Test public void customPath() { 21 | AndroidThreeTen.init(context, "does/not/exist.dat"); 22 | try { 23 | // This will trigger class loading and parsing of the supplied file. 24 | ZoneRulesProvider.getAvailableZoneIds(); 25 | fail(); 26 | } catch (ExceptionInInitializerError e) { 27 | assertThat(e).hasCauseThat().isInstanceOf(IllegalStateException.class); 28 | assertThat(e).hasCauseThat().hasMessageThat().isEqualTo("does/not/exist.dat missing from assets"); 29 | } 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /threetenabp/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | -------------------------------------------------------------------------------- /threetenabp/src/main/assets/org/threeten/bp/TZDB.dat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JakeWharton/ThreeTenABP/546b614642fde8caee93fe5f9da909c34d87257e/threetenabp/src/main/assets/org/threeten/bp/TZDB.dat -------------------------------------------------------------------------------- /threetenabp/src/main/java/com/jakewharton/threetenabp/AndroidThreeTen.java: -------------------------------------------------------------------------------- 1 | package com.jakewharton.threetenabp; 2 | 3 | import android.app.Application; 4 | import android.content.Context; 5 | import java.util.concurrent.atomic.AtomicBoolean; 6 | import org.threeten.bp.zone.ZoneRulesInitializer; 7 | 8 | /** Android-specific initializer for the JSR-310 library. */ 9 | public final class AndroidThreeTen { 10 | private static final AtomicBoolean initialized = new AtomicBoolean(); 11 | 12 | public static void init(Application application) { 13 | init((Context) application); 14 | } 15 | 16 | public static void init(Context context) { 17 | init(context, "org/threeten/bp/TZDB.dat"); 18 | } 19 | 20 | public static void init(Context context, String assetPath) { 21 | if (!initialized.getAndSet(true)) { 22 | ZoneRulesInitializer.setInitializer(new AssetsZoneRulesInitializer(context, assetPath)); 23 | } 24 | } 25 | 26 | private AndroidThreeTen() { 27 | throw new AssertionError(); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /threetenabp/src/main/java/com/jakewharton/threetenabp/AssetsZoneRulesInitializer.java: -------------------------------------------------------------------------------- 1 | package com.jakewharton.threetenabp; 2 | 3 | import android.content.Context; 4 | import java.io.IOException; 5 | import java.io.InputStream; 6 | import org.threeten.bp.zone.TzdbZoneRulesProvider; 7 | import org.threeten.bp.zone.ZoneRulesInitializer; 8 | import org.threeten.bp.zone.ZoneRulesProvider; 9 | 10 | final class AssetsZoneRulesInitializer extends ZoneRulesInitializer { 11 | private final Context context; 12 | private final String assetPath; 13 | 14 | AssetsZoneRulesInitializer(Context context, String assetPath) { 15 | this.context = context; 16 | this.assetPath = assetPath; 17 | } 18 | 19 | @Override protected void initializeProviders() { 20 | TzdbZoneRulesProvider provider; 21 | 22 | InputStream is = null; 23 | try { 24 | is = context.getAssets().open(assetPath); 25 | provider = new TzdbZoneRulesProvider(is); 26 | } catch (IOException e) { 27 | throw new IllegalStateException(assetPath + " missing from assets", e); 28 | } finally { 29 | if (is != null) { 30 | try { 31 | is.close(); 32 | } catch (IOException ignored) { 33 | } 34 | } 35 | } 36 | 37 | ZoneRulesProvider.registerProvider(provider); 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /update.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | set -e 4 | 5 | mkdir temp 6 | pushd temp 7 | 8 | # Download the latest release jar 9 | wget --trust-server-names "https://search.maven.org/remote_content?g=org.threeten&a=threetenbp&v=LATEST" 10 | 11 | # Extract its version 12 | file="$(ls)" 13 | version="${file#threetenbp-}" 14 | version="${version%.jar}" 15 | 16 | # Unzip its contents 17 | unzip "$file" 18 | 19 | # Replace embedded TZDB with new one. 20 | rm ../threetenabp/src/main/assets/org/threeten/bp/TZDB.dat 21 | mv org/threeten/bp/TZDB.dat ../threetenabp/src/main/assets/org/threeten/bp/ 22 | 23 | popd 24 | rm -r temp 25 | 26 | # Bump version in build file. 27 | sed -i -E "s/threetenbp:[^:]+:no-tzdb/threetenbp:${version}:no-tzdb/" build.gradle 28 | 29 | git status 30 | --------------------------------------------------------------------------------