You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

在Foundry中设置对象Timestamp属性报错,求正确实现方法

Foundry函数设置Timestamp属性报错:r.getTime is not a function

问题场景

给Foundry对象的Timestamp属性赋值时触发错误,代码写法:

object.timeProperty = {type: 'Timestamp', dateTime: '2023-08-18T09:50:21.385Z'}

错误栈信息:

r.getTime is not a function.
Error Parameters: {}
TypeError: r.getTime is not a function
at Function.convertToPhonographTypeV2 (FunctionsFunctionsIsolateRuntimePackagePackage:84:23715)
at t.TypeConvertingPropertyStore.convertToPhonographType (FunctionsFunctionsIsolateRuntimePackagePackage:362:6183)
at t.TypeConvertingPropertyStore.set (FunctionsFunctionsIsolateRuntimePackagePackage:362:5943)
at t.DefaultObjectStorageProvider.setPropertyValue (FunctionsFunctionsIsolateRuntimePackagePackage:100:35067)
at t.MetricRecordingObjectStorageProvider.setPropertyValue (FunctionsFunctionsIsolateRuntimePackagePackage:322:9326)
at t.OntologyAccessRecordingObjectStorageProvider.setPropertyValue (FunctionsFunctionsIsolateRuntimePackagePackage:325:701)
at Proxy.setPropertyValue (FunctionsFunctionsIsolateRuntimePackagePackage:325:3257)
at set commentTime [as commentTime] (OntologyObjectFactory:13:10868)
at UserCode:22:33724
at Array.forEach ()

问题根源

你构造的自定义对象不符合Foundry Timestamp属性的要求。底层类型转换逻辑期望接收原生JavaScript Date对象,而不是你手动创建的带type和dateTime字段的对象——你的自定义对象没有getTime方法,这才触发了报错。

修复方案

直接传入原生Date对象即可,Foundry会自动完成内部类型转换:

  • 从ISO时间字符串构建Date对象:
    object.timeProperty = new Date('2023-08-18T09:50:21.385Z');
    
  • 若要设置当前时间,直接调用无参构造:
    // object.timeProperty = new Date();
    

内容的提问来源于stack exchange,提问作者harsh2702

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.13 07:10:28