babalae/better-genshin-impact · warning · ArgumentException

无效的小时值: {hour},必须是 0-24 之间的整数字符

Error message

无效的小时值: {hour},必须是 0-24 之间的整数字符

What it means

Thrown by the int overload of SetTime when hour is outside the inclusive range [0, 24]. The game's time-adjustment UI supports hours 0 through 24 (24 meaning next-day midnight). Values outside this range are meaningless for the in-game clock.

Source

Thrown at BetterGenshinImpact/Core/Script/Dependence/Genshin.cs:498

    /// 进出千星奇域
    /// </summary>
    /// <returns></returns>
    public async Task WonderlandCycle()
    {
        await new EnterAndExitWonderlandJob().Start(CancellationContext.Instance.Cts.Token);
    }

    /// <summary>
    /// 调整时间
    /// </summary>
    /// <param name="hour">目标小时(0-24)</param>
    /// <param name="minute">目标分钟(0-59)</param>
    /// <param name="skip">是否跳过动画(默认为否)</param>
    /// <returns></returns>
    public async Task SetTime(int hour, int minute, bool skip = false)
    {
        if ( hour < 0 || hour > 24)
            throw new ArgumentException($"无效的小时值: {hour},必须是 0-24 之间的整数字符", nameof(hour));
        if (minute < 0 || minute > 59)
            throw new ArgumentException($"无效的分钟值: {minute},必须是 0-59 之间的整数字符", nameof(minute));
        await new SetTimeTask().Start(hour, minute, CancellationContext.Instance.Cts.Token, skip);
    }
    
    /// <summary>
    /// 调整时间
    /// </summary>
    /// <param name="hour">目标小时(0-24的字符类型)</param>
    /// <param name="minute">目标分钟(0-59的字符类型)</param>
    /// <param name="skip">是否跳过动画(默认为否)</param>
    /// <returns></returns>
    public async Task SetTime(string hour, string minute, bool skip = false)
    {
        if (!int.TryParse(hour, out var h) || h < 0 || h > 24)
            throw new ArgumentException($"无效的小时值: {hour},必须是 0-24 之间的整数字符", nameof(hour));
        if (!int.TryParse(minute, out var m) || m < 0 || m > 59)
            throw new ArgumentException($"无效的分钟值: {minute},必须是 0-59 之间的整数字符", nameof(minute));

View on GitHub (pinned to a7cb36712d)

Solutions

  1. Clamp hour to [0, 24] before calling SetTime.
  2. Use modulo: hour = ((hour % 24) + 24) % 24 if you want wrap-around.
  3. Validate the value in your script logic and log a warning if it falls outside range.
  4. Switch to the string overload only if you need string parsing; it performs the same range check.

Example fix

// before
genshin.SetTime(computedHour, computedMinute);

// after
var safeHour = Math.Clamp(computedHour, 0, 24);
var safeMinute = Math.Clamp(computedMinute, 0, 59);
genshin.SetTime(safeHour, safeMinute);
Defensive patterns

Strategy: validation

Validate before calling

// Validate hour range before calling SetTime
if (hour < 0 || hour > 24)
    throw new ArgumentOutOfRangeException(nameof(hour), hour, "Hour must be 0-24");
genshin.SetTime(hour, minute);

Prevention

When it happens

Trigger: Calling genshin.SetTime(hour, minute) with hour < 0 or hour > 24. Common with off-by-one bugs (e.g., 25), negative values from arithmetic, or incorrect dynamic calculation from DateTime.

Common situations: Script computes hour from a formula or external data source and passes an unclamped value. Misunderstanding the range as 0-23 (24-hour clock) instead of 0-24 inclusive.

Related errors


AI-assisted analysis of babalae/better-genshin-impact@a7cb36712d (2026-08-13). Data as JSON: /api/errors/7fd826c3e0794846. Report an issue: GitHub.