Example usage for org.joda.time DateTimeZone getDefault

List of usage examples for org.joda.time DateTimeZone getDefault

Introduction

In this page you can find the example usage for org.joda.time DateTimeZone getDefault.

Prototype

public static DateTimeZone getDefault() 

Source Link

Document

Gets the default time zone.

Usage

From source file:com.attribyte.relay.wp.PostMeta.java

License:Apache License

@Override
public String toString() {
    return MoreObjects.toStringHelper(this.getClass()).add("id", id)
            .add("lastModifiedMillis", lastModifiedMillis)
            .add("lastModifiedHuman",
                    ISODateTimeFormat.basicDateTime().withZone(DateTimeZone.getDefault())
                            .print(lastModifiedMillis))
            .add("lastModifiedHumanUTC",
                    ISODateTimeFormat.basicDateTime().withZoneUTC().print(lastModifiedMillis))
            .add("fingerprint", fingerprint).toString();
}

From source file:com.ehdev.chronos.lib.Chronos.java

License:Open Source License

@Override
public void onCreate(SQLiteDatabase db, ConnectionSource connectionSource) {

    try {/* w  ww  .jav a  2 s .  com*/
        //Punch
        TableUtils.createTable(connectionSource, Punch.class); //Create Table

        //Task
        TableUtils.createTable(connectionSource, Task.class); //Create Table

        //Job
        TableUtils.createTable(connectionSource, Job.class); //Create Table

        //Job
        TableUtils.createTable(connectionSource, Note.class); //Create Table

        //create basic entries
        Dao<Task, String> taskDAO = getTaskDao();
        Dao<Job, String> jobDAO = getJobDao();

        //Create 1 Job
        DateTime jobMidnight = new DateMidnight().toDateTime().minusWeeks(1)
                .withZone(DateTimeZone.getDefault());
        Log.d(TAG, "start of time:" + jobMidnight);
        Log.d(TAG, "time zone:" + DateTimeZone.getDefault());
        Job currentJob = new Job("", 7.25f, jobMidnight, PayPeriodDuration.TWO_WEEKS);
        currentJob.setDoubletimeThreshold(60);
        currentJob.setOvertimeThreshold(40);
        currentJob.setOvertimeOptions(OvertimeOptions.WEEK);
        jobDAO.create(currentJob);

        Log.d(TAG, "Pay Rate: " + currentJob.getPayRate());

        Task newTask; //Basic element
        newTask = new Task(currentJob, 0, "Regular");
        taskDAO.create(newTask);
        newTask = new Task(currentJob, 1, "Lunch Break");
        newTask.setEnablePayOverride(true);
        newTask.setPayOverride(-7.25f);
        taskDAO.create(newTask);
        newTask = new Task(currentJob, 2, "Other Break");
        newTask.setEnablePayOverride(true);
        newTask.setPayOverride(-7.25f);
        taskDAO.create(newTask);
        newTask = new Task(currentJob, 3, "Travel");
        taskDAO.create(newTask);
        newTask = new Task(currentJob, 4, "Admin");
        taskDAO.create(newTask);
        newTask = new Task(currentJob, 5, "Sick Leave");
        taskDAO.create(newTask);
        newTask = new Task(currentJob, 6, "Personal Time");
        taskDAO.create(newTask);
        newTask = new Task(currentJob, 7, "Other");
        taskDAO.create(newTask);
        newTask = new Task(currentJob, 8, "Holiday Pay");
        taskDAO.create(newTask);

        Log.d(TAG, "Created Elements");

        //Create elements for testing
        //dropAndTest();

    } catch (SQLException e) {
        Log.e(TAG, "Could not create new table for Thing", e);
    }
}

From source file:com.ehdev.chronos.lib.Chronos.java

License:Open Source License

@Override
public void onUpgrade(SQLiteDatabase db, ConnectionSource connectionSource, int oldVersion, int newVersion) {
    try {//from   w  w  w  .  ja  va2s. c o m
        Log.w(TAG, "Upgrading database, this will drop tables and recreate.");
        Log.w(TAG, "oldVerion: " + oldVersion + "\tnewVersion: " + newVersion);

        //Back up database
        try {
            File sd = Environment.getExternalStorageDirectory();
            File data = Environment.getDataDirectory();
            if (sd.canWrite()) {
                String currentDBPath = "/data/com.kopysoft.chronos/databases/" + DATABASE_NAME;
                String backupDBPath = DATABASE_NAME + ".db";
                File currentDB = new File(data, currentDBPath);
                File backupDB = new File(sd, backupDBPath);
                if (currentDB.exists()) {
                    FileChannel src = new FileInputStream(currentDB).getChannel();
                    FileChannel dst = new FileOutputStream(backupDB).getChannel();
                    dst.transferFrom(src, 0, src.size());
                    src.close();
                    dst.close();
                }
            }
        } catch (Exception e) {
            Log.e(TAG, "ERROR: Can not move file");
        }

        /*
        db.execSQL("CREATE TABLE " + TABLE_NAME_CLOCK +
            " ( _id INTEGER PRIMARY KEY NOT NULL, time LONG NOT NULL, actionReason INTEGER NOT NULL )");
        db.execSQL("CREATE TABLE " + TABLE_NAME_NOTE +
            " ( _id LONG PRIMARY KEY, note_string TEXT NOT NULL, time LONG NOT NULL )");
        */

        if (oldVersion < 15) {

            DateTime jobMidnight = DateTime.now().withDayOfWeek(7).minusWeeks(1).toDateMidnight().toDateTime()
                    .withZone(DateTimeZone.getDefault());
            Job currentJob = new Job("", 10, jobMidnight, PayPeriodDuration.TWO_WEEKS);

            SharedPreferences pref = PreferenceManager.getDefaultSharedPreferences(gContext);
            currentJob.setPayRate(Float.valueOf(pref.getString("normal_pay", "7.25")));
            currentJob.setOvertime(Float.valueOf(pref.getString("over_time_threshold", "40")));
            currentJob.setDoubletimeThreshold(Float.valueOf(pref.getString("double_time_threshold", "60")));
            SharedPreferences.Editor edit = pref.edit();
            edit.remove("8_or_40_hours"); //Moved from string to boolean
            edit.commit();
            String date[] = pref.getString("date", "2011.1.17").split("\\p{Punct}");
            jobMidnight = new DateTime(Integer.parseInt(date[0]), Integer.parseInt(date[1]),
                    Integer.parseInt(date[2]), 0, 0);

            currentJob.setStartOfPayPeriod(jobMidnight.withZone(DateTimeZone.getDefault()));

            List<Punch> punches = new LinkedList<Punch>();
            List<Task> tasks = new LinkedList<Task>();
            List<Note> notes = new LinkedList<Note>();

            Task newTask; //Basic element
            newTask = new Task(currentJob, 0, "Regular");
            tasks.add(newTask);
            newTask = new Task(currentJob, 1, "Lunch Break");
            newTask.setEnablePayOverride(true);
            newTask.setPayOverride(-7.25f);
            tasks.add(newTask);
            newTask = new Task(currentJob, 2, "Other Break");
            newTask.setEnablePayOverride(true);
            newTask.setPayOverride(-7.25f);
            tasks.add(newTask);
            newTask = new Task(currentJob, 3, "Travel");
            tasks.add(newTask);
            newTask = new Task(currentJob, 4, "Admin");
            tasks.add(newTask);
            newTask = new Task(currentJob, 5, "Sick Leave");
            tasks.add(newTask);
            newTask = new Task(currentJob, 6, "Personal Time");
            tasks.add(newTask);
            newTask = new Task(currentJob, 7, "Other");
            tasks.add(newTask);
            newTask = new Task(currentJob, 8, "Holiday Pay");
            tasks.add(newTask);

            Cursor cursor = db.query("clockactions", null, null, null, null, null, "_id desc");

            final int colTime = cursor.getColumnIndex("time");
            final int colAR = cursor.getColumnIndex("actionReason");

            if (cursor.moveToFirst()) {
                do {
                    long time = cursor.getLong(colTime);
                    Task type = tasks.get(0);
                    if (colAR != -1) {
                        type = tasks.get(cursor.getInt(colAR));
                    }
                    punches.add(new Punch(currentJob, type, new DateTime(time)));

                } while (cursor.moveToNext());
            }

            if (cursor != null && !cursor.isClosed()) {
                cursor.close();
            }

            cursor = db.query("notes", null, null, null, null, null, "_id desc");

            final int colInsertTime = cursor.getColumnIndex("time");
            final int colText = cursor.getColumnIndex("note_string");

            if (cursor.moveToFirst()) {
                do {
                    long time = cursor.getLong(colInsertTime);
                    String note = cursor.getString(colText);
                    notes.add(new Note(new DateTime(time), currentJob, note));

                } while (cursor.moveToNext());
            }

            if (cursor != null && !cursor.isClosed()) {
                cursor.close();
            }

            db.execSQL("DROP TABLE IF EXISTS clockactions");
            db.execSQL("DROP TABLE IF EXISTS notes");
            db.execSQL("DROP TABLE IF EXISTS misc");

            //Recreate DB
            TableUtils.createTable(connectionSource, Punch.class); //Punch - Create Table
            TableUtils.createTable(connectionSource, Task.class); //Task - Create Table
            TableUtils.createTable(connectionSource, Job.class); //Job - Create Table
            TableUtils.createTable(connectionSource, Note.class); //Task - Create Table

            //recreate entries
            Dao<Task, String> taskDAO = getTaskDao();
            Dao<Job, String> jobDAO = getJobDao();
            Dao<Note, String> noteDAO = getNoteDao();
            Dao<Punch, String> punchDOA = getPunchDao();

            jobDAO.create(currentJob);

            for (Task t : tasks) {
                taskDAO.create(t);
            }

            for (Note n : notes) {
                noteDAO.create(n);
            }

            for (Punch p : punches) {
                punchDOA.create(p);
            }

            //"CREATE TABLE " + TABLE_NAME_NOTE " ( _id LONG PRIMARY KEY, note_string TEXT NOT NULL, time LONG NOT NULL )");
        } else if (oldVersion == 15) {

            //Drop
            //DB - 15
            //TableUtils.dropTable(connectionSource, Punch.class, true); //Punch - Drop all
            //TableUtils.dropTable(connectionSource, Task.class, true); //Task - Drop all
            //TableUtils.dropTable(connectionSource, Job.class, true); //Job - Drop all
            //TableUtils.dropTable(connectionSource, Note.class, true); //Note - Drop all
            Dao<Task, String> taskDAO = getTaskDao();
            List<Task> tasks = taskDAO.queryForAll();

            db.execSQL("DROP TABLE IF EXISTS tasks");

            //create
            TableUtils.createTable(connectionSource, Task.class); //Task - Create Table

            for (Task t : tasks) {
                taskDAO.create(t);
            }
        } else if (oldVersion == 16) {

            //Drop
            //DB - 15
            //TableUtils.dropTable(connectionSource, Punch.class, true); //Punch - Drop all
            //TableUtils.dropTable(connectionSource, Task.class, true); //Task - Drop all
            //TableUtils.dropTable(connectionSource, Job.class, true); //Job - Drop all
            TableUtils.dropTable(connectionSource, Note.class, true); //Note - Drop all

            //create
            TableUtils.createTable(connectionSource, Note.class); //Task - Create Table

        } else if (oldVersion == 17) {

            //update db from old version
            Dao<Job, String> dao = getJobDao();
            dao.executeRaw("ALTER TABLE `jobs` ADD COLUMN fourtyHourWeek BOOLEAN DEFAULT 1;");

        } else if (oldVersion == 18) {

            Dao<Task, String> taskDAO = getTaskDao();
            List<Task> tasks = taskDAO.queryForAll();
            Job currentJob = getAllJobs().get(0);
            if (tasks.size() == 0) {

                Task newTask; //Basic element
                newTask = new Task(currentJob, 0, "Regular");
                tasks.add(newTask);
                newTask = new Task(currentJob, 1, "Lunch Break");
                newTask.setEnablePayOverride(true);
                newTask.setPayOverride(-7.25f);
                tasks.add(newTask);
                newTask = new Task(currentJob, 2, "Other Break");
                newTask.setEnablePayOverride(true);
                newTask.setPayOverride(-7.25f);
                tasks.add(newTask);
                newTask = new Task(currentJob, 3, "Travel");
                tasks.add(newTask);
                newTask = new Task(currentJob, 4, "Admin");
                tasks.add(newTask);
                newTask = new Task(currentJob, 5, "Sick Leave");
                tasks.add(newTask);
                newTask = new Task(currentJob, 6, "Personal Time");
                tasks.add(newTask);
                newTask = new Task(currentJob, 7, "Other");
                tasks.add(newTask);
                newTask = new Task(currentJob, 8, "Holiday Pay");
                tasks.add(newTask);

                for (Task t : tasks) {
                    taskDAO.createOrUpdate(t);
                }
            }
        } else if (oldVersion == 19) {

            try {
                TableUtils.dropTable(connectionSource, Job.class, true); //Job - Create Table

                TableUtils.createTable(connectionSource, Job.class); //Job - Create Table

                DateTime jobMidnight = new DateMidnight().toDateTime().minusWeeks(1)
                        .withZone(DateTimeZone.getDefault());

                Job thisJob = new Job("", 7.25f, jobMidnight, PayPeriodDuration.TWO_WEEKS);

                SharedPreferences pref = PreferenceManager.getDefaultSharedPreferences(gContext);
                try {
                    thisJob.setPayRate(Float.valueOf(pref.getString("normal_pay", "7.25")));
                } catch (NumberFormatException e) {
                    thisJob.setPayRate(7.25f);
                    Log.d(TAG, e.getMessage());
                }

                try {
                    thisJob.setOvertime(Float.valueOf(pref.getString("over_time_threshold", "40")));
                } catch (NumberFormatException e) {
                    thisJob.setOvertime(40f);
                    Log.d(TAG, e.getMessage());
                }

                try {
                    thisJob.setDoubletimeThreshold(
                            Float.valueOf(pref.getString("double_time_threshold", "60")));
                } catch (NumberFormatException e) {
                    thisJob.setDoubletimeThreshold(60f);
                    Log.d(TAG, e.getMessage());
                }

                String date[] = pref.getString("date", "2011.1.17").split("\\p{Punct}");
                String time[] = pref.getString("time", "00:00").split("\\p{Punct}");
                thisJob.setStartOfPayPeriod(new DateTime(Integer.parseInt(date[0]), Integer.parseInt(date[1]),
                        Integer.parseInt(date[2]), Integer.parseInt(time[0]), Integer.parseInt(time[1])));
                switch (Integer.parseInt(pref.getString("len_of_month", "2"))) {
                case 1:
                    thisJob.setDuration(PayPeriodDuration.ONE_WEEK);
                    break;
                case 2:
                    thisJob.setDuration(PayPeriodDuration.TWO_WEEKS);
                    break;
                case 3:
                    thisJob.setDuration(PayPeriodDuration.THREE_WEEKS);
                    break;
                case 4:
                    thisJob.setDuration(PayPeriodDuration.FOUR_WEEKS);
                    break;
                case 5:
                    thisJob.setDuration(PayPeriodDuration.FULL_MONTH);
                    break;
                case 6:
                    thisJob.setDuration(PayPeriodDuration.FIRST_FIFTEENTH);
                    break;
                default:
                    thisJob.setDuration(PayPeriodDuration.TWO_WEEKS);
                    break;
                }

                getJobDao().create(thisJob);

            } catch (SQLException e1) {
                e1.printStackTrace();
            }

        } else if (oldVersion == 20) {
            getJobDao().executeRaw(
                    "ALTER TABLE 'jobs' ADD COLUMN '" + Job.OVERTIME_OPTIONS + "'  VARCHAR default 'NONE';");
            getJobDao().executeRaw("ALTER TABLE 'jobs' ADD COLUMN '" + Job.SATURDAY_OVERRIDE_FIELD
                    + "'  VARCHAR default 'NONE';");
            getJobDao().executeRaw("ALTER TABLE 'jobs' ADD COLUMN '" + Job.SUNDAY_OVERRIDE_FIELD
                    + "'  VARCHAR default 'NONE';");
            List<Job> jobList = getAllJobs();
            for (Job job : jobList) {
                GenericRawResults<String[]> rawResults = getJobDao().queryRaw(
                        "select fourtyHourWeek,overTimeEnabled  from jobs where job_id = " + job.getID());
                String[] results = rawResults.getResults().get(0);
                if (results[0] == "0") {
                    job.setOvertimeOptions(OvertimeOptions.NONE);
                } else {
                    if (results[1] == "0") {
                        job.setOvertimeOptions(OvertimeOptions.DAY);
                    } else if (results[1] == "1") { //being paranoid
                        job.setOvertimeOptions(OvertimeOptions.WEEK);
                    }
                }
            }

            //delete stuff
            getJobDao().executeRaw("ALTER TABLE 'jobs' DROP COLUMN 'fourtyHourWeek';");
            getJobDao().executeRaw("ALTER TABLE 'jobs' DROP COLUMN 'overTimeEnabled';");
        }

    } catch (SQLException e) {
        e.printStackTrace();
        Log.e(TAG, "Could not upgrade the table for Thing", e);
    }
}

