--- old/src/java.base/share/classes/java/time/chrono/Chronology.java 2016-03-01 12:54:44.164575994 +0300 +++ new/src/java.base/share/classes/java/time/chrono/Chronology.java 2016-03-01 12:54:43.888575994 +0300 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2012, 2016, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -67,6 +67,7 @@ import java.time.LocalDate; import java.time.LocalTime; import java.time.ZoneId; +import java.time.ZoneOffset; import java.time.format.DateTimeFormatterBuilder; import java.time.format.ResolverStyle; import java.time.format.TextStyle; @@ -712,6 +713,56 @@ return new ChronoPeriodImpl(this, years, months, days); } + //--------------------------------------------------------------------- + + /** + * Gets the number of seconds from the Java epoch of 1970-01-01T00:00:00Z. + *

+ * Returns the number of seconds from the epoch of 1970-01-01T00:00:00Z + * formed using given prolepticYear, month, dayOfMonth , hour, minute, second and zoneOffset. + * Subclass can override the default implementation for a more efficient implementation. + * + * @param prolepticYear the chronology proleptic-year + * @param month the chronology month-of-year + * @param dayOfMonth the chronology day-of-month + * @param hour the hour-of-day to represent, from 0 to 23 + * @param minute the minute-of-hour to represent, from 0 to 59 + * @param second the second-of-minute to represent, from 0 to 59 + * @param zoneOffset the zone offset, not null + * @return the number of seconds relative to 1970-01-01T00:00:00Z, may be negative + */ + public default long epochSecond(int prolepticYear, int month, int dayOfMonth, + int hour, int minute, int second, ZoneOffset zoneOffset) { + Objects.requireNonNull(zoneOffset, "zoneOffset"); + long daysInSec = Math.multiplyExact(date(prolepticYear, month, dayOfMonth).toEpochDay(), 86400); + long timeinSec = (hour * 60 + minute) * 60 + second; + return Math.addExact(daysInSec, timeinSec - zoneOffset.getTotalSeconds()); + } + + /** + * Gets the number of seconds from the epoch of 1970-01-01T00:00:00Z. + *

+ * The number of seconds is caluculated using given era, prolepticYear, + * month, dayOfMonth , hour, minute, second and zoneOffset. + * + * @param era the era of the correct type for the chronology, not null + * @param yearofEra the chronology year-of-era + * @param month the chronology month-of-year + * @param dayOfMonth the chronology day-of-month + * @param hour the hour-of-day to represent, from 0 to 23 + * @param minute the minute-of-hour to represent, from 0 to 59 + * @param second the second-of-minute to represent, from 0 to 59 + * @param zoneOffset the zone offset, not null + * @return the number of seconds relative to 1970-01-01T00:00:00Z, may be negative + */ + public default long epochSecond(Era era, int yearofEra, int month, int dayOfMonth, + int hour, int minute, int second, ZoneOffset zoneOffset) { + Objects.requireNonNull(era, "era"); + Objects.requireNonNull(zoneOffset, "zoneOffset"); + long daysInSec = Math.multiplyExact(date(era, yearofEra, month, dayOfMonth).toEpochDay(), 86400); + long timeinSec = (hour * 60 + minute) * 60 + second; + return Math.addExact(daysInSec, timeinSec - zoneOffset.getTotalSeconds()); + } //----------------------------------------------------------------------- /** * Compares this chronology to another chronology.