Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to represent date type in apache thrift

Tags:

date

types

thrift

I'm developing a service using apache thrift and I need to define periods of time. Dates are significant (YYYY-mm-dd) and time should be totally omitted (HH:ii:ss). I couldn't find any specific date/datetime thrift data type so I'm thinking about two approaches:

  1. more complex

    int year,
    int month,
    int day,
    
  2. less complex but includes time of day part which I don't need.

    int timestamp
    

Is there a common thrift approach to represent date(time) types?

like image 361
ducin Avatar asked Mar 24 '13 20:03

ducin


People also ask

What is Thrift type?

The Thrift type system is intended to allow programmers to use native types as much as possible, no matter what programming language they are working in. This information is based on, and supersedes, the information in the Thrift Whitepaper.

What is Thrift binary?

Thrift is an interface definition language and binary communication protocol used for defining and creating services for numerous programming languages. It was developed at Facebook for "scalable cross-language services development" and as of 2020 is an open source project in the Apache Software Foundation.

Does Facebook still use Thrift?

Since then, usage of Thrift at Facebook has continued to grow. Today, it powers more than 100 services used in production, most of which are written in C++, Java, PHP, or Python.


2 Answers

I don't think there is a date representation on Thrift IDL. We use this notation for our projects.

typedef string Timestamp

then use that notation on subsequent model which needs a timestamp usage like this

struct blah{

    /**
    * TODO:list what notation this dateTime represents. eg ISO-8601
    * or if its in the format like YYYY-mm-DD you mentioned.
    */
    1:Timestamp dateTime;

    }

String makes it easier to use JODA Operations

--EDIT--

I don't know what timestamp you intend to store. For instance if you want to calculate current instance a transaction has occurred and store it into that thrift object, you can do this with Joda.

    String timestamp = new DateTime().toString("YYYY-MM-dd"); //2013-03-26 This will be string value generated. It will convert the current time to format you seek to output.
    //Use the generated thrift object.
    Blah newblah = new Blah();
    blah.setDateTime(timestamp);
like image 196
Venki Avatar answered Nov 30 '22 09:11

Venki


I'm not aware of some specific format preference. I usually use decimal encoded date representation, since it's quite compact and human-readable, like this: 20130325

like image 21
Wildfire Avatar answered Nov 30 '22 07:11

Wildfire