NAME

Protobuf::WKT::Timestamp - Mixin for google.protobuf.Timestamp

VERSION

version 0.04

SYNOPSIS

# In your .proto
import "google/protobuf/timestamp.proto";

message MyLog {
  google.protobuf.Timestamp event_time = 1;
}

# In your Perl code
use Time::Piece;

my $log = MyLog->new;
my $timestamp = $log->event_time;

# Setting from Time::Piece
my $now = localtime;
$timestamp->from_time_piece($now);

# Getting a Time::Piece object
my $tp = $timestamp->to_time_piece();
print $tp->strftime("%Y-%m-%d %H:%M:%S"), "
";

# Getting ISO 8601 string
my $iso_string = $timestamp->to_iso8601(); # e.g., "2026-04-01T12:00:00Z"

DESCRIPTION

This module provides helper methods for the generated class corresponding to the google.protobuf.Timestamp Well-Known Type. These methods are injected into the Protobuf::WKT::Timestamp class, which should be automatically used when google/protobuf/timestamp.proto is processed.

The Timestamp type represents a point in time independent of any time zone or calendar, encoded as seconds and nanoseconds since the Unix epoch.

METHODS

to_time_piece()

Converts the timestamp to a Time::Piece object. Note that nanos are not fully supported by Time::Piece, so precision may be lost.

from_time_piece($tp)

Sets the seconds and nanos fields from a Time::Piece object $tp. nanos will be set to 0.

Returns $self for chaining.

to_iso8601()

Returns an ISO 8601 string representation of the timestamp in UTC (e.g., "2026-04-01T12:00:00Z"). This uses Time::Piece internally, so nanosecond precision is lost.

get_injected_methods()

Internal method used by Protobuf::ClassGenerator to list methods to inject into the class.

SEE ALSO

Protobuf, Protobuf::Message, Time::Piece

AUTHOR

C.J. Collier <cjac@google.com>

COPYRIGHT AND LICENSE

This software is copyright (c) 2026 by Google LLC.

This is free software; you can redistribute it and/or modify it under the terms of the BSD 3-Clause License.