getEmojiDayOrNight static method
Returns sunEmoji if the given hour is between 8am (exclusive of 7am) and 5pm (exclusive of 6pm), otherwise returns moonEmoji.
Returns null
if tzHour
is null or in case of any error during processing, logging the error.
Example:
TimeEmojiUtils.getEmojiDayOrNight(10); // Returns '☀️' (for 10am)
TimeEmojiUtils.getEmojiDayOrNight(20); // Returns '🌙' (for 8pm)
TimeEmojiUtils.getEmojiDayOrNight(null); // Returns null
Implementation
static String? getEmojiDayOrNight(int? tzHour) {
if (tzHour == null) {
return null;
}
return tzHour > 7 && tzHour < 18
// sun emoji for hours between 8am and 5pm (exclusive of 7am and 6pm)
? sunEmoji
// moon emoji for hours outside the 8am-5pm range
: moonEmoji;
}