Created
February 8, 2020 05:49
-
-
Save kapiljhajhria/c42967decfdaf09228e0a0c4a4cf0367 to your computer and use it in GitHub Desktop.
regex contains year or pdf for hackertimes
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
void main() { | |
List list1 = [1, 2, 3, 4, 5, 6, 7]; | |
List list2 = [11, 12, 13]; | |
int index = 6; | |
list2.forEach((item) { | |
list1.insert(index, item); | |
index++; | |
}); | |
print(list1); | |
var titleYear = 'Hello there, how are you (2005)'; | |
var titleYearPdf = 'Opportunities and Challenges of Emerging Technologies for Refugees (2019) [pdf]'; | |
print(doesItContainYear2(titleYear)); | |
print(doesItContainYear2(titleYearPdf)); | |
var titlePdf = 'Surveillance on UK council websites [pdf]'; | |
print(doesItContainPdf(titlePdf)); | |
String x = storeKeyAsPerIDandTime( | |
'kapil001', DateTime.now().subtract(Duration(minutes: 7))); | |
print(x); | |
print(isViewedTimeFromKeyAbove5Min(x)); | |
} | |
doesItContainYear(String title) { | |
if (title.contains('(') && title.contains(')')) { | |
var divide = title.split('(').toList(); | |
// print(divide); | |
var length = divide[1].length; | |
if (divide[1][length - 1] == ')' && length == 5) { | |
// print('its a year'); | |
return true; | |
} | |
} | |
return false; | |
} | |
doesItContainYear2(String title) { | |
return title.contains(new RegExp(r'[0-9.\-\)\(]+')); | |
// var l=title.length; | |
// if (title.contains('(') && title.contains(')') && title.contains(new RegExp(r'[0-9]'), l-7)) { | |
// return true; | |
// } | |
// return false; | |
} | |
doesItContainPdf(String title) { | |
var l = title.length; | |
if (title.contains('[') && title.contains(']')) { | |
var divide = title.split('[').toList(); | |
// print(divide); | |
var length = divide[1].length; | |
if (divide[1][length - 1] == ']' && | |
length == 4 && | |
title.substring(l - 4, l - 1) == 'pdf') { | |
// print('its a year'); | |
return true; | |
} | |
} | |
return false; | |
} | |
storeKeyAsPerIDandTime(String newsId, DateTime timeNow) { | |
return newsId + '/' + timeNow.toString(); | |
} | |
isViewedTimeFromKeyAbove5Min(String mapKey) { | |
var timeString = mapKey.split('/').toList()[1]; | |
print(timeString); | |
DateTime time = DateTime.parse(timeString); | |
return DateTime.now().difference(time).inMinutes >= 5; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment