| 830 | } |
| 831 | |
| 832 | @Override |
| 833 | public long getElapsedTime(TimeScale scale) { |
| 834 | |
| 835 | switch (scale) { |
| 836 | case POSIX: |
| 837 | return this.posixTime; |
| 838 | case UTC: |
| 839 | return this.getElapsedTimeUTC(); |
| 840 | case TAI: |
| 841 | long tai; |
| 842 | int nano; |
| 843 | if (this.getElapsedTimeUTC() < 0) { |
| 844 | PlainDate date = this.getDateUTC(); |
| 845 | double ttValue = TimeScale.deltaT(date); |
| 846 | ttValue += (this.posixTime - POSIX_UTC_DELTA); |
| 847 | ttValue += (this.getNanosecond() / (MRD * 1.0)); |
| 848 | long tv = (long) Math.floor(ttValue); |
| 849 | if (Double.compare(MRD - (ttValue - tv) * MRD, 1.0) < 0) { |
| 850 | tv++; |
| 851 | nano = 0; |
| 852 | } else { |
| 853 | nano = toNanos(ttValue, tv); |
| 854 | } |
| 855 | tai = tv - 32 + UTC_TAI_DELTA; |
| 856 | nano -= 184_000_000; |
| 857 | if (nano < 0) { |
| 858 | tai--; |
| 859 | } |
| 860 | } else { |
| 861 | tai = this.getElapsedTimeUTC() + UTC_TAI_DELTA + 10; |
| 862 | } |
| 863 | if (tai < 0) { |
| 864 | throw new IllegalArgumentException( |
| 865 | "TAI not supported before 1958-01-01: " + this); |
| 866 | } else { |
| 867 | return tai; |
| 868 | } |
| 869 | case GPS: |
| 870 | long utcG = this.getElapsedTimeUTC(); |
| 871 | if (LeapSeconds.getInstance().strip(utcG) < POSIX_GPS_DELTA) { |
| 872 | throw new IllegalArgumentException( |
| 873 | "GPS not supported before 1980-01-06: " + this); |
| 874 | } else { |
| 875 | long gps = LeapSeconds.getInstance().isEnabled() ? utcG : (utcG + 9); |
| 876 | return gps - UTC_GPS_DELTA; |
| 877 | } |
| 878 | case TT: |
| 879 | if (this.posixTime < POSIX_UTC_DELTA) { |
| 880 | PlainDate date = this.getDateUTC(); |
| 881 | double ttValue = TimeScale.deltaT(date); |
| 882 | ttValue += (this.posixTime - POSIX_UTC_DELTA); |
| 883 | ttValue += (this.getNanosecond() / (MRD * 1.0)); |
| 884 | long tt = (long) Math.floor(ttValue); |
| 885 | if (Double.compare(MRD - (ttValue - tt) * MRD, 1.0) < 0) { |
| 886 | return tt + 1; |
| 887 | } |
| 888 | return tt; |
| 889 | } else { |