Exemplo n.º 1
0
def subtract_tzoffset_from_date(the_date):
    """Input: NSDate object
    Output: NSDate object with same date and time as the UTC.
    In Los Angeles (PDT), '2011-06-20T12:00:00Z' becomes
    '2011-06-20 12:00:00 -0700'.
    In New York (EDT), it becomes '2011-06-20 12:00:00 -0400'.
    This allows a pkginfo item to reference a time in UTC that
    gets translated to the same relative local time.
    A force_install_after_date for '2011-06-20T12:00:00Z' will happen
    after 2011-06-20 12:00:00 local time.
    """
    # find our time zone offset in seconds
    timezone = NSTimeZone.defaultTimeZone()
    seconds_offset = timezone.secondsFromGMTForDate_(the_date)
    # return new NSDate minus local_offset
    return NSDate.alloc(
        ).initWithTimeInterval_sinceDate_(-seconds_offset, the_date)
Exemplo n.º 2
0
def subtract_tzoffset_from_date(the_date):
    """Input: NSDate object
    Output: NSDate object with same date and time as the UTC.
    In Los Angeles (PDT), '2011-06-20T12:00:00Z' becomes
    '2011-06-20 12:00:00 -0700'.
    In New York (EDT), it becomes '2011-06-20 12:00:00 -0400'.
    This allows a pkginfo item to reference a time in UTC that
    gets translated to the same relative local time.
    A force_install_after_date for '2011-06-20T12:00:00Z' will happen
    after 2011-06-20 12:00:00 local time.
    """
    # find our time zone offset in seconds
    timezone = NSTimeZone.defaultTimeZone()
    seconds_offset = timezone.secondsFromGMTForDate_(the_date)
    # return new NSDate minus local_offset
    return NSDate.alloc().initWithTimeInterval_sinceDate_(
        -seconds_offset, the_date)
Exemplo n.º 3
0
def add_tzoffset_to_date(the_date):
    """Input: NSDate object
    Output: NSDate object with timezone difference added
    to the date. This allows conditional_item conditions to
    be written like so:

    <Key>condition</key>
    <string>date > CAST("2012-12-17T16:00:00Z", "NSDate")</string>

    with the intent being that the comparision is against local time.

    """
    # find our time zone offset in seconds
    timezone = NSTimeZone.defaultTimeZone()
    seconds_offset = timezone.secondsFromGMTForDate_(the_date)
    # return new NSDate minus local_offset
    return NSDate.alloc(
        ).initWithTimeInterval_sinceDate_(seconds_offset, the_date)
Exemplo n.º 4
0
def add_tzoffset_to_date(the_date):
    """Input: NSDate object
    Output: NSDate object with timezone difference added
    to the date. This allows conditional_item conditions to
    be written like so:

    <Key>condition</key>
    <string>date > CAST("2012-12-17T16:00:00Z", "NSDate")</string>

    with the intent being that the comparision is against local time.

    """
    # find our time zone offset in seconds
    timezone = NSTimeZone.defaultTimeZone()
    seconds_offset = timezone.secondsFromGMTForDate_(the_date)
    # return new NSDate minus local_offset
    return NSDate.alloc().initWithTimeInterval_sinceDate_(
        seconds_offset, the_date)