Skip to content

Wrong variables used in example #33857

@sedwick2048

Description

@sedwick2048

Description

In the "Dates and times" section, the example code starts with:

message Meeting {
    string subject = 1;
    google.protobuf.Timestamp start = 2;
    google.protobuf.Duration duration = 3;
}  

But the next code uses Time and Duration for the Meeting instance's properties, when it probably should instead use start and duration:

// Create Timestamp and Duration from .NET DateTimeOffset and TimeSpan.
var meeting = new Meeting
{
    Time = Timestamp.FromDateTimeOffset(meetingTime), // also FromDateTime()
    Duration = Duration.FromTimeSpan(meetingLength)
};

// Convert Timestamp and Duration to .NET DateTimeOffset and TimeSpan.
var time = meeting.Time.ToDateTimeOffset();
var duration = meeting.Duration?.ToTimeSpan();

Correcting this may reduce confusion. Thanks...

Page URL

https://learn.microsoft.com/en-us/aspnet/core/grpc/protobuf?view=aspnetcore-8.0

Content source URL

https://github.com/dotnet/AspNetCore.Docs/blob/main/aspnetcore/grpc/protobuf.md

Document ID

4ce52659-cd0f-0172-2f8c-e58b8497eadc

Article author

@JamesNK

Related Issues

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions