问题
Has anyone had to update a Duraton
field from within a plugin?
On the UI it is fairly intelligent, you can type
5 minutes
7 //defaults to minutes
3 hours
And it will workout what you need.
Assuming the field is called new_foo
, what value should I assign? Int?
var e = new Entity("new_bar");
e.Attributes("new_foo", 5);//5 minutes?
Double?
var e = new Entity("new_bar");
e.Attributes("new_foo", 5.00);//5 minutes?
Other ideas?
回答1:
Duration
is a format for the Whole Number
type, so by code you need to set an Int32
value (in this case not negative or it will throw an exception)
The value is always considered in minutes, so if you want to put 3 hours you need to set the field value to 180 (60 minutes x 3 hours), 1 day is 1440 (60 minutes x 24 hours) and so on.
By interface you can set using decimals, but it's always a representation of an integer value (for example 1.5 hours equals 90 minutes)
来源:https://stackoverflow.com/questions/16148303/updating-a-duration-field-by-plugin