DEV Community

AvlCodeMonkey for AvlCodeMonkey Industries

Posted on Originally published at featureflags.app on

Time Window Filters in .NET: Because Nobody Wants to Wake Up at Midnight

Want to launch a feature at 9 AM on Monday? Disable a promotion at midnight on Friday? Enable a feature every evening during off-peak hours?

You could set a reminder, wake up, log in, flip a flag, and wonder why you didn't automate this in the first place. Or you could use the TimeWindowFilter in Microsoft's .NET feature management library.

Let's do the lazy thing.

What Is the Time Window Filter?

The Microsoft.FeatureManagement library includes a built-in TimeWindowFilter that enables a feature based on a configured time window. Instead of manually toggling a flag, you define when it should become active and, optionally, when it should stop being active.

For example:

  • Launch a feature at a specific date and time.
  • Automatically disable a promotion when it expires.
  • Schedule a feature for a planned announcement.
  • Enable functionality during recurring maintenance windows or off-peak periods.

No cron job. No scheduled deployment. No alarm clock. Just a flag with a schedule.

Basic Configuration

First, make sure you've installed the ASP.NET Core package:

dotnet add package Microsoft.FeatureManagement.AspNetCore
Enter fullscreen mode Exit fullscreen mode

Register feature management in Program.cs:

builder.Services.AddFeatureManagement();
Enter fullscreen mode Exit fullscreen mode

Now define a flag in appsettings.json:

{
  "FeatureManagement": {
    "NewDashboard": {
      "EnabledFor": [
        {
          "Name": "Microsoft.TimeWindow",
          "Parameters": {
            "Start": "Fri, 16 Oct 2026 13:00:00 GMT",
            "End": "Fri, 16 Oct 2026 17:00:00 GMT"
          }
        }
      ]
    }
  }
}
Enter fullscreen mode Exit fullscreen mode

This example enables NewDashboard during the specified UTC time window. The feature is off before the window opens and after it closes. Your application code can check the flag as usual:

if (await _featureManager.IsEnabledAsync("NewDashboard"))
{
    // Show the new dashboard
}
Enter fullscreen mode Exit fullscreen mode

The feature management library handles the time-based evaluation. You don't need to write your own date comparisons throughout the application. One less thing to get wrong.

Start and End Times Are Optional

You don't always need both boundaries.

Only Start: The feature becomes eligible to be enabled at the specified time and remains eligible afterward.

Only End: The feature is enabled until the specified time, assuming the flag is otherwise enabled.

Both: The feature is enabled only within the defined time window.

This is handy for everything from scheduled launches to temporary promotions. Just remember that the flag's overall enabled state and its filters still matter. A time window isn't a magic override for every other condition.

Recurring Time Windows

Now for the fun part. What if you want a feature enabled every weekday evening, or every day during a particular maintenance window? The filter supports recurrence rules using Pattern and Range. For example, this configuration repeats a two-hour window every day:

{
  "FeatureManagement": {
    "MaintenanceMode": {
      "EnabledFor": [
        {
          "Name": "Microsoft.TimeWindow",
          "Parameters": {
            "Start": "Fri, 16 Oct 2026 20:00:00 GMT",
            "End": "Fri, 16 Oct 2026 22:00:00 GMT",
            "Recurrence": {
              "Pattern": {
                "Type": "Daily",
                "Interval": 1
              },
              "Range": {
                "Type": "NoEnd"
              }
            }
          }
        }
      ]
    }
  }
}
Enter fullscreen mode Exit fullscreen mode

The window repeats daily, indefinitely. You can also configure weekly patterns, such as every Monday or every other Friday, and specify when the recurrence should stop. A couple of important details:

  • Recurrence requires both Start and End.
  • The initial start time must fit the recurrence pattern.
  • The window duration can't exceed the interval between occurrences.
  • The example uses UTC, so account for time zones and daylight saving time when planning releases.

For the full configuration details, see Microsoft's .NET feature management documentation.

When Should You Use It?

Time window filters are useful whenever the schedule itself determines whether a feature should be active.

Scheduled launches: Prepare a feature in advance and let it become available at launch time.

Promotions: Automatically stop offering a discount when the campaign ends.

Maintenance windows: Enable maintenance functionality during planned periods.

Recurring operations: Activate features during predictable daily or weekly windows.

They're not a replacement for every scheduling system. If you need to execute a background job at a precise time, you still need an appropriate job scheduler. A feature flag controls application behavior. It doesn't magically execute code when the clock strikes twelve.

Managing the Configuration

There's one catch with the appsettings.json approach. Someone has to maintain the configuration. If a launch time changes, you need to update the relevant settings. Depending on your configuration setup, that might involve a deployment or a configuration reload.

That's manageable for a small application. It becomes less fun when non-technical people need to coordinate launches, or when you have multiple environments and several scheduled features. This is where a feature flag management UI helps. You can manage the flags while keeping Microsoft's feature management library responsible for evaluating them in your application.

The Bottom Line

Time window filters let you automate feature availability based on a schedule. Use them to launch features, expire promotions, and manage recurring availability without manually flipping switches.

Just remember:

  • Configure the correct start and end times.
  • Be explicit about time zones.
  • Test your filter configuration.
  • Don't confuse enabling a feature with scheduling a background job.

And if you want a simpler way to manage your .NET feature flags, take a look at FeatureFlags.app.

Automate the toggle. Keep your sleep schedule. Ship the feature.

Top comments (0)