From source file:com.ehdev.chronos.lib.Chronos.java

License:Open Source License

static public boolean getDataOnSDCard(Context context, boolean oldFormat) {
    if (getCardReadStatus() == false) {

        CharSequence text = "Could not read to SD Card!.";
        int duration = Toast.LENGTH_SHORT;

        Toast toast = Toast.makeText(context, text, duration);
        toast.show();//ww w .  j a  v a  2 s . c o  m
        return false;
    }

    //Create 1 Job
    DateTime jobMidnight = DateTime.now().withDayOfWeek(7).minusWeeks(1).toDateMidnight().toDateTime()
            .withZone(DateTimeZone.getDefault());
    Job currentJob = new Job("", 10, jobMidnight, PayPeriodDuration.TWO_WEEKS);
    currentJob.setDoubletimeThreshold(60);
    currentJob.setOvertimeThreshold(40);
    currentJob.setOvertimeOptions(OvertimeOptions.WEEK);

    List<Punch> punches = new LinkedList<Punch>();
    List<Task> tasks = new LinkedList<Task>();
    List<Note> notes = new LinkedList<Note>();

    Task newTask; //Basic element
    newTask = new Task(currentJob, 0, "Regular");
    tasks.add(newTask);
    newTask = new Task(currentJob, 1, "Lunch Break");
    newTask.setEnablePayOverride(true);
    newTask.setPayOverride(0.0f);
    tasks.add(newTask);
    newTask = new Task(currentJob, 2, "Other Break");
    newTask.setEnablePayOverride(true);
    newTask.setPayOverride(0.0f);
    tasks.add(newTask);
    newTask = new Task(currentJob, 3, "Travel");
    tasks.add(newTask);
    newTask = new Task(currentJob, 4, "Admin");
    tasks.add(newTask);
    newTask = new Task(currentJob, 5, "Sick Leave");
    tasks.add(newTask);
    newTask = new Task(currentJob, 6, "Personal Time");
    tasks.add(newTask);
    newTask = new Task(currentJob, 7, "Other");
    tasks.add(newTask);
    newTask = new Task(currentJob, 8, "Holiday Pay");
    tasks.add(newTask);

    try {
        File directory = Environment.getExternalStorageDirectory();
        File backup;
        if (!oldFormat)
            backup = new File(directory, "Chronos_Backup.csv");
        else
            backup = new File(directory, "Chronos_Backup.cvs");
        if (!backup.exists()) {
            return false;
        }

        BufferedReader br = new BufferedReader(new FileReader(backup));
        String strLine = br.readLine();

        //id,date,name,task name, date in ms, job num, task num
        //1,Sun Mar 11 2012 15:46,null,Regular,1331498803269,1,1
        while (strLine != null) {
            //Log.d(TAG, strLine);
            String[] parcedString = strLine.split(",");
            long time;
            int task;

            if (!oldFormat) {
                time = Long.parseLong(parcedString[4]);
                task = Integer.parseInt(parcedString[6]);
            } else {
                time = Long.parseLong(parcedString[1]);
                task = Integer.parseInt(parcedString[2]);
                //System.out.println(parcedString.length);

                if (parcedString.length > 4 && StringUtils.isNotBlank(parcedString[4])) {
                    String noteContent = parcedString[4];
                    Note note = new Note(Chronos.getDateFromStartOfPayPeriod(currentJob, new DateTime(time)),
                            currentJob, noteContent);
                    notes.add(note);
                }
            }

            //Job iJob, Task iPunchTask, DateTime iTime
            punches.add(new Punch(currentJob, tasks.get(task - 1), new DateTime(time)));
            strLine = br.readLine();
        }
    } catch (Exception e) {

        e.printStackTrace();
        if (e != null && e.getCause() != null) {
            Log.e(TAG, e.getCause().toString());
        }
        return false;
    }

    //Log.d(TAG, "Number of punches: " + punches.size());
    try {
        Chronos chronos = new Chronos(context);
        TableUtils.dropTable(chronos.getConnectionSource(), Punch.class, true); //Punch - Drop all
        TableUtils.dropTable(chronos.getConnectionSource(), Task.class, true); //Task - Drop all
        TableUtils.dropTable(chronos.getConnectionSource(), Job.class, true); //Job - Drop all
        TableUtils.dropTable(chronos.getConnectionSource(), Note.class, true); //Note - Drop all

        //Recreate DB
        TableUtils.createTable(chronos.getConnectionSource(), Punch.class); //Punch - Create Table
        TableUtils.createTable(chronos.getConnectionSource(), Task.class); //Task - Create Table
        TableUtils.createTable(chronos.getConnectionSource(), Job.class); //Job - Create Table
        TableUtils.createTable(chronos.getConnectionSource(), Note.class); //Task - Create Table

        //recreate entries
        Dao<Task, String> taskDAO = chronos.getTaskDao();
        Dao<Job, String> jobDAO = chronos.getJobDao();
        Dao<Punch, String> punchDOA = chronos.getPunchDao();
        Dao<Note, String> noteDOA = chronos.getNoteDao();

        jobDAO.create(currentJob);

        for (Task t : tasks) {
            taskDAO.create(t);
        }

        for (Punch p : punches) {
            punchDOA.create(p);
        }

        HashMap<DateTime, Note> merger = new HashMap<DateTime, Note>();
        for (Note n : notes) {
            merger.put(n.getTime(), n);
        }

        for (DateTime dt : merger.keySet()) {
            noteDOA.create(merger.get(dt));
        }

        chronos.close();

    } catch (Exception e) {
        Log.e(TAG, e.getMessage());
        return false;
    }

    return true;
}

