getEmojiDayOrNight static method

String? getEmojiDayOrNight(
  1. int? tzHour
)

Returns sunEmoji if the given hour is during daytime (7am inclusive to 6pm exclusive), otherwise returns moonEmoji.

Daytime range: hour >= dayStartHour (7) and hour < dayEndHour (18). At exactly 7am, sun is shown. At exactly 6pm (18:00), moon is shown.

Returns null if tzHour is null or in case of any error during processing, logging the error.

Example:

TimeEmojiUtils.getEmojiDayOrNight(7);  // Returns '☀️' (7am — start of day)
TimeEmojiUtils.getEmojiDayOrNight(10); // Returns '☀️' (10am)
TimeEmojiUtils.getEmojiDayOrNight(18); // Returns '🌙' (6pm — start of night)
TimeEmojiUtils.getEmojiDayOrNight(20); // Returns '🌙' (8pm)
TimeEmojiUtils.getEmojiDayOrNight(null); // Returns null

Implementation

static String? getEmojiDayOrNight(int? tzHour) {
  if (tzHour == null) {
    return null;
  }

  return tzHour >= dayStartHour && tzHour < dayEndHour ? sunEmoji : moonEmoji;
}