Skip to content

Instantly share code, notes, and snippets.

@jimit24365
Last active February 6, 2020 07:59
Show Gist options
  • Save jimit24365/a62755868cb4881ffc695aec238effeb to your computer and use it in GitHub Desktop.
Save jimit24365/a62755868cb4881ffc695aec238effeb to your computer and use it in GitHub Desktop.
VideoKYCAvaibility
import 'package:flutter/material.dart';
void main() {
DateTime mockDeviceTime = DateTime.utc(2020, 2, 10, 15, 00, 00);
bool isVideoKycPossible = shouldEnableVideoKYC(mockDeviceTime);
print('IsVideoKYCPossible-${isVideoKycPossible}');
}
List<BankHolidayModel> getBankHolidayList() {
return List<BankHolidayModel>()
..add(BankHolidayModel(
nameOfHoliday: 'New Year`s Day',
startTime: DateTime.utc(2020, 1, 1, 00, 00, 00),
endTime: DateTime.utc(2020, 1, 2,00,00,00),
description: 'New Year`s Day'))
..add(BankHolidayModel(
nameOfHoliday: 'Chinese New Year',
startTime: DateTime.utc(2020, 1, 25, 00, 00, 00),
endTime: DateTime.utc(2020, 1, 26,00,00,00),
description: 'Chinese New Year'))
..add(BankHolidayModel(
nameOfHoliday: 'Isra Mi`raj',
startTime: DateTime.utc(2020, 3, 22, 00, 00, 00),
endTime: DateTime.utc(2020, 3, 23,00,00,00),
description: 'Isra Mi`raj'))
..add(BankHolidayModel(
nameOfHoliday: 'Bali Hindu New Year',
startTime: DateTime.utc(2020, 3, 25, 00, 00, 00),
endTime: DateTime.utc(2020, 3, 26,00,00,00),
description: 'Bali Hindu New Year'))
..add(BankHolidayModel(
nameOfHoliday: 'Good Friday',
startTime: DateTime.utc(2020, 4, 10, 00, 00, 00),
endTime: DateTime.utc(2020, 4, 11,00,00,00),
description: 'Good Friday'))
..add(BankHolidayModel(
nameOfHoliday: 'Labour Day',
startTime: DateTime.utc(2020, 5, 1, 00, 00, 00),
endTime: DateTime.utc(2020, 5, 2,00,00,00),
description: 'Labour Day'))
..add(BankHolidayModel(
nameOfHoliday: 'Waisak Day',
startTime: DateTime.utc(2020, 5, 7, 00, 00, 00),
endTime: DateTime.utc(2020, 5, 8,00,00,00),
description: 'Waisak Day'))
..add(BankHolidayModel(
nameOfHoliday: 'Ascension Day',
startTime: DateTime.utc(2020, 5, 21, 00, 00, 00),
endTime: DateTime.utc(2020, 5, 22,00,00,00),
description: 'Ascension Day'))
..add(BankHolidayModel(
nameOfHoliday: 'Idul Fitri',
startTime: DateTime.utc(2020, 5, 24, 00, 00, 00),
endTime: DateTime.utc(2020, 5, 26,00,00,00),
description: 'Idul Fitri'))
..add(BankHolidayModel(
nameOfHoliday: 'Lebaran Holiday',
startTime: DateTime.utc(2020, 5, 26, 00, 00, 00),
endTime: DateTime.utc(2020, 5, 28,00,00,00),
description: 'Lebaran Holiday'))
..add(BankHolidayModel(
nameOfHoliday: 'Pancasila Day',
startTime: DateTime.utc(2020, 6, 1, 00, 00, 00),
endTime: DateTime.utc(2020, 6, 2,00,00,00),
description: 'Pancasila Day'))
..add(BankHolidayModel(
nameOfHoliday: 'Idul Adha',
startTime: DateTime.utc(2020, 7, 31, 00, 00, 00),
endTime: DateTime.utc(2020, 8, 1,00,00,00),
description: 'Idul Adha'))
..add(BankHolidayModel(
nameOfHoliday: 'Independence Day',
startTime: DateTime.utc(2020, 8, 17, 00, 00, 00),
endTime: DateTime.utc(2020, 8, 18,00,00,00),
description: 'Independence Day'))
..add(BankHolidayModel(
nameOfHoliday: 'Islamic New Year',
startTime: DateTime.utc(2020, 8, 20, 00, 00, 00),
endTime: DateTime.utc(2020, 8, 21,00,00,00),
description: 'Islamic New Year'))
..add(BankHolidayModel(
nameOfHoliday: 'Prophet Muhammad`s Birthday',
startTime: DateTime.utc(2020, 10, 29, 00, 00, 00),
endTime: DateTime.utc(2020, 10, 30,00,00,00),
description: 'Prophet Muhammad`s Birthday'))
..add(BankHolidayModel(
nameOfHoliday: 'Christmas Holiday',
startTime: DateTime.utc(2020, 12, 24, 00, 00, 00),
endTime: DateTime.utc(2020, 12, 25,00,00,00),
description: 'Christmas Holiday'))
..add(BankHolidayModel(
nameOfHoliday: 'Christmas Day',
startTime: DateTime.utc(2020, 12, 25, 00, 00, 00),
endTime: DateTime.utc(2020, 12, 26,00,00,00),
description: 'Christmas Day'))
..add(BankHolidayModel(
nameOfHoliday: 'Weekend',
startTime: DateTime.utc(2020, 1, 5, 00, 00, 00),
endTime: DateTime.utc(2020, 1, 6, 00, 00, 00),
description: 'Weekend'))
..add(BankHolidayModel(
nameOfHoliday: 'Weekend',
startTime: DateTime.utc(2020, 1, 12, 00, 00, 00),
endTime: DateTime.utc(2020, 1, 13, 00, 00, 00),
description: 'Weekend'))
..add(BankHolidayModel(
nameOfHoliday: 'Weekend',
startTime: DateTime.utc(2020, 1, 19, 00, 00, 00),
endTime: DateTime.utc(2020, 1, 20, 00, 00, 00),
description: 'Weekend'))
..add(BankHolidayModel(
nameOfHoliday: 'Weekend',
startTime: DateTime.utc(2020, 1, 26, 00, 00, 00),
endTime: DateTime.utc(2020, 1, 27, 00, 00, 00),
description: 'Weekend'))
..add(BankHolidayModel(
nameOfHoliday: 'Weekend',
startTime: DateTime.utc(2020, 2, 2, 00, 00, 00),
endTime: DateTime.utc(2020, 2, 3, 00, 00, 00),
description: 'Weekend'))
..add(BankHolidayModel(
nameOfHoliday: 'Weekend',
startTime: DateTime.utc(2020, 2, 9, 00, 00, 00),
endTime: DateTime.utc(2020, 2, 10, 00, 00, 00),
description: 'Weekend'))
..add(BankHolidayModel(
nameOfHoliday: 'Weekend',
startTime: DateTime.utc(2020, 2, 16, 00, 00, 00),
endTime: DateTime.utc(2020, 2, 17, 00, 00, 00),
description: 'Weekend'))
..add(BankHolidayModel(
nameOfHoliday: 'Weekend',
startTime: DateTime.utc(2020, 2, 23, 00, 00, 00),
endTime: DateTime.utc(2020, 2, 24, 00, 00, 00),
description: 'Weekend'))
..add(BankHolidayModel(
nameOfHoliday: 'Weekend',
startTime: DateTime.utc(2020, 3, 1, 00, 00, 00),
endTime: DateTime.utc(2020, 3, 2, 00, 00, 00),
description: 'Weekend'))
..add(BankHolidayModel(
nameOfHoliday: 'Weekend',
startTime: DateTime.utc(2020, 3, 8, 00, 00, 00),
endTime: DateTime.utc(2020, 3, 9, 00, 00, 00),
description: 'Weekend'))
..add(BankHolidayModel(
nameOfHoliday: 'Weekend',
startTime: DateTime.utc(2020, 3, 15, 00, 00, 00),
endTime: DateTime.utc(2020, 3, 16, 00, 00, 00),
description: 'Weekend'))
..add(BankHolidayModel(
nameOfHoliday: 'Weekend',
startTime: DateTime.utc(2020, 3, 29, 00, 00, 00),
endTime: DateTime.utc(2020, 3, 30, 00, 00, 00),
description: 'Weekend'))
..add(BankHolidayModel(
nameOfHoliday: 'Weekend',
startTime: DateTime.utc(2020, 4, 5, 00, 00, 00),
endTime: DateTime.utc(2020, 4, 6, 00, 00, 00),
description: 'Weekend'))
..add(BankHolidayModel(
nameOfHoliday: 'Weekend',
startTime: DateTime.utc(2020, 4, 12, 00, 00, 00),
endTime: DateTime.utc(2020, 4, 13, 00, 00, 00),
description: 'Weekend'))
..add(BankHolidayModel(
nameOfHoliday: 'Weekend',
startTime: DateTime.utc(2020, 4, 19, 00, 00, 00),
endTime: DateTime.utc(2020, 4, 20, 00, 00, 00),
description: 'Weekend'))
..add(BankHolidayModel(
nameOfHoliday: 'Weekend',
startTime: DateTime.utc(2020, 4, 26, 00, 00, 00),
endTime: DateTime.utc(2020, 4, 27, 00, 00, 00),
description: 'Weekend'))
..add(BankHolidayModel(
nameOfHoliday: 'Weekend',
startTime: DateTime.utc(2020, 5, 3, 00, 00, 00),
endTime: DateTime.utc(2020, 5, 4, 00, 00, 00),
description: 'Weekend'))
..add(BankHolidayModel(
nameOfHoliday: 'Weekend',
startTime: DateTime.utc(2020, 5, 10, 00, 00, 00),
endTime: DateTime.utc(2020, 5, 11, 00, 00, 00),
description: 'Weekend'))
..add(BankHolidayModel(
nameOfHoliday: 'Weekend',
startTime: DateTime.utc(2020, 5, 17, 00, 00, 00),
endTime: DateTime.utc(2020, 5, 18, 00, 00, 00),
description: 'Weekend'))
..add(BankHolidayModel(
nameOfHoliday: 'Weekend',
startTime: DateTime.utc(2020, 5, 31, 00, 00, 00),
endTime: DateTime.utc(2020, 6, 1, 00, 00, 00),
description: 'Weekend'))
..add(BankHolidayModel(
nameOfHoliday: 'Weekend',
startTime: DateTime.utc(2020, 6, 7, 00, 00, 00),
endTime: DateTime.utc(2020, 6, 8, 00, 00, 00),
description: 'Weekend'))
..add(BankHolidayModel(
nameOfHoliday: 'Weekend',
startTime: DateTime.utc(2020, 6, 14, 00, 00, 00),
endTime: DateTime.utc(2020, 6, 15, 00, 00, 00),
description: 'Weekend'))
..add(BankHolidayModel(
nameOfHoliday: 'Weekend',
startTime: DateTime.utc(2020, 6, 21, 00, 00, 00),
endTime: DateTime.utc(2020, 6, 22, 00, 00, 00),
description: 'Weekend'))
..add(BankHolidayModel(
nameOfHoliday: 'Weekend',
startTime: DateTime.utc(2020, 6, 28, 00, 00, 00),
endTime: DateTime.utc(2020, 6, 29, 00, 00, 00),
description: 'Weekend'))
..add(BankHolidayModel(
nameOfHoliday: 'Weekend',
startTime: DateTime.utc(2020, 7, 5, 00, 00, 00),
endTime: DateTime.utc(2020, 7, 6, 00, 00, 00),
description: 'Weekend'))
..add(BankHolidayModel(
nameOfHoliday: 'Weekend',
startTime: DateTime.utc(2020, 7, 12, 00, 00, 00),
endTime: DateTime.utc(2020, 7, 13, 00, 00, 00),
description: 'Weekend'))
..add(BankHolidayModel(
nameOfHoliday: 'Weekend',
startTime: DateTime.utc(2020, 7, 19, 00, 00, 00),
endTime: DateTime.utc(2020, 7, 20, 00, 00, 00),
description: 'Weekend'))
..add(BankHolidayModel(
nameOfHoliday: 'Weekend',
startTime: DateTime.utc(2020, 7, 26, 00, 00, 00),
endTime: DateTime.utc(2020, 7, 27, 00, 00, 00),
description: 'Weekend'))
..add(BankHolidayModel(
nameOfHoliday: 'Weekend',
startTime: DateTime.utc(2020, 8, 9, 00, 00, 00),
endTime: DateTime.utc(2020, 8, 10, 00, 00, 00),
description: 'Weekend'))
..add(BankHolidayModel(
nameOfHoliday: 'Weekend',
startTime: DateTime.utc(2020, 8, 16, 00, 00, 00),
endTime: DateTime.utc(2020, 8, 17, 00, 00, 00),
description: 'Weekend'))
..add(BankHolidayModel(
nameOfHoliday: 'Weekend',
startTime: DateTime.utc(2020, 8, 23, 00, 00, 00),
endTime: DateTime.utc(2020, 8, 24, 00, 00, 00),
description: 'Weekend'))
..add(BankHolidayModel(
nameOfHoliday: 'Weekend',
startTime: DateTime.utc(2020, 8, 30, 00, 00, 00),
endTime: DateTime.utc(2020, 8, 31, 00, 00, 00),
description: 'Weekend'))
..add(BankHolidayModel(
nameOfHoliday: 'Weekend',
startTime: DateTime.utc(2020, 9, 6, 00, 00, 00),
endTime: DateTime.utc(2020, 9, 7, 00, 00, 00),
description: 'Weekend'))
..add(BankHolidayModel(
nameOfHoliday: 'Weekend',
startTime: DateTime.utc(2020, 9, 13, 00, 00, 00),
endTime: DateTime.utc(2020, 9, 14, 00, 00, 00),
description: 'Weekend'))
..add(BankHolidayModel(
nameOfHoliday: 'Weekend',
startTime: DateTime.utc(2020, 9, 20, 00, 00, 00),
endTime: DateTime.utc(2020, 9, 21, 00, 00, 00),
description: 'Weekend'))
..add(BankHolidayModel(
nameOfHoliday: 'Weekend',
startTime: DateTime.utc(2020, 9, 27, 00, 00, 00),
endTime: DateTime.utc(2020, 9, 28, 00, 00, 00),
description: 'Weekend'))
..add(BankHolidayModel(
nameOfHoliday: 'Weekend',
startTime: DateTime.utc(2020, 10, 4, 00, 00, 00),
endTime: DateTime.utc(2020, 10, 5, 00, 00, 00),
description: 'Weekend'))
..add(BankHolidayModel(
nameOfHoliday: 'Weekend',
startTime: DateTime.utc(2020, 10, 11, 00, 00, 00),
endTime: DateTime.utc(2020, 10, 12, 00, 00, 00),
description: 'Weekend'))
..add(BankHolidayModel(
nameOfHoliday: 'Weekend',
startTime: DateTime.utc(2020, 10, 18, 00, 00, 00),
endTime: DateTime.utc(2020, 10, 19, 00, 00, 00),
description: 'Weekend'))
..add(BankHolidayModel(
nameOfHoliday: 'Weekend',
startTime: DateTime.utc(2020, 10, 25, 00, 00, 00),
endTime: DateTime.utc(2020, 10, 26, 00, 00, 00),
description: 'Weekend'))
..add(BankHolidayModel(
nameOfHoliday: 'Weekend',
startTime: DateTime.utc(2020, 11, 1, 00, 00, 00),
endTime: DateTime.utc(2020, 11, 2, 00, 00, 00),
description: 'Weekend'))
..add(BankHolidayModel(
nameOfHoliday: 'Weekend',
startTime: DateTime.utc(2020, 11, 8, 00, 00, 00),
endTime: DateTime.utc(2020, 11, 9, 00, 00, 00),
description: 'Weekend'))
..add(BankHolidayModel(
nameOfHoliday: 'Weekend',
startTime: DateTime.utc(2020, 11, 15, 00, 00, 00),
endTime: DateTime.utc(2020, 11, 16, 00, 00, 00),
description: 'Weekend'))
..add(BankHolidayModel(
nameOfHoliday: 'Weekend',
startTime: DateTime.utc(2020, 11, 22, 00, 00, 00),
endTime: DateTime.utc(2020, 11, 23, 00, 00, 00),
description: 'Weekend'))
..add(BankHolidayModel(
nameOfHoliday: 'Weekend',
startTime: DateTime.utc(2020, 11, 29, 00, 00, 00),
endTime: DateTime.utc(2020, 11, 30, 00, 00, 00),
description: 'Weekend'))
..add(BankHolidayModel(
nameOfHoliday: 'Weekend',
startTime: DateTime.utc(2020, 12, 6, 00, 00, 00),
endTime: DateTime.utc(2020, 12, 7, 00, 00, 00),
description: 'Weekend'))
..add(BankHolidayModel(
nameOfHoliday: 'Weekend',
startTime: DateTime.utc(2020, 12, 13, 00, 00, 00),
endTime: DateTime.utc(2020, 12, 14, 00, 00, 00),
description: 'Weekend'))
..add(BankHolidayModel(
nameOfHoliday: 'Weekend',
startTime: DateTime.utc(2020, 12, 20, 00, 00, 00),
endTime: DateTime.utc(2020, 12, 21, 00, 00, 00),
description: 'Weekend'))
..add(BankHolidayModel(
nameOfHoliday: 'Weekend',
startTime: DateTime.utc(2020, 12, 27, 00, 00, 00),
endTime: DateTime.utc(2020, 12, 28, 00, 00, 00),
description: 'Weekend'))
..add(BankHolidayModel(
nameOfHoliday: 'Weekend',
startTime: DateTime.utc(2020, 8, 2, 00, 00, 00),
endTime: DateTime.utc(2020, 8, 3, 00, 00, 00),
description: 'Weekend'));
}
List<BusinessHourModel> getBusinessHourList(){
return List<BusinessHourModel>()
..add(BusinessHourModel(
day: DateTime.monday,
startTime: const TimeOfDay(hour: 1, minute: 0),
endTime: const TimeOfDay(hour: 10, minute: 0)
))
..add(BusinessHourModel(
day: DateTime.tuesday,
startTime: const TimeOfDay(hour: 1, minute: 0),
endTime: const TimeOfDay(hour: 10, minute: 0)
))
..add(BusinessHourModel(
day: DateTime.wednesday,
startTime: const TimeOfDay(hour: 1, minute: 0),
endTime: const TimeOfDay(hour: 10, minute: 0)
))
..add(BusinessHourModel(
day: DateTime.thursday,
startTime: const TimeOfDay(hour: 1, minute: 0),
endTime: const TimeOfDay(hour: 10, minute: 0)
))
..add(BusinessHourModel(
day: DateTime.friday,
startTime: const TimeOfDay(hour: 1, minute: 0),
endTime: const TimeOfDay(hour: 10, minute: 0)
))
..add(BusinessHourModel(
day: DateTime.saturday,
startTime: const TimeOfDay(hour: 1, minute: 0),
endTime: const TimeOfDay(hour: 5, minute: 0)
));
}
bool shouldEnableVideoKYC(DateTime deviceDateTime) {
if (!_currentDateTimeIsUnderBusinessHour(deviceDateTime)) {
return false;
}
if(_currentDateTimeIsUnderHolidayList(deviceDateTime)){
return false;
}
return true;
}
bool _currentDateTimeIsUnderBusinessHour(DateTime currentDeviceDateTime){
print('CurrentDateTime-${currentDeviceDateTime.toString()}');
final int currentDay = currentDeviceDateTime.weekday;
print('CurrentDay-${currentDay}');
for (final BusinessHourModel businessHourModel in getBusinessHourList()) {
print('BusinessDay-${businessHourModel.day}');
if (businessHourModel.day == currentDay) {
print('MatchDay-${businessHourModel.day}');
final DateTime utcStartTime = businessHourModel.getStartDateTime(currentDeviceDateTime);
print('utcStartTime-${utcStartTime.toString()}');
final DateTime utcEndTime = businessHourModel.getEndDateTime(currentDeviceDateTime);
print('utcEndTime-${utcEndTime.toString()}');
if (doesLiesBetween(currentDeviceDateTime,
utcStartTime,utcEndTime)) {
return true;
}
}
}
return false;
}
bool _currentDateTimeIsUnderHolidayList(DateTime currentDeviceDateTime){
for (final BankHolidayModel bankHolidayModel in getBankHolidayList()) {
if (doesLiesBetween(currentDeviceDateTime,
bankHolidayModel.startTime, bankHolidayModel.endTime) ) {
return true;
}
}
return false;
}
bool doesLiesBetween(DateTime dateToCheck,
DateTime startDateTime, DateTime endDateTime){
if ((dateToCheck.isAfter(startDateTime)
&& dateToCheck.isBefore(endDateTime))
|| dateToCheck.isAtSameMomentAs(startDateTime)
|| dateToCheck.isAtSameMomentAs(endDateTime) ) {
return true;
}
return false;
}
class BusinessHourModel {
final int day;
final TimeOfDay startTime;
final TimeOfDay endTime;
BusinessHourModel(
{this.day, this.startTime, this.endTime});
DateTime getStartDateTime(DateTime currentDateTime) {
final DateTime startDateTime = DateTime.utc(
currentDateTime.year,
currentDateTime.month,
currentDateTime.day,
startTime.hour,
startTime.minute);
return startDateTime;
}
DateTime getEndDateTime(DateTime currentDateTime) {
final DateTime endDateTime = DateTime.utc(
currentDateTime.year,
currentDateTime.month,
currentDateTime.day,
endTime.hour,
endTime.minute);
return endDateTime;
}
}
class BankHolidayModel {
final String nameOfHoliday;
final String description;
final DateTime startTime;
final DateTime endTime;
BankHolidayModel(
{this.nameOfHoliday, this.description, @required this.startTime,
@required this.endTime});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment