Skip to content

Instantly share code, notes, and snippets.

Created September 12, 2023 15:25
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save cmathew/ece4f653d1649ba0ccdd7b62a9f7cb0a to your computer and use it in GitHub Desktop.
Android Lint code to remind developers that DateTime.toLocalDate is a lossy operation
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") {
"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