Подтвердить что ты не робот

Где дополнительные 75 секунд?

При написании некоторых модульных тестов в калькуляторе Julian Day я обнаружил, что даты до 2 декабря 1847 года были неправильно инициализированы NSDate. Кажется, у них 75 секунд. Я не смог найти ничего, указывающего на эту дату (что хорошо после отсечения григорианского календаря). Это ошибка или есть историческая корректировка календаря, с которой я не сталкивался?

int main(int argc, const char * argv[])
{
    @autoreleasepool {

        NSCalendar *cal = [NSCalendar currentCalendar];
        NSDateComponents *dateComps = [NSDateComponents new];
        dateComps.year = 1847;
        dateComps.month = 12;
        dateComps.day    = 1;
        NSDate *d1 = [cal dateFromComponents:dateComps];
        NSLog(@"d1 = %@", d1);

        dateComps = [NSDateComponents new];
        dateComps.year = 1847;
        dateComps.month = 12;
        dateComps.day    = 2;
        NSDate *d2 = [cal dateFromComponents:dateComps];
        NSLog(@"d2 = %@", d2);
    }
    return 0;
}

Вывод:

d1 = 1847-12-01 00:01:15 +0000

d2 = 1847-12-02 00:00:00 +0000

4b9b3361

Ответ 1

В соответствии с http://www.timeanddate.com/worldclock/clockchange.html?n=136&year=1847 в это время был сдвиг времени на 75 секунд.

В Лондоне, когда местное время вот-вот достигло 12:00:00 в среду 1 декабря 1847 года, часы были отправлены в среду, 1 декабря 1847 года 12:01:15.

Ответ 2

В ответ на сообщение Ричарда Краюнуса, вот некоторая дополнительная информация из zoneinfo база данных, используемая большинством компьютеров для отслеживания таких изменений:

# From Paul Eggert (1993-11-18):
#
# Howse writes that Britain was the first country to use standard time.
# The railways cared most about the inconsistencies of local mean time,
# and it was they who forced a uniform time on the country.
# The original idea was credited to Dr. William Hyde Wollaston (1766-1828)
# and was popularized by Abraham Follett Osler (1808-1903).
# The first railway to adopt London time was the Great Western Railway
# in November 1840; other railways followed suit, and by 1847 most
# (though not all) railways used London time.  On 1847-09-22 the
# Railway Clearing House, an industry standards body, recommended that GMT be
# adopted at all stations as soon as the General Post Office permitted it.
# The transition occurred on 12-01 for the L&NW, the Caledonian,
# and presumably other railways; the January 1848 Bradshaw lists many
# railways as using GMT.  By 1855 the vast majority of public
# clocks in Britain were set to GMT (though some, like the great clock
# on Tom Tower at Christ Church, Oxford, were fitted with two minute hands,
# one for local time and one for GMT).  The last major holdout was the legal
# system, which stubbornly stuck to local time for many years, leading
# to oddities like polls opening at 08:13 and closing at 16:13.
# The legal system finally switched to GMT when the Statutes (Definition
# of Time) Act took effect; it received the Royal Assent on 1880-08-02.
#
# In the tables below, we condense this complicated story into a single
# transition date for London, namely 1847-12-01.  We don't know as much
# about Dublin, so we use 1880-08-02, the legal transition time.

Извините, я не мог ответить, используя комментарий в этом потоке; StackOverflow еще не считает меня достойным этого.

Ответ 3

Если вы выполняете какое-либо манипулирование Date/Time, вам нужно Частые вопросы по часам. Он отвечает на все вопросы, подобные этому.

Ответ 4

Это ошибка или есть историческая корректировка календаря, с которой я не сталкивался?

Было несколько раз, когда календарь был... исправлен в прошлом.

Проверьте разделы "принятия" статей wikipedia для Julian и Gregorian.

В экземпляре NSDate всегда должна отображаться правильная дата для любого временного часа, который был инициализирован.

Ответ 5

NSDateComponents используют ваш локальный часовой пояс. Попробуйте установить timeZone на UTC?

NSCalendar *cal = [NSCalendar currentCalendar];
NSDateComponents *dateComps = [NSDateComponents new];
dateComps.timeZone = [NSTimeZone timeZoneWithAbbreviation:@"UTC"];
dateComps.year = 1847;
dateComps.month = 12;
dateComps.day    = 1;
NSDate *d1 = [cal dateFromComponents:dateComps];
NSLog(@"d1 = %@", d1);

dateComps = [NSDateComponents new];
dateComps.timeZone = [NSTimeZone timeZoneWithAbbreviation:@"UTC"];
dateComps.year = 1847;
dateComps.month = 12;
dateComps.day    = 2;
NSDate *d2 = [cal dateFromComponents:dateComps];
NSLog(@"d2 = %@", d2);

[19875:60b] d1 = 1847-12-01 00:00:00 +0000
[19875:60b] d2 = 1847-12-02 00:00:00 +0000