├── .gitignore
├── README.md
├── build.gradle
├── logo.jpg
├── settings.gradle
└── wdate
├── .gitignore
├── build.gradle
├── proguard-rules.pro
└── src
├── androidTest
└── java
│ └── com
│ └── llollox
│ └── androidprojects
│ └── wdatelibrary
│ └── ExampleInstrumentedTest.java
├── main
├── AndroidManifest.xml
└── java
│ └── com
│ └── llollox
│ └── androidprojects
│ └── wdatelibrary
│ └── WDate.java
└── test
└── java
└── com
└── llollox
└── androidprojects
└── wdatelibrary
└── ExampleUnitTest.java
/.gitignore:
--------------------------------------------------------------------------------
1 | *.iml
2 | .gradle
3 | /local.properties
4 | /.idea/workspace.xml
5 | /.idea/libraries
6 | .DS_Store
7 | /build
8 | /captures
9 | .externalNativeBuild
10 |
11 |
12 | .idea
13 | gradle
14 | gradle.properties
15 | gradlew
16 | gradlew.bat
17 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # WDate - Wrapper of Date
2 |
3 | This is an utility class that wraps the standard `Date` class
4 | providing some useful methods without using the `Calendar` object.
5 |
6 | 
7 | [](https://android-arsenal.com/details/1/5136)
8 |
9 | 
10 |
11 |
12 | ## Getting Started
13 |
14 | #### Gradle
15 |
16 | ```groovy
17 | dependencies {
18 | compile 'com.llollox.androidprojects:wdate:1.2.1'
19 | }
20 | ```
21 |
22 | #### Maven
23 | ```xml
24 |
25 | com.llollox.androidprojects
26 | wdate
27 | 1.2.1
28 | pom
29 |
30 | ```
31 |
32 | ## Getting Started
33 |
34 | The first thing to do is set the date for our
35 | `WDate` object. This can be done in the following manner:
36 |
37 | ```java
38 | // Set its date as now
39 | WDate wdate = new WDate();
40 |
41 | // Set as its date the one passed as argument
42 | WDate wdate = new WDate(yourDate);
43 |
44 | // Get the Date object
45 | Date date = wDate.getDate();
46 | ```
47 |
48 | ## Configuration
49 | ```java
50 | // By default the week starts on Monday,
51 | // but it is possible to customize it
52 | // configuring the wdate object setting it
53 | // with WeekStart.SUNDAY
54 | wDate.setWeekStart(WeekStart weekStart);
55 | ```
56 |
57 |
58 | ## Usage
59 |
60 | ##### Checkers
61 |
62 | ```java
63 | boolean isToday()
64 |
65 | boolean isTomorrow()
66 |
67 | boolean isYesterday()
68 |
69 | // Week
70 |
71 | boolean isMonday();
72 |
73 | boolean isThursday();
74 |
75 | boolean isWednesday();
76 |
77 | boolean isTuesday();
78 |
79 | boolean isFriday();
80 |
81 | boolean isSaturday();
82 |
83 | boolean isSunday();
84 |
85 | // Time
86 |
87 | boolean isAtMidNight();
88 | ```
89 |
90 |
91 |
92 |
93 | ##### Comparators
94 |
95 | ```java
96 | // Returns the number of days (absolute value) between the dates.
97 | // The wdate's date is included, the other one not.
98 | int getNumDaysBetween(Date date)
99 |
100 | // Returns the number of months (absolute value) between the dates.
101 | // The wdate's date is included, the other one not.
102 | int getNumMonthsBetween(Date date)
103 |
104 | // Returns the number of years (absolute value) between the dates.
105 | // The wdate's date is included, the other one not.
106 | int getNumYearsBetween(Date date)
107 |
108 | // Returns the number of milliseconds (absolute value) between the dates.
109 | long getMilliSecondsDifference(Date date)
110 |
111 | // Checks if the wdate's date is contained in the period.
112 | // Both start and end date limits are excluded.
113 | boolean isInRange (Date start, Date end)
114 |
115 | // Checks if both dates have same day, month and year.
116 | boolean isSameDay(Date date)
117 | ```
118 |
119 | ##### Converters
120 |
121 | ```java
122 |
123 | // Set the time to midnight 00:00:00.000
124 | WDate atMidnight()
125 | ```
126 |
127 |
128 | ##### Formatter
129 |
130 | ```java
131 | // Format string following the Simple Date Format pattern.
132 | String format (String sdfPattern)
133 | ```
134 |
135 |
136 | ### Getters
137 |
138 | ##### Date
139 |
140 | ```java
141 | int getDay () // Day number in the month
142 |
143 | int getMonth () // Months start from 0
144 |
145 | int getYear ()
146 | ```
147 |
148 | ##### Time
149 |
150 | ```java
151 | int getHours () // 24h format
152 |
153 | int getMinutes ()
154 |
155 | int getSeconds ()
156 |
157 | int getMilliSeconds ()
158 | ```
159 |
160 | ##### Period
161 |
162 | ```java
163 | Date getFirstDayOfWeek ()
164 |
165 | Date getLastDayOfWeek ()
166 |
167 | Date getFirstDayOfMonth ()
168 |
169 | Date getLastDayOfMonth ()
170 |
171 | Date getFirstDayOfYear ()
172 |
173 | Date getLastDayOfYear ()
174 | ```
175 |
176 |
177 |
178 | ### Modifiers
179 | All modifiers supports method chaining.
180 |
181 | ##### Date
182 |
183 | ```java
184 | WDate addDays (int numDays)
185 |
186 | WDate addMonths (int numMonths)
187 |
188 | WDate addYears (int numYears)
189 | ```
190 |
191 | ##### Time
192 |
193 | ```java
194 | WDate addHours (int numHours)
195 |
196 | WDate addMinutes (int numMinutes)
197 |
198 | WDate addSeconds (int numSeconds)
199 |
200 | WDate addMilliSeconds (int numMilliSeconds)
201 | ```
202 |
203 |
204 |
205 | ### Setters
206 | All setters supports method chaining.
207 |
208 | ##### Date
209 |
210 | ```java
211 | WDate setDay (int days)
212 |
213 | WDate setMonth (int months)
214 |
215 | WDate setYear (int years)
216 | ```
217 |
218 | ##### Time
219 |
220 | ```java
221 | WDate setHours (int hours)
222 |
223 | WDate setMinutes (int minutes)
224 |
225 | WDate setSeconds (int seconds)
226 |
227 | WDate setMilliSeconds (int milliSeconds)
228 | ```
229 |
230 |
231 | ##### Static Methods
232 |
233 | The following methods return a `WDate` object
234 | with the time set at midnight (00:00:00)
235 |
236 | ```java
237 | WDate.dayAfterTomorrow()
238 |
239 | WDate.dayBeforeYesterday()
240 |
241 | WDate.today()
242 |
243 | WDate.tomorrow()
244 |
245 | WDate.yesterday()
246 |
247 | WDate.min(List dates)
248 |
249 | WDate.max(List dates)
250 | ```
251 |
--------------------------------------------------------------------------------
/build.gradle:
--------------------------------------------------------------------------------
1 | // Top-level build file where you can add configuration options common to all sub-projects/modules.
2 |
3 | buildscript {
4 | repositories {
5 | jcenter()
6 | }
7 | dependencies {
8 | classpath 'com.android.tools.build:gradle:2.2.3'
9 |
10 | // NOTE: Do not place your application dependencies here; they belong
11 | // in the individual module build.gradle files
12 | }
13 | }
14 |
15 | allprojects {
16 | repositories {
17 | jcenter()
18 | }
19 | }
20 |
21 | task clean(type: Delete) {
22 | delete rootProject.buildDir
23 | }
24 |
--------------------------------------------------------------------------------
/logo.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/llollox/WDate-Wrapper-of-Date-Android/2c94623e0fc20b93400d2b66058e3cb2ea8f7407/logo.jpg
--------------------------------------------------------------------------------
/settings.gradle:
--------------------------------------------------------------------------------
1 | include ':wdate'
2 |
--------------------------------------------------------------------------------
/wdate/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/wdate/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.library'
2 |
3 | ext {
4 | PUBLISH_GROUP_ID = 'com.llollox.androidprojects'
5 | PUBLISH_ARTIFACT_ID = 'wdate'
6 | PUBLISH_VERSION = '1.2.1'
7 | }
8 |
9 | android {
10 | compileSdkVersion 25
11 | buildToolsVersion "25.0.2"
12 | defaultConfig {
13 | minSdkVersion 9
14 | targetSdkVersion 25
15 | versionCode 1
16 | versionName "1.0"
17 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
18 | }
19 | buildTypes {
20 | release {
21 | minifyEnabled false
22 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
23 | }
24 | }
25 | }
26 |
27 | dependencies {
28 | compile fileTree(dir: 'libs', include: ['*.jar'])
29 | androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
30 | exclude group: 'com.android.support', module: 'support-annotations'
31 | })
32 | testCompile 'junit:junit:4.12'
33 | }
34 |
35 | apply from: 'https://raw.githubusercontent.com/blundell/release-android-library/master/android-release-aar.gradle'
36 |
--------------------------------------------------------------------------------
/wdate/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # By default, the flags in this file are appended to flags specified
3 | # in /Users/lorenzorigato/Library/Android/sdk/tools/proguard/proguard-android.txt
4 | # You can edit the include path and order by changing the proguardFiles
5 | # directive in build.gradle.
6 | #
7 | # For more details, see
8 | # http://developer.android.com/guide/developing/tools/proguard.html
9 |
10 | # Add any project specific keep options here:
11 |
12 | # If your project uses WebView with JS, uncomment the following
13 | # and specify the fully qualified class name to the JavaScript interface
14 | # class:
15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
16 | # public *;
17 | #}
18 |
--------------------------------------------------------------------------------
/wdate/src/androidTest/java/com/llollox/androidprojects/wdatelibrary/ExampleInstrumentedTest.java:
--------------------------------------------------------------------------------
1 | package com.llollox.androidprojects.wdatelibrary;
2 |
3 | import android.content.Context;
4 | import android.support.test.InstrumentationRegistry;
5 | import android.support.test.runner.AndroidJUnit4;
6 |
7 | import org.junit.Test;
8 | import org.junit.runner.RunWith;
9 |
10 | import static org.junit.Assert.*;
11 |
12 | /**
13 | * Instrumentation test, which will execute on an Android device.
14 | *
15 | * @see Testing documentation
16 | */
17 | @RunWith(AndroidJUnit4.class)
18 | public class ExampleInstrumentedTest {
19 | @Test
20 | public void useAppContext() throws Exception {
21 | // Context of the app under test.
22 | Context appContext = InstrumentationRegistry.getTargetContext();
23 |
24 | assertEquals("com.llollox.androidprojects.wdatelibrary", appContext.getPackageName());
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/wdate/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/wdate/src/main/java/com/llollox/androidprojects/wdatelibrary/WDate.java:
--------------------------------------------------------------------------------
1 | package com.llollox.androidprojects.wdatelibrary;
2 |
3 | import java.text.SimpleDateFormat;
4 | import java.util.Calendar;
5 | import java.util.Date;
6 | import java.util.List;
7 | import java.util.concurrent.TimeUnit;
8 |
9 | /**
10 | * Created by lorenzorigato on 11/01/2017.
11 | */
12 |
13 | public class WDate {
14 |
15 | public enum WeekStart {
16 | SUNDAY, MONDAY
17 | }
18 |
19 | private Calendar calendar;
20 | private WeekStart weekStart = WeekStart.MONDAY;
21 |
22 |
23 | public WDate() {
24 | this.calendar = Calendar.getInstance();
25 | }
26 |
27 | public WDate(Date date) {
28 | this();
29 | calendar.setTime(date);
30 | }
31 |
32 | public WDate(long milliseconds) {
33 | this(new Date(milliseconds));
34 | }
35 |
36 | public WDate setDate(Date date) {
37 | calendar.setTime(date);
38 | return this;
39 | }
40 |
41 | public Date getDate() {
42 | return calendar.getTime();
43 | }
44 |
45 | public WDate setWeekStart (WeekStart weekStart) {
46 | this.weekStart = weekStart;
47 | return this;
48 | }
49 |
50 |
51 |
52 |
53 |
54 |
55 |
56 | // **********************************************
57 | // COMPARATORS
58 | // **********************************************
59 |
60 | /**
61 | *
62 | * @param date The date used for the comparison
63 | * @return the number of days between
64 | * this wdate object's date and the one passed
65 | * as argument.
66 | *
67 | * The value returned is an absolute value, therefore
68 | * even if the date to be compared is in the past
69 | * the value returned is always positive.
70 | *
71 | * The wdate object's date is included, the
72 | * compared one not.
73 | *
74 | */
75 | public int getNumDaysBetween(Date date) {
76 | return Math.abs((int) TimeUnit.DAYS.convert(getMilliSecondsDifference(date), TimeUnit.MILLISECONDS));
77 | }
78 |
79 | /**
80 | *
81 | * @param date The date used for the comparison
82 | * @return the number of months between
83 | * this wdate object's date and the one passed
84 | * as argument.
85 | *
86 | * The value returned is an absolute value, therefore
87 | * even if the date to be compared is in the past
88 | * the value returned is always positive.
89 | *
90 | * The wdate object's date is included, the
91 | * compared one not.
92 | *
93 | */
94 | public int getNumMonthsBetween(Date date) {
95 | return getNumYearsBetween(date) * 12 + Math.abs(getMonth() - new WDate(date).getMonth());
96 | }
97 |
98 | /**
99 | *
100 | * @param date The date used for the comparison
101 | * @return the number of years between
102 | * this wdate object's date and the one passed
103 | * as argument.
104 | *
105 | * The value returned is an absolute value, therefore
106 | * even if the date to be compared is in the past
107 | * the value returned is always positive.
108 | *
109 | * The wdate object's date is included, the
110 | * compared one not.
111 | *
112 | */
113 |
114 | public int getNumYearsBetween(Date date) {
115 | return Math.abs(getYear() - new WDate(date).getYear());
116 | }
117 |
118 | /**
119 | *
120 | * @param date The date used for the comparison
121 | * @return the number milliseconds between
122 | * this wdate object's date and the one passed
123 | * as argument.
124 | *
125 | */
126 |
127 | public long getMilliSecondsDifference(Date date) {
128 | return Math.abs(calendar.getTime().getTime() - date.getTime());
129 | }
130 |
131 |
132 | /**
133 | *
134 | * @param start The start date of the range
135 | * @param end The end date of the range
136 | * @return if the wdate object's date is strictly contained
137 | * in the period between the start and end dates.
138 | * Therefore both start and end limits are excluded!
139 | *
140 | */
141 |
142 | public boolean isInRange(Date start, Date end) {
143 | return start.before(calendar.getTime()) && end.after(calendar.getTime());
144 | }
145 |
146 |
147 |
148 |
149 |
150 |
151 |
152 |
153 | // **********************************************
154 | // CONVERTERS
155 | // **********************************************
156 |
157 | public WDate atMidNight () {
158 | calendar.set(Calendar.HOUR_OF_DAY, 0);
159 | calendar.set(Calendar.MINUTE, 0);
160 | calendar.set(Calendar.SECOND, 0);
161 | calendar.set(Calendar.MILLISECOND, 0);
162 | return this;
163 | }
164 |
165 |
166 |
167 |
168 |
169 |
170 |
171 |
172 | // **********************************************
173 | // DAYS CHECKS
174 | // **********************************************
175 |
176 | // Week
177 |
178 | public boolean isMonday() {
179 | return calendar.get(Calendar.DAY_OF_WEEK) == Calendar.MONDAY;
180 | }
181 |
182 | public boolean isThursday() {
183 | return calendar.get(Calendar.DAY_OF_WEEK) == Calendar.THURSDAY;
184 | }
185 |
186 | public boolean isWednesday() {
187 | return calendar.get(Calendar.DAY_OF_WEEK) == Calendar.WEDNESDAY;
188 | }
189 |
190 | public boolean isTuesday() {
191 | return calendar.get(Calendar.DAY_OF_WEEK) == Calendar.TUESDAY;
192 | }
193 |
194 | public boolean isFriday() {
195 | return calendar.get(Calendar.DAY_OF_WEEK) == Calendar.FRIDAY;
196 | }
197 |
198 | public boolean isSaturday() {
199 | return calendar.get(Calendar.DAY_OF_WEEK) == Calendar.SATURDAY;
200 | }
201 |
202 | public boolean isSunday() {
203 | return calendar.get(Calendar.DAY_OF_WEEK) == Calendar.SUNDAY;
204 | }
205 |
206 | // Dates
207 |
208 | public boolean isToday() {
209 | return isSameDay(new Date());
210 | }
211 |
212 | public boolean isTomorrow() {
213 | Calendar tomorrowCalendar = Calendar.getInstance();
214 | tomorrowCalendar.add(Calendar.DATE, 1);
215 | return isSameDay(tomorrowCalendar.getTime());
216 | }
217 |
218 | public boolean isYesterday() {
219 | Calendar yesterdayCalendar = Calendar.getInstance();
220 | yesterdayCalendar.add(Calendar.DATE, -1);
221 | return isSameDay(yesterdayCalendar.getTime());
222 | }
223 |
224 | // Time
225 |
226 | public boolean isAtMidNight() {
227 | return calendar.get(Calendar.HOUR_OF_DAY) == 0
228 | && calendar.get(Calendar.MINUTE) == 0
229 | && calendar.get(Calendar.SECOND) == 0
230 | && calendar.get(Calendar.MILLISECOND) == 0;
231 | }
232 |
233 |
234 | public boolean isAfter(Date date) {
235 | return getDate().after(date);
236 | }
237 |
238 | public boolean isAfter(WDate wDate) {
239 | return isAfter(wDate.getDate());
240 | }
241 |
242 | public boolean isBefore(Date date) {
243 | return getDate().before(date);
244 | }
245 |
246 | public boolean isBefore(WDate wDate) {
247 | return isBefore(wDate.getDate());
248 | }
249 |
250 | /**
251 | *
252 | * @param date The date used for the comparison
253 | * @return if the wdate's date and the one passed as argument
254 | * have the same day, month and year.
255 | *
256 | */
257 |
258 | public boolean isSameDay(Date date) {
259 | WDate wDate = new WDate(date);
260 | return getDay() == wDate.getDay()
261 | && getMonth() == wDate.getMonth()
262 | && getYear() == wDate.getYear();
263 | }
264 |
265 |
266 |
267 |
268 |
269 |
270 |
271 | // **********************************************
272 | // DATE MODIFIERS
273 | // **********************************************
274 |
275 |
276 | public WDate addDays (int numDays) {
277 | calendar.add(Calendar.DAY_OF_MONTH, numDays);
278 | return this;
279 | }
280 |
281 | public WDate addMonths (int numMonths) {
282 | calendar.add(Calendar.MONTH, numMonths);
283 | return this;
284 | }
285 |
286 | public WDate addYears (int numYears) {
287 | calendar.add(Calendar.YEAR, numYears);
288 | return this;
289 | }
290 |
291 |
292 |
293 |
294 |
295 |
296 |
297 |
298 |
299 |
300 | // **********************************************
301 | // DATE GETTERS
302 | // **********************************************
303 |
304 |
305 | public int getDay () {
306 | return calendar.get(Calendar.DAY_OF_MONTH);
307 | }
308 |
309 | public int getMonth () {
310 | return calendar.get(Calendar.MONTH);
311 | }
312 |
313 | public int getYear () {
314 | return calendar.get(Calendar.YEAR);
315 | }
316 |
317 |
318 |
319 |
320 |
321 |
322 |
323 |
324 |
325 |
326 | // **********************************************
327 | // DATE SETTERS
328 | // **********************************************
329 |
330 |
331 | public WDate setDay (int day) {
332 | if (inRangeLimitsIncluded(1, 31, day)) {
333 | calendar.set(Calendar.DAY_OF_MONTH, day);
334 | }
335 | return this;
336 | }
337 |
338 | public WDate setMonth (int month) {
339 | if (inRangeLimitsIncluded(0, 11, month)) {
340 | calendar.set(Calendar.MONTH, month);
341 | }
342 | return this;
343 | }
344 |
345 | public WDate setYear (int year) {
346 | if (year > 0) {
347 | calendar.set(Calendar.YEAR, year);
348 | }
349 | return this;
350 | }
351 |
352 |
353 |
354 |
355 |
356 |
357 |
358 |
359 | // **********************************************
360 | // FORMATTERS
361 | // **********************************************
362 |
363 | /**
364 | *
365 | * @param sdfPattern The pattern used by SimpleDateFormat
366 | * @return a string that represent the date formatted
367 | *
368 | */
369 |
370 | public String format (String sdfPattern) {
371 | return new SimpleDateFormat(sdfPattern).format(calendar.getTime());
372 | }
373 |
374 |
375 |
376 |
377 |
378 |
379 | // **********************************************
380 | // PERIOD GETTERS
381 | // **********************************************
382 |
383 |
384 |
385 | public Date getFirstDayOfWeek() {
386 | Calendar cal = Calendar.getInstance();
387 | cal.setTime(calendar.getTime());
388 | cal.set(Calendar.DAY_OF_WEEK, 1);
389 | if (weekStart == WeekStart.MONDAY)
390 | cal.add(Calendar.DATE, 1);
391 |
392 | return cal.getTime();
393 | }
394 |
395 | public Date getLastDayOfWeek() {
396 | Calendar cal = Calendar.getInstance();
397 | cal.setTime(calendar.getTime());
398 | cal.set(Calendar.DAY_OF_WEEK, 7);
399 |
400 | if (weekStart == WeekStart.MONDAY)
401 | cal.add(Calendar.DATE, 1);
402 |
403 | return cal.getTime();
404 | }
405 |
406 | public Date getFirstDayOfMonth() {
407 | Calendar cal = Calendar.getInstance();
408 | cal.setTime(calendar.getTime());
409 | cal.set(Calendar.DAY_OF_MONTH, 1);
410 | return cal.getTime();
411 | }
412 |
413 | public Date getLastDayOfMonth() {
414 | Calendar cal = Calendar.getInstance();
415 | cal.setTime(getFirstDayOfMonth());
416 | cal.add(Calendar.MONTH, 1);
417 | cal.add(Calendar.DATE, -1);
418 | return cal.getTime();
419 | }
420 |
421 | public Date getFirstDayOfYear() {
422 | Calendar cal = Calendar.getInstance();
423 | cal.setTime(calendar.getTime());
424 | cal.set(Calendar.DAY_OF_YEAR, 1);
425 | return cal.getTime();
426 | }
427 |
428 | public Date getLastDayOfYear() {
429 | Calendar cal = Calendar.getInstance();
430 | cal.setTime(getFirstDayOfYear());
431 | cal.add(Calendar.YEAR, 1);
432 | cal.add(Calendar.DATE, -1);
433 | return cal.getTime();
434 | }
435 |
436 |
437 |
438 |
439 |
440 |
441 |
442 |
443 | // **********************************************
444 | // TIME GETTERS
445 | // **********************************************
446 |
447 | public int getHours() {
448 | return calendar.get(Calendar.HOUR_OF_DAY);
449 | }
450 |
451 | public int getMilliSeconds() {
452 | return calendar.get(Calendar.MILLISECOND);
453 | }
454 |
455 | public int getMinutes() {
456 | return calendar.get(Calendar.MINUTE);
457 | }
458 |
459 | public int getSeconds() {
460 | return calendar.get(Calendar.SECOND);
461 | }
462 |
463 | public long getMilliSecondsFromEpoch() {
464 | return calendar.getTime().getTime();
465 | }
466 |
467 |
468 |
469 |
470 |
471 |
472 | // **********************************************
473 | // TIME MODIFIERS
474 | // **********************************************
475 |
476 |
477 | public WDate addHours (int numHours) {
478 | calendar.add(Calendar.HOUR_OF_DAY, numHours);
479 | return this;
480 | }
481 |
482 | public WDate addMinutes (int numMinutes) {
483 | calendar.add(Calendar.MINUTE, numMinutes);
484 | return this;
485 | }
486 |
487 | public WDate addSeconds (int numSeconds) {
488 | calendar.add(Calendar.SECOND, numSeconds);
489 | return this;
490 | }
491 |
492 | public WDate addMilliSeconds (int numMilliSeconds) {
493 | calendar.add(Calendar.MILLISECOND, numMilliSeconds);
494 | return this;
495 | }
496 |
497 |
498 |
499 |
500 |
501 |
502 |
503 |
504 | // **********************************************
505 | // TIME SETTERS
506 | // **********************************************
507 |
508 | public WDate setHours(int hours) {
509 | if (inRangeLimitsIncluded(0, 23, hours)) {
510 | calendar.set(Calendar.HOUR_OF_DAY, hours);
511 | }
512 | return this;
513 | }
514 |
515 | public WDate setMilliSeconds(int milliSeconds) {
516 | if (inRangeLimitsIncluded(0, 999, milliSeconds)) {
517 | calendar.set(Calendar.MILLISECOND, milliSeconds);
518 | }
519 | return this;
520 | }
521 |
522 | public WDate setMinutes(int minutes) {
523 | if (inRangeLimitsIncluded(0, 59, minutes)) {
524 | calendar.set(Calendar.MINUTE, minutes);
525 | }
526 | return this;
527 | }
528 |
529 | public WDate setSeconds(int seconds) {
530 | if (inRangeLimitsIncluded(0, 59, seconds)) {
531 | calendar.set(Calendar.SECOND, seconds);
532 | }
533 | return this;
534 | }
535 |
536 |
537 |
538 |
539 | // **********************************************
540 | // STATIC METHODS
541 | // **********************************************
542 |
543 | public static WDate dayAfterTomorrow() {
544 | return new WDate().addDays(2).atMidNight();
545 | }
546 |
547 | public static WDate dayBeforeYesterday() {
548 | return new WDate().addDays(-2).atMidNight();
549 | }
550 |
551 | public static WDate today() {
552 | return new WDate().atMidNight();
553 | }
554 |
555 | public static WDate tomorrow() {
556 | return new WDate().addDays(1).atMidNight();
557 | }
558 |
559 | public static WDate yesterday() {
560 | return new WDate().addDays(-1).atMidNight();
561 | }
562 |
563 | public static WDate min(List dates) {
564 | if (dates != null && !dates.isEmpty()) {
565 | Date minDate = dates.get(0);
566 |
567 | for (int i=1; i dates) {
582 | if (dates != null && !dates.isEmpty()) {
583 | Date maxDate = dates.get(0);
584 |
585 | for (int i=1; i= min && value <= max;
607 | }
608 |
609 |
610 | }
611 |
--------------------------------------------------------------------------------
/wdate/src/test/java/com/llollox/androidprojects/wdatelibrary/ExampleUnitTest.java:
--------------------------------------------------------------------------------
1 | package com.llollox.androidprojects.wdatelibrary;
2 |
3 | import org.junit.Test;
4 |
5 | import static org.junit.Assert.*;
6 |
7 | /**
8 | * Example local unit test, which will execute on the development machine (host).
9 | *
10 | * @see Testing documentation
11 | */
12 | public class ExampleUnitTest {
13 | @Test
14 | public void addition_isCorrect() throws Exception {
15 | assertEquals(4, 2 + 2);
16 | }
17 | }
--------------------------------------------------------------------------------