getSchemaBuilder()->hasTable('share_system_state') ? DB::table('share_system_state')->where('key', self::DAILY_FROM_KEY)->value('value') : null; } public static function forDate(string $date, ?string $dailyFrom): string { return $dailyFrom !== null && $date >= $dailyFrom ? $date : substr($date, 0, 7); } /** Inclusive start and exclusive end, both in Beijing. */ public static function bounds(string $period, ?string $dailyFrom): array { if (strlen($period) === 10) { return [$period, CarbonImmutable::parse($period, self::TIMEZONE)->addDay()->toDateString()]; } $start = $period . '-01'; $end = CarbonImmutable::parse($start, self::TIMEZONE)->addMonth()->toDateString(); return [$start, $dailyFrom === null ? $end : max($start, min($end, $dailyFrom))]; } public static function waitsForSettlement(string $period, ?string $dailyFrom): bool { return strlen($period) === 10 || ($dailyFrom !== null && $period === substr($dailyFrom, 0, 7)); } }