NAME
Wikibase::Datatype::Struct::Value::Time - Wikibase time value structure serialization.
SYNOPSIS
my
$struct_hr
= obj2struct(
$obj
,
$base_uri
);
my
$obj
= struct2obj(
$struct_hr
);
DESCRIPTION
This conversion is between objects defined in Wikibase::Datatype and structures serialized via JSON to MediaWiki.
SUBROUTINES
obj2struct
my
$struct_hr
= obj2struct(
$obj
,
$base_uri
);
Convert Wikibase::Datatype::Value::Time instance to structure. $base_uri
is base URI of Wikibase system (e.g. http://test.wikidata.org/entity/).
Returns reference to hash with structure.
struct2obj
my
$obj
= struct2obj(
$struct_hr
);
Convert structure of time to object.
Returns Wikibase::Datatype::Value::Time instance.
ERRORS
obj2struct():
Base URI is required.
Object doesn't exist.
Object isn
't '
Wikibase::Datatype::Value::Time'.
struct2obj():
Structure isn
't for '
time
' datatype.
EXAMPLE1
use
strict;
use
warnings;
use
Data::Printer;
# Object.
my
$obj
= Wikibase::Datatype::Value::Time->new(
'precision'
=> 10,
'value'
=>
'+2020-09-01T00:00:00Z'
,
);
# Get structure.
# Dump to output.
p
$struct_hr
;
# Output:
# \ {
# type "time",
# value {
# after 0,
# before 0,
# calendarmodel "http://test.wikidata.org/entity/Q1985727",
# precision 10,
# time "+2020-09-01T00:00:00Z",
# timezone 0
# }
# }
EXAMPLE2
use
strict;
use
warnings;
# Time structure.
my
$struct_hr
= {
'type'
=>
'time'
,
'value'
=> {
'after'
=> 0,
'before'
=> 0,
'precision'
=> 10,
'time'
=>
'+2020-09-01T00:00:00Z'
,
'timezone'
=> 0,
},
};
# Get object.
my
$obj
= struct2obj(
$struct_hr
);
# Get calendar model.
my
$calendarmodel
=
$obj
->calendarmodel;
# Get precision.
my
$precision
=
$obj
->precision;
# Get type.
my
$type
=
$obj
->type;
# Get value.
my
$value
=
$obj
->value;
# Print out.
"Calendar model: $calendarmodel\n"
;
"Precision: $precision\n"
;
"Type: $type\n"
;
"Value: $value\n"
;
# Output:
# Calendar model: Q1985727
# Precision: 10
# Type: time
# Value: +2020-09-01T00:00:00Z
DEPENDENCIES
Error::Pure, Exporter, Readonly, URL, Wikibase::Datatype::Value::Time.
SEE ALSO
- Wikibase::Datatype::Struct
-
Wikibase structure serialization.
- Wikibase::Datatype::Value::Time
-
Wikibase time value datatype.
REPOSITORY
https://github.com/michal-josef-spacek/Wikibase-Datatype-Struct
AUTHOR
Michal Josef Špaček mailto:skim@cpan.org
LICENSE AND COPYRIGHT
© 2020-2025 Michal Josef Špaček
BSD 2-Clause License
VERSION
0.14