// Path: contrib/grpc-contrib/src/main/java/com/salesforce/grpc/contrib/MoreTimestamps.java
// public final class MoreTimestamps {
//     private MoreTimestamps() {
//         // private static constructor
//     }
// 
//     public static Instant toInstantUtc(@Nonnull Timestamp timestamp) {
//         checkNotNull(timestamp, "timestamp");
//         return Instant.ofEpochSecond(timestamp.getSeconds(), timestamp.getNanos());
//     }
// 
//     public static OffsetDateTime toOffsetDateTimeUtc(@Nonnull Timestamp timestamp) {
//         checkNotNull(timestamp, "timestamp");
//         return toInstantUtc(timestamp).atOffset(ZoneOffset.UTC);
//     }
// 
//     public static ZonedDateTime toZonedDateTimeUtc(@Nonnull Timestamp timestamp) {
//         checkNotNull(timestamp, "timestamp");
//         return toOffsetDateTimeUtc(timestamp).toZonedDateTime();
//     }
// 
//     public static Timestamp fromInstantUtc(@Nonnull Instant instant) {
//         checkNotNull(instant, "instant");
//         return Timestamp.newBuilder()
//                 .setSeconds(instant.getEpochSecond())
//                 .setNanos(instant.getNano())
//                 .build();
//     }
// 
//     public static Timestamp fromOffsetDateTimeUtc(@Nonnull OffsetDateTime offsetDateTime) {
//         checkNotNull(offsetDateTime, "offsetDateTime");
//         return fromInstantUtc(offsetDateTime.toInstant());
//     }
// 
//     public static Timestamp fromZonedDateTimeUtc(@Nonnull ZonedDateTime zonedDateTime) {
//         checkNotNull(zonedDateTime, "zonedDateTime");
//         return fromOffsetDateTimeUtc(zonedDateTime.toOffsetDateTime());
//     }
// }


import com.google.protobuf.Empty;
import com.google.protobuf.Timestamp;
import com.salesforce.grpc.contrib.MoreTimestamps;
import com.salesforce.grpc.contrib.spring.GrpcService;
import com.salesforce.servicelibs.TimeReply;
import com.salesforce.servicelibs.TimeServiceGrpc;
import io.grpc.stub.StreamObserver;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.time.Instant;
/*
 *  Copyright (c) 2019, Salesforce.com, Inc.
 *  All rights reserved.
 *  Licensed under the BSD 3-Clause license.
 *  For full license text, see LICENSE.txt file in the repo root  or https://opensource.org/licenses/BSD-3-Clause
 */

package com.salesforce.servicelibs.timeserver;



/**
 * Implements TimeService.proto.
 */
@GrpcService
public class TimeServiceImpl extends TimeServiceGrpc.TimeServiceImplBase {
    private final Logger logger = LoggerFactory.getLogger(TimeServiceImpl.class);

    @Override
    public void getTime(Empty request, StreamObserver<TimeReply> responseObserver) {
        // JDK8 type
        Instant now = Instant.now();
        logger.info("Reporting the time " + now);

        // Protobuf type
// Path: contrib/grpc-contrib/src/main/java/com/salesforce/grpc/contrib/MoreTimestamps.java
// public final class MoreTimestamps {
//     private MoreTimestamps() {
//         // private static constructor
//     }
// 
//     public static Instant toInstantUtc(@Nonnull Timestamp timestamp) {
//         checkNotNull(timestamp, "timestamp");
//         return Instant.ofEpochSecond(timestamp.getSeconds(), timestamp.getNanos());
//     }
// 
//     public static OffsetDateTime toOffsetDateTimeUtc(@Nonnull Timestamp timestamp) {
//         checkNotNull(timestamp, "timestamp");
//         return toInstantUtc(timestamp).atOffset(ZoneOffset.UTC);
//     }
// 
//     public static ZonedDateTime toZonedDateTimeUtc(@Nonnull Timestamp timestamp) {
//         checkNotNull(timestamp, "timestamp");
//         return toOffsetDateTimeUtc(timestamp).toZonedDateTime();
//     }
// 
//     public static Timestamp fromInstantUtc(@Nonnull Instant instant) {
//         checkNotNull(instant, "instant");
//         return Timestamp.newBuilder()
//                 .setSeconds(instant.getEpochSecond())
//                 .setNanos(instant.getNano())
//                 .build();
//     }
// 
//     public static Timestamp fromOffsetDateTimeUtc(@Nonnull OffsetDateTime offsetDateTime) {
//         checkNotNull(offsetDateTime, "offsetDateTime");
//         return fromInstantUtc(offsetDateTime.toInstant());
//     }
// 
//     public static Timestamp fromZonedDateTimeUtc(@Nonnull ZonedDateTime zonedDateTime) {
//         checkNotNull(zonedDateTime, "zonedDateTime");
//         return fromOffsetDateTimeUtc(zonedDateTime.toOffsetDateTime());
//     }
// }


// Path: demos/grpc-java-contrib-demo/time-service-demo/src/main/java/com/salesforce/servicelibs/timeserver/TimeServiceImpl.java
import com.google.protobuf.Empty;
import com.google.protobuf.Timestamp;
import com.salesforce.grpc.contrib.MoreTimestamps;
import com.salesforce.grpc.contrib.spring.GrpcService;
import com.salesforce.servicelibs.TimeReply;
import com.salesforce.servicelibs.TimeServiceGrpc;
import io.grpc.stub.StreamObserver;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.time.Instant;

/*
 *  Copyright (c) 2019, Salesforce.com, Inc.
 *  All rights reserved.
 *  Licensed under the BSD 3-Clause license.
 *  For full license text, see LICENSE.txt file in the repo root  or https://opensource.org/licenses/BSD-3-Clause
 */

package com.salesforce.servicelibs.timeserver;



/**
 * Implements TimeService.proto.
 */
@GrpcService
public class TimeServiceImpl extends TimeServiceGrpc.TimeServiceImplBase {
    private final Logger logger = LoggerFactory.getLogger(TimeServiceImpl.class);

    @Override
    public void getTime(Empty request, StreamObserver<TimeReply> responseObserver) {
        // JDK8 type
        Instant now = Instant.now();
        logger.info("Reporting the time " + now);

        // Protobuf type
        Timestamp protoNow = MoreTimestamps.fromInstantUtc(now);