From source file:com.ehdev.chronos.lib.JsonToSql.java

License:Open Source License

private void prepareJob(Job thisJob) {
    if (null == thisJob.getName())
        thisJob.setName("Default Job");

    if (null == thisJob.getDuration())
        thisJob.setDuration(PayPeriodDuration.TWO_WEEKS);

    if (null == thisJob.getStartOfPayPeriod() || 2010 > thisJob.getStartOfPayPeriod().getYear())
        thisJob.setStartOfPayPeriod(DateTime.now().withDayOfWeek(7).minusWeeks(1).toDateMidnight().toDateTime()
                .withZone(DateTimeZone.getDefault()));
}

From source file:com.enonic.cms.core.search.facet.builder.ElasticsearchDateHistogramFacetBuilder.java

License:Open Source License

private void setTimeZoneSettings(final DateHistogramFacetModel model, final DateHistogramFacetBuilder builder) {
    if (Strings.isNullOrEmpty(model.getPreZone())) {
        builder.preZone(DateTimeZone.getDefault().getID());
    } else {/*from w  w w  .j  av a2s  .c  o m*/
        builder.preZone(model.getPreZone());
    }

    if (!Strings.isNullOrEmpty(model.getPostZone())) {
        builder.postZone(model.getPostZone());
    }

    builder.preZoneAdjustLargeInterval(true);
}

