NAME
    RDF::Query::Functions::Buzzword::DateTime - plugin for buzzword.org.uk
    datetime functions

SYNOPSIS
    TODO - update synopsis

      use RDF::TrineShortcuts qw[:all];
      use Data::Dumper;
  
      my $data = rdf_parse(<<'TURTLE', type=>'turtle');
      @prefix foaf: <http://xmlns.com/foaf/0.1/> .
      @prefix rdf:  <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
      @prefix xsd:  <http://www.w3.org/2001/XMLSchema#> .

      <http://tobyinkster.co.uk/#i>
        foaf:birthday "1980-06-01"^^xsd:date .
      TURTLE

      $r = rdf_query(<<'SPARQL', $data);
      PREFIX foaf: <http://xmlns.com/foaf/0.1/>
      PREFIX dt:   <http://buzzword.org.uk/2011/functions/datetime#>
      PREFIX xsd:  <http://www.w3.org/2001/XMLSchema#>
      SELECT
        (dt:now() AS ?now)
        (dt:today() AS ?today)
        ?bday
        (dt:format_duration(
          dt:difference(dt:now(), ?bday),
          "%Y years, %m months")
          AS ?age)
        (dt:add(?bday, "P10Y"^^xsd:duration) AS ?tenthbday)
        (dt:strftime(?bday, "%a, %d %b %Y"@en) AS ?fmtbday)
        (dt:strtodate("1/6/1980"@en-us) AS ?guessamericandate)
        (dt:strtodate("1/6/1980"@en) AS ?guessenglishdate)
      WHERE
      {
        ?person foaf:birthday ?bday .
      }
      SPARQL
  
      print Dumper(flatten_iterator($r, literal_as=>'ntriples'));

DESCRIPTION
    This is a plugin for RDF::Query providing a number of extension
    functions.

    *   http://buzzword.org.uk/2011/functions/datetime#add

        Given an xsd:dateTime or xsd:date, and an xsd:duration, adds the
        duration to the datetime. Returns an xsd:date if it was passed an
        xsd:date and the xsd:duration didn't specify any hours, minutes or
        seconds. Returns an xsd:dateTime otherwise.

    *   http://buzzword.org.uk/2011/functions/datetime#difference

        Given two xsd:dateTime or xsd:date literals, returns an xsd:duration
        representing the difference between them.

    *   http://buzzword.org.uk/2011/functions/datetime#format_duration

        Given an xsd:duration and a literal formatting string, returns a
        formatted duration. See DateTime::Format::Duration.

    *   http://buzzword.org.uk/2011/functions/datetime#now

        Returns the current xsd:dateTime, with supposed nanosecond
        precision. If called multiple times in the same SPARQL query, will
        always return the same instant.

    *   http://buzzword.org.uk/2011/functions/datetime#strftime

        Takes a xsd:datetime and a literal formatting string and returns a
        formattted date. See DateTime.

    *   http://buzzword.org.uk/2011/functions/datetime#strtodate

        Attempts to parse an arbitrary literal using natural language and
        convert it into an xsd:date. Smart enough to tell the difference
        between "1/6/1980"@en-us and "1/6/1980"@en-gb.

        Can safely be passed an existing xsd:date or xsd:dateTime.

    *   http://buzzword.org.uk/2011/functions/datetime#strtotime

        As per "strtodate" but returns an xsd:dateTime.

        "add", "difference" and "strftime" all implicitly call "strtotime"
        on their xsd:dateTime arguments, which means they don't need to be
        given strict xsd:date/dateTime input.

    *   http://buzzword.org.uk/2011/functions/datetime#today

        Like "now" but returns an xsd:date.

SEE ALSO
    RDF::Query, RDF::Query::Functions::Buzzword::Util.

    DateTime.

    <http://perlrdf.org/>.

AUTHOR
    Toby Inkster <tobyink@cpan.org>.

COPYRIGHT
    Copyright 2011 Toby Inkster

    This library is free software; you can redistribute it and/or modify it
    under the same terms as Perl itself.