Arduino - Calculate Person's Age in Years, Months, Days

Here is code I recently used to calculate persons age in Years, Months, and Days on Arduino:

 
#include "RTClib.h"
RTC_DS3231 rtc; // Using DS3231 Real Time Clock 
DateTime now = rtc.now(); // Current Date and Time
DateTime dob = DateTime(1984,8,16,0,0,0); // Date of Birth (1984.08.16 00:00:00)
 
int t0 = dob.year() * 12 + dob.month() - 1;
int t = now.year() * 12 + now.month() - 1;
int dm = t - t0;
int Y;
int M;
int D;
 
//Calculate age in Y/M/D
if(now.day() >= dob.day()){
  Y = floor(dm/12);
  M = dm % 12;
  D = now.day() - dob.day();
}
else {
  dm--;
  t--;
  Y = floor(dm/12);
  M = dm % 12;
  DateTime tmp = DateTime(floor(t/12),(t%12)+1,dob.day(),0,0,0);
  D = (now.unixtime() - tmp.unixtime())/60/60/24;
}
 

 

Read more: Arduino - Calculate Person's Age in Years, Months, Days

The WIFI_SERVICE must be looked up on the Application context...

Issue

Generating signed APK in Android Studio 2.3 fails with following error:

Error: The WIFI_SERVICE must be looked up on the Application context or memory will leak on devices < Android N. Try changing  to .getApplicationContext()  [WifiManagerLeak]

Read more: The WIFI_SERVICE must be looked up on the Application context...

ListView Pop-Up Context Menu broken in Android 7 (API 24)

Issue

ListView context menu pop-up doesn't work properly in Android 7.0 and 7.1 Nougat (API 24 and API 25).

Instead of the full menu appearing in the middle of the screen, it now appears collapsed to a single item and either at the very top or at the very bottom of the screen.

Here is the expected behaviour:

Here is how the context menu looks in Android 7.1.1:

The app uses com.android.support:appcompat-v7 library and Theme.Holo.Light theme.

Read more: ListView Pop-Up Context Menu broken in Android 7 (API 24)

The number of method references in a .dex file cannot exceed 64k

Gradle build fails with error "The number of method references in a .dex file cannot exceed 64k "

As the error suggests you cannot have more than 64k methods in one classes.dex file. One way around this is to use enable MultiDex in your build.gradle

 
multiDexEnabled true
 

Read more: The number of method references in a .dex file cannot exceed 64k



Newsletter

Subscribe to receive occasional updates on new posts.
Your email will not be used for any other purpose and you can unsubscribe at any time.
Please wait