🎨 Add Include time switch to database creation time field and update time field https://github.com/siyuan-note/siyuan/issues/12091

Signed-off-by: Daniel <845765@qq.com>
This commit is contained in:
Daniel 2025-11-07 21:25:03 +08:00
parent 75da247b23
commit 0bea01ad3b
No known key found for this signature in database
GPG key ID: 86211BA83DF03017
8 changed files with 262 additions and 37 deletions

View file

@ -370,6 +370,12 @@ func fillAttributeViewAutoGeneratedValues(attrView *av.AttributeView, collection
}
}
case av.KeyTypeCreated: // 渲染创建时间
key, _ := attrView.GetKey(value.KeyID)
isNotTime := false
if nil != key && nil != key.Created {
isNotTime = !key.Created.IncludeTime
}
ial := map[string]string{}
block := item.GetBlockValue()
if nil != block {
@ -385,12 +391,18 @@ func fillAttributeViewAutoGeneratedValues(attrView *av.AttributeView, collection
createdStr := id[:len("20060102150405")]
created, parseErr := time.ParseInLocation("20060102150405", createdStr, time.Local)
if nil == parseErr {
value.Created = av.NewFormattedValueCreated(created.UnixMilli(), 0, av.CreatedFormatNone)
value.Created = av.NewFormattedValueCreated(created.UnixMilli(), 0, av.CreatedFormatNone, isNotTime)
value.Created.IsNotEmpty = true
} else {
value.Created = av.NewFormattedValueCreated(time.Now().UnixMilli(), 0, av.CreatedFormatNone)
value.Created = av.NewFormattedValueCreated(time.Now().UnixMilli(), 0, av.CreatedFormatNone, isNotTime)
}
case av.KeyTypeUpdated: // 渲染更新时间
key, _ := attrView.GetKey(value.KeyID)
isNotTime := false
if nil != key && nil != key.Updated {
isNotTime = !key.Updated.IncludeTime
}
ial := map[string]string{}
block := item.GetBlockValue()
if nil != block {
@ -401,15 +413,15 @@ func fillAttributeViewAutoGeneratedValues(attrView *av.AttributeView, collection
}
updatedStr := ial["updated"]
if "" == updatedStr && nil != block {
value.Updated = av.NewFormattedValueUpdated(block.Block.Updated, 0, av.UpdatedFormatNone)
value.Updated = av.NewFormattedValueUpdated(block.Block.Updated, 0, av.UpdatedFormatNone, isNotTime)
value.Updated.IsNotEmpty = true
} else {
updated, parseErr := time.ParseInLocation("20060102150405", updatedStr, time.Local)
if nil == parseErr {
value.Updated = av.NewFormattedValueUpdated(updated.UnixMilli(), 0, av.UpdatedFormatNone)
value.Updated = av.NewFormattedValueUpdated(updated.UnixMilli(), 0, av.UpdatedFormatNone, isNotTime)
value.Updated.IsNotEmpty = true
} else {
value.Updated = av.NewFormattedValueUpdated(time.Now().UnixMilli(), 0, av.UpdatedFormatNone)
value.Updated = av.NewFormattedValueUpdated(time.Now().UnixMilli(), 0, av.UpdatedFormatNone, isNotTime)
}
}
}