Vercel News

Timestamp attributes are now supported in Vercel Flags

6.7内容质量

TL;DR · AI 摘要

Timestamp attributes are now supported in Vercel Flags - Vercel Vercel Flags now supports timestamp attributes, so you c...

核心要点

  • 主题聚焦:Timestamp attributes are now supported in Vercel
  • 来源:Vercel News,建议结合原文判断细节。
  • AI 分析暂不可用,本条为保底评分与摘要。
#AI#编程#产品
打开原文

Vercel Flags 现在支持时间戳属性 - Vercel

Vercel Flags 现在支持时间戳属性,因此您可以按日期和时间定位实体。

使用时间戳属性仅在两个日期之间显示活动页面、运行黑色星期五促销活动,或定位在截止日期前注册的用户。

复制链接到标题 配置时间戳属性

您可以通过仪表板或通过 CLI 配置时间戳属性。

在 Vercel 仪表板中,打开 Flags,选择 Entities,然后创建或选择一个实体。添加一个属性并将其数据类型设置为 timestamp。

配置为时间戳的系统实体。

或者通过 CLI 定义属性:

code
# 在新实体上
vercel flags entities create system
--label
System
\
--attribute
time:timestamp
# 在现有实体上
vercel flags entities update system --add-attribute time:timestamp

通过 Vercel CLI 定义时间戳属性。

无论您是在仪表板还是 CLI 中配置属性,当评估标志时,您的应用程序都必须提供其值。实体和属性名称必须与您的配置匹配,且值必须是毫秒级的 Unix 时间戳。

以下 Flags SDK 示例在评估标志时将当前时间作为 system.time 传递。Date.now() 返回以毫秒为单位的所需值。将其保留在 dedupe() 内部可确保同一请求期间评估的所有标志使用相同的时间:

code
1
import
{
dedupe
,
flag
}
from
'flags/next'
;
2
import
{
vercelAdapter
}
from
'@flags-sdk/vercel'
;
3
4
type
Entities
=
{
5
system
:
{
6
time
:
number
;
7
}
;
8
}
;
9
10
const
identify
=
dedupe
(
async
(
)
:
Promise
<
Entities
>
=>
(
{
11
system
:
{
12
time
:
Date
.
now
(
)
,
13
}
,
14
}
)
)
;
15
16
export
const
promotion
=
flag
<
boolean
,
Entities
>
(
{
17
key
:
'promotion'
,
18
adapter
:
vercelAdapter
(
)
,
19
identify
,
20
}
)
;

在评估标志时将当前时间作为时间戳属性传递。

复制链接到标题 添加定位规则

在仪表板中,打开标志并使用时间戳属性添加定位规则。该规则将您的应用程序中的值与您选择的日期和时间进行比较。

规则支持“在...之后”、“在...或之后”、“在...之前”和“在...或之前”。日期和时间选择器使用您的本地时区。

在两个日期之间提供“On”变体的规则。

要通过 CLI 添加基于时间的定位规则,请使用 after、at-or-after、before 或 at-or-before:

code
vercel flags rules
add
promotion
--environment
production
\
--condition
system.time:at-or-after:2026-09-02T13:00:00Z
\
--condition
system.time:before:2026-09-16T22:00:00Z
\
--variant
on

通过 Vercel CLI 向标志添加日期范围。

了解如何在代码中提供实体并在特定时间发布标志,或阅读 Flags 文档。