Hi,
I have a field called bookedDated which stores a list of dates that the user is booked. Now I am trying to make a Dynamic UI change based on if the user is available or not based on the current date. To make the UI change, I need to check the list from the database to see if the current date exists.
I noticed that in firebase it saves the dates in the following manner: July 26, 2024 at 12:00:00โฏAM UTC+4
So I created a custom function that takes the current date time and converts it into 12:00:00 AM with the help of ChatGPT. This is my code:
import 'dart:convert';
import 'dart:math' as math;
import 'package:flutter/material.dart';
import 'package:google_fonts/google_fonts.dart';
import 'package:intl/intl.dart';
import 'package:timeago/timeago.dart' as timeago;
import '/flutter_flow/lat_lng.dart';
import '/flutter_flow/place.dart';
import '/flutter_flow/uploaded_file.dart';
import '/flutter_flow/custom_functions.dart';
import '/backend/backend.dart';
import 'package:cloud_firestore/cloud_firestore.dart';
import '/backend/schema/structs/index.dart';
import '/auth/firebase_auth/auth_util.dart';
DateTime? getCurrentDateAtMidnightUTC4() {
/// MODIFY CODE ONLY BELOW THIS LINE
// Get the current date and time
// Get the current date and time
DateTime now = DateTime.now();
// Convert to UTC+4 by adding 4 hours to the current time
DateTime utc4Time = now.toUtc().add(Duration(hours: 4));
// Set the time to 12:00:00 AM
DateTime utc4Midnight =
DateTime.utc(utc4Time.year, utc4Time.month, utc4Time.day, 0, 0, 0)
.add(Duration(hours: 4));
return utc4Midnight;
/// MODIFY CODE ONLY ABOVE THIS LINE
}