1/*
2Copyright (c) 2016 VMware, Inc. All Rights Reserved.
3
4Licensed under the Apache License, Version 2.0 (the "License");
5you may not use this file except in compliance with the License.
6You may obtain a copy of the License at
7
8    http://www.apache.org/licenses/LICENSE-2.0
9
10Unless required by applicable law or agreed to in writing, software
11distributed under the License is distributed on an "AS IS" BASIS,
12WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13See the License for the specific language governing permissions and
14limitations under the License.
15*/
16
17package object
18
19import (
20	"context"
21	"time"
22
23	"github.com/vmware/govmomi/vim25"
24	"github.com/vmware/govmomi/vim25/methods"
25	"github.com/vmware/govmomi/vim25/types"
26)
27
28type HostDateTimeSystem struct {
29	Common
30}
31
32func NewHostDateTimeSystem(c *vim25.Client, ref types.ManagedObjectReference) *HostDateTimeSystem {
33	return &HostDateTimeSystem{
34		Common: NewCommon(c, ref),
35	}
36}
37
38func (s HostDateTimeSystem) UpdateConfig(ctx context.Context, config types.HostDateTimeConfig) error {
39	req := types.UpdateDateTimeConfig{
40		This:   s.Reference(),
41		Config: config,
42	}
43
44	_, err := methods.UpdateDateTimeConfig(ctx, s.c, &req)
45	return err
46}
47
48func (s HostDateTimeSystem) Update(ctx context.Context, date time.Time) error {
49	req := types.UpdateDateTime{
50		This:     s.Reference(),
51		DateTime: date,
52	}
53
54	_, err := methods.UpdateDateTime(ctx, s.c, &req)
55	return err
56}
57
58func (s HostDateTimeSystem) Query(ctx context.Context) (*time.Time, error) {
59	req := types.QueryDateTime{
60		This: s.Reference(),
61	}
62
63	res, err := methods.QueryDateTime(ctx, s.c, &req)
64	if err != nil {
65		return nil, err
66	}
67
68	return &res.Returnval, nil
69}
70