From source file:com.esofthead.mycollab.core.utils.DateTimeUtils.java

License:Open Source License

public static Date convertTimeFromSystemTimezoneToUTC(long timeInMillis) {
    DateTime dt = new DateTime();
    dt = dt.withMillis(-DateTimeZone.getDefault().getOffset(timeInMillis) + timeInMillis);
    dt = dt.withZone(utcZone);//w w  w  . ja v  a2s . c  o  m
    Date date = dt.toDate();
    return date;
}

From source file:com.esofthead.mycollab.core.utils.DateTimeUtils.java

License:Open Source License

/**
 * Convert from UTC time to default time zone of system
 * //w  ww  . j a  v a  2s  .  co  m
 * @param timeInMillis
 * @return
 */
public static Date convertTimeFromUTCToSystemTimezone(long timeInMillis) {
    DateTime dt = new DateTime();
    dt = dt.withMillis(DateTimeZone.getDefault().getOffset(timeInMillis) + timeInMillis);
    dt = dt.withZone(utcZone);
    Date date = dt.toDate();
    return date;
}

From source file:com.facebook.presto.hive.GenericHiveRecordCursor.java

License:Apache License

private static long getLongOrTimestamp(Object value, DateTimeZone hiveTimeZone) {
    if (value instanceof Timestamp) {
        // The Hive SerDe parses timestamps using the default time zone of
        // this JVM, but the data might have been written using a different
        // time zone. We need to convert it to the configured time zone.

        // the timestamp that Hive parsed using the JVM time zone
        long parsedJvmMillis = ((Timestamp) value).getTime();

        // remove the JVM time zone correction from the timestamp
        DateTimeZone jvmTimeZone = DateTimeZone.getDefault();
        long hiveMillis = jvmTimeZone.convertUTCToLocal(parsedJvmMillis);

        // convert to UTC using the real time zone for the underlying data
        long utcMillis = hiveTimeZone.convertLocalToUTC(hiveMillis, false);

        return utcMillis;
    }//  w  w  w . j a va2 s  .com
    return ((Number) value).longValue();
}

From source file:com.facebook.presto.hive.HiveMetadata.java

License:Apache License

private void verifyJvmTimeZone() {
    if (!allowCorruptWritesForTesting && !timeZone.equals(DateTimeZone.getDefault())) {
        throw new PrestoException(HIVE_TIMEZONE_MISMATCH, format(
                "To write Hive data, your JVM timezone must match the Hive storage timezone. Add -Duser.timezone=%s to your JVM arguments.",
                timeZone.getID()));//from w w w. j av  a  2  s.  c o  m
    }
}