33[ ![ Platform] ( https://img.shields.io/badge/platform-Android-blue.svg )] ( https://www.android.com )
44[ ![ API] ( https://img.shields.io/badge/API-26+-blue.svg )] ( https://android-arsenal.com/api?level=26 )
55
6- [ ![ Version] ( https://img.shields.io/badge/version-0.3.0-blue.svg )] ( https://github.com/TimeXt/TimeXt-Java/tree/0.3.0 )
7- [ ![ Build] ( https://img.shields.io/badge/buildJava-success-green.svg )] ( releases/lib-2019-05-02-1.jar )
6+ [ ![ Version] ( https://img.shields.io/badge/version-0.4.0-blue.svg )] ( https://github.com/TimeXt/TimeXt-Java/tree/0.4.0 )
7+ [ ![ Build] ( https://img.shields.io/badge/buildJava-success-green.svg )] ( releases/lib-2019-07-19-1.jar )
8+ [ ![ Build] ( https://img.shields.io/badge/buildAndroid-success-green.svg )] ( releases/lib-android-2019-07-19-2.aar )
89
910[ ![ License: MIT] ( https://img.shields.io/badge/License-MIT-blue.svg )] ( https://opensource.org/licenses/MIT )
1011[ ![ Paypal] ( https://img.shields.io/badge/paypal-donate-blue.svg )] ( https://www.paypal.me/GuepardoApps )
@@ -15,7 +16,7 @@ First of all many thanks to [Kizitonwose](https://github.com/kizitonwose/Time) f
1516This library shall help to reduce code like
1617
1718``` java
18- int dayInMillis = 24 * 60 * 60 * 1000 ; // Represent a day in milliSeconds
19+ int dayInMillis = 24 * 60 * 60 * 1000 ; // Represent a day in millis
1920```
2021
2122## Important
@@ -27,65 +28,71 @@ Better use the [Kotlin version](https://github.com/TimeXt/TimeXt-Kotlin/) of thi
2728### Basics
2829
2930``` java
30- Interval threeYears = NumberExtensions . toYears(3 );
31- Interval oneWeek = NumberExtensions . toWeeks(1 );
32- Interval threeDays = NumberExtensions . toDays(3 );
33- Interval elevenHours = NumberExtensions . toHours(11 );
34- Interval sixMinutes = NumberExtensions . toMinutes(6 );
35- Interval fiftySeconds = NumberExtensions . toSeconds(50 );
36- Interval hundredMilliSeconds = NumberExtensions . toMilliSeconds (100 );
37- Interval fiveMicroSeconds = NumberExtensions . toMicroSeconds (5 );
38- Interval oneNanoSecond = NumberExtensions . toNanoSeconds( 1 );
39- Interval onePicoSecond = NumberExtensions . toPicoSeconds( 1 );
40-
41- double oneDayInMillis = NumberExtensions . toDays(1 ). InMilliSeconds (); // Converts one day into milliseconds
42- double twoWeeksInHours = NumberExtensions . toWeeks(2 ). InHours(); // Converts two weeks into hours
43-
44- Interval duration = NumberExtensions . toDays(1 ). Plus(NumberExtensions . toHours(6 ));
45- Interval difference = NumberExtensions . toMinutes(34 ). Minus(NumberExtensions . toSeconds(420 ));
46- Interval multipliedDuration = new Interval (4 , Unit . Week ). Times(1.5 );
47- Interval dividedDuration = new Interval (750 , Unit . PicoSecond ). Div(2.0 );
31+ TimeXt threeYears = DoubleXt . toYears(3.0 );
32+ TimeXt oneWeek = IntXt . toWeeks(1 );
33+ TimeXt threeDays = LongXt . toDays(3L );
34+ TimeXt elevenHours = DoubleXt . toHours(11.0 );
35+ TimeXt sixMinutes = IntXt . toMinutes(6 );
36+ TimeXt fiftySeconds = LongXt . toSeconds(50L );
37+ TimeXt hundredMillis = DoubleXt . toMillis (100.0 );
38+ TimeXt fiveMicros = IntXt . toMicros (5 );
39+ TimeXt oneNano = LongXt . toNanos( 1L );
40+ TimeXt onePico = DoubleXt . toPicos( 1.0 );
41+
42+ double oneDayInMillis = IntXt . toDays(1 ). InMillis (); // Converts one day into millis
43+ double twoWeeksInHours = LongXt . toWeeks(2L ). InHours(); // Converts two weeks into hours
44+
45+ TimeXt duration = DoubleXt . toDays(1.0 ). Plus(IntXt . toHours(6 ));
46+ TimeXt difference = LongXt . toMinutes(34L ). Minus(DoubleXt . toSeconds(420.0 ));
47+ TimeXt multipliedDuration = new TimeXt (4 , TimeXtUnit . Week ). Times(1.5 );
48+ TimeXt dividedDuration = new TimeXt (750 , TimeXtUnit . Picos ). Div(2.0 );
4849
4950```
5051
5152### Extensions
5253
5354``` java
5455// Calendar
55- Calendar inOneHour = CalendarExtensions . Add(Calendar . getInstance(), new Interval (1 , Unit . Hour ));
56- Calendar threeDaysAgo = CalendarExtensions . Minus(Calendar . getInstance(), new Interval (3 , Unit . Day ));
56+ Calendar inOneHour = CalendarXt . Add(Calendar . getInstance(), new TimeXt (1 , TimeXtUnit . Hour ));
57+ Calendar threeDaysAgo = CalendarXt . Minus(Calendar . getInstance(), new TimeXt (3 , TimeXtUnit . Day ));
58+ TimeXt calendarDifference = CalendarXt . Minus(Calendar calendar1, Calendar calendar2);
5759
5860// Sql Date
5961java.sql. Date sqlDate = new java.sql. Date ();
60- sqlDate = DateExtensions . Add(sqlDate, new Interval (30 , Unit . Second ));
61- sqlDate = DateExtensions . Minus(sqlDate, new Interval (500 , Unit . MilliSecond ));
62+ sqlDate = DateXt . Add(sqlDate, new TimeXt (30 , TimeXtUnit . Second ));
63+ sqlDate = DateXt . Minus(sqlDate, new TimeXt (500 , TimeXtUnit . Millis ));
64+ TimeXt dateDifference = DateXt . Minus(java.sql. Date date1, java.sql. Date date2);
6265
6366// Util Date
6467java.util. Date utilDate = new java.util. Date ();
65- utilDate = DateExtensions . Add(utilDate, new Interval (30 , Unit . Second ));
66- utilDate = DateExtensions . Minus(utilDate, new Interval (500 , Unit . MilliSecond ));
68+ utilDate = DateXt . Add(utilDate, new TimeXt (30 , TimeXtUnit . Second ));
69+ utilDate = DateXt . Minus(utilDate, new TimeXt (500 , TimeXtUnit . Millis ));
70+ TimeXt dateDifference = DateXt . Minus(java.util. Date date1, java.util. Date date2);
6771
6872// Timer
6973Timer timer = new Timer ();
7074TimerTask timerTask = ... ;
71- TimerExtensions . Schedule(timer, timerTask, new Interval (10 , Unit . Second ));
75+ TimerXt . Schedule(timer, timerTask, new TimeXt (10 , TimeXtUnit . Second ));
7276```
7377
7478The library also includes extensions for Android's Handler class, this is only available if you compile the "lib-android" module.
7579
7680``` java
7781Handler handler = new Handler ()
7882Runnable runnable = ... ;
79- HandlerExtensions . PostDelayed(handler, runnable, new Interval (2 , Unit . Minute ));
83+ HandlerXt . PostDelayed(handler, runnable, new TimeXt (2 , TimeXtUnit . Minute ));
8084```
8185
8286Since version 0.3.0 TimeXt has new extensions for the long type to display this number value in a human readable string format.
87+ In version 0.4.0 support for Integer and Double was added as well as the new method formatWeeks.
8388
8489``` java
85- val readableStringFromMilliseconds = LongExtensions . formatMilliseconds(34325055574 ) // 56 weeks, 5 days, 6 hours, 44 minutes, 15 seconds, 574 milliseconds
86- val readableStringFromSeconds = LongExtensions . formatSeconds(4350554 ) // 7 weeks, 1 day, 8 hours, 29 minutes, 14 seconds
87- val readableStringFromMinutes = LongExtensions . formatMinutes(432555 ) // 42 weeks, 6 days, 9 hours, 15 minutes
88- val readableStringFromHours = LongExtensions . formatHours(4574 ) // 27 weeks, 1 day, 14 hours
90+ val readableStringFromMillis = LongXt . formatMillis(34325055574L ) // 56 weeks, 5 days, 6 hours, 44 minutes, 15 seconds, 574 milliseconds
91+ val readableStringFromSeconds = LongXt . formatSeconds(4350554L ) // 7 weeks, 1 day, 8 hours, 29 minutes, 14 seconds
92+ val readableStringFromMinutes = LongXt . formatMinutes(432555L ) // 42 weeks, 6 days, 9 hours, 15 minutes
93+ val readableStringFromHours = LongXt . formatHours(4574L ) // 27 weeks, 1 day, 14 hours
94+ val readableStringFromDays = DoubleXt . formatDays(0.75 ) // 18 hours
95+ val readableStringFromWeeks = IntXt . formatWeeks(3 ) // 3 weeks
8996```
9097
9198## Requirements
@@ -119,3 +126,9 @@ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
119126OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
120127SOFTWARE.
121128```
129+
130+ ## Attention
131+
132+ Migrating from version 0.3.0 or lower to 0.4.0 or upper includes breaking changes.
133+ Class names where shortened from * Extensions to * Xt and unit enum was moved to another package (same as TimeXt) and renamed to TimeXtUnit.
134+ Furthermore all units smaller the unit second got shortened to * s (millis, micros, picos, nanos).
0 commit comments