Android Lint code to remind developers that DateTime.toLocalDate is a lossy operation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class WarnLocalDateConversion : Detector(), SourceCodeScanner { | |
override fun getApplicableMethodNames(): List<String> = listOf("toLocalDateTime", "toLocalDate") | |
override fun visitMethodCall(context: JavaContext, node: UCallExpression, method: PsiMethod) { | |
val receiverClassName = (node.receiverType as PsiClassReferenceType).reference.qualifiedName | |
if (receiverClassName == "org.joda.time.DateTime") { | |
context.report( | |
WARN_LOCAL_DATE_CONVERSION, | |
node, | |
context.getLocation(node), | |
"Be cautious about dropping timezone information, especially for UTC-zoned DateTimes.", | |
) | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment