Exemplo n.º 1
0
    def transform(self,
                  date_value,
                  from_format=u'',
                  to_format=u'',
                  from_timezone=u'',
                  to_timezone=u'',
                  **kwargs):
        if not date_value:
            return u''

        if not to_timezone:
            to_timezone = u'UTC'

        dt = try_parse_date(date_value, from_format=from_format)
        if not dt:
            return self.raise_exception('Date could not be parsed')

        dtout = arrow.get(dt)

        # if the from_timezone is *not* UTC and our datetime *is* UTC, replace it...
        if from_timezone and from_timezone != 'UTC' and dtout.tzinfo == dateutil.tz.tzutc(
        ):
            dtout = dtout.replace(tzinfo=from_timezone)

        return dtout.to(to_timezone).format(to_format)
Exemplo n.º 2
0
    def fields(self, *args, **kwargs):
        dt = arrow.get(try_parse_date('Mon Jan 22 15:04:05 -0800 2006')).to('utc')

        format_choices = ','.join(['{}|{} ({})'.format(f, f, dt.format(f)) for f in PREDEFINED_DATE_FORMATS])

        return [
            {
                'type': 'unicode',
                'required': True,
                'key': 'expression',
                'help_text': (
                    'Provide the amount of time you would like to add or subtract to the date (negative values subtract time). '
                    'Examples: `+8 hours 1 minute`, `+1 month -2 days`, `-1 day +8 hours`.'
                )
            },
            {
                'type': 'unicode',
                'required': True,
                'key': 'to_format',
                'choices': format_choices,
                'help_text': 'Provide the format that the date should be converted to. For date format help, see: https://zapier.com/help/formatter/#date-time'
            },
            {
                'type': 'unicode',
                'required': False,
                'key': 'from_format',
                'choices': format_choices,
                'help_text': 'If we incorrectly interpret the incoming (input) date, set this to explicitly tell us the format. Otherwise, we will do our best to figure it out.' # NOQA
            },
        ]
Exemplo n.º 3
0
    def transform(self, date_value, expression=u'', from_format=u'', to_format=u'', **kwargs):
        if date_value is None:
            date_value = u''

        delta = tdelta(expression)

        dt = try_parse_date(date_value, from_format=from_format)
        if not dt:
            return self.raise_exception('Date could not be parsed')

        dt = shift_date(dt, delta)
        if not dt:
            return self.raise_exception('Date could not be manipulated')

        return arrow.get(dt).to('utc').format(to_format)
Exemplo n.º 4
0
    def fields(self, *args, **kwargs):
        dt = arrow.get(
            try_parse_date('Mon Jan 22 15:04:05 -0800 2006')).to('utc')

        format_choices = ','.join([
            '{}|{} ({})'.format(f, f, dt.format(f))
            for f in PREDEFINED_DATE_FORMATS
        ])

        return [
            {
                'type':
                'unicode',
                'required':
                True,
                'key':
                'expression',
                'help_text':
                ('Provide the amount of time you would like to add or subtract to the date (negative values subtract time). '
                 'Examples: `+8 hours 1 minute`, `+1 month -2 days`, `-1 day +8 hours`.'
                 )
            },
            {
                'type':
                'unicode',
                'required':
                True,
                'key':
                'to_format',
                'choices':
                format_choices,
                'help_text':
                'Provide the format that the date should be converted to. For date format help, see: https://zapier.com/help/formatter/#date-time'
            },
            {
                'type':
                'unicode',
                'required':
                False,
                'key':
                'from_format',
                'choices':
                format_choices,
                'help_text':
                'If we incorrectly interpret the incoming (input) date, set this to explicitly tell us the format. Otherwise, we will do our best to figure it out.'  # NOQA
            },
        ]
Exemplo n.º 5
0
    def transform(self, date_value, from_format=u'', to_format=u'', from_timezone=u'', to_timezone=u'', **kwargs):
        if not date_value:
            return u''

        if not to_timezone:
            to_timezone = u'UTC'

        dt = try_parse_date(date_value, from_format=from_format)
        if not dt:
            return self.raise_exception('Date could not be parsed')

        dtout = arrow.get(dt)

        # if the from_timezone is *not* UTC and our datetime *is* UTC, replace it...
        if from_timezone and from_timezone != 'UTC' and dtout.tzinfo == dateutil.tz.tzutc():
            dtout = dtout.replace(tzinfo=from_timezone)

        return dtout.to(to_timezone).format(to_format)
Exemplo n.º 6
0
    def transform(self,
                  date_value,
                  expression=u'',
                  from_format=u'',
                  to_format=u'',
                  **kwargs):
        if date_value is None:
            date_value = u''

        delta = tdelta(expression)

        dt = try_parse_date(date_value, from_format=from_format)
        if not dt:
            return self.raise_exception('Date could not be parsed')

        dt = shift_date(dt, delta)
        if not dt:
            return self.raise_exception('Date could not be manipulated')

        return arrow.get(dt).to('utc').format(to_format)
Exemplo n.º 7
0
    def fields(self, *args, **kwargs):
        dt = arrow.get(try_parse_date('Mon Jan 22 15:04:05 -0800 2006')).to('utc')

        choices = ','.join(['{}|{} ({})'.format(f, f, dt.format(f)) for f in PREDEFINED_DATE_FORMATS])

        timezones = list(sorted(pytz.common_timezones, key=lambda v: '-' + v if v.startswith('US') else v))

        return [
            {
                'type': 'unicode',
                'required': True,
                'key': 'to_format',
                'choices': choices,
                'help_text': 'Provide the format that the date is converted to. For date format help, see: https://zapier.com/help/formatter/#date-time'
            },
            {
                'type': 'unicode',
                'required': False,
                'key': 'to_timezone',
                'label': 'To Timezone',
                'choices': timezones,
                'default': 'UTC',
                'help_text': 'Choose a timezone the date should be converted to. (Default: UTC)'
            },
            {
                'type': 'unicode',
                'required': False,
                'key': 'from_format',
                'choices': choices,
                'help_text': 'If we incorrectly interpret the incoming (input) date, set this to explicitly tell us the format. Otherwise, we will do our best to figure it out.' # NOQA
            },
            {
                'type': 'unicode',
                'required': False,
                'key': 'from_timezone',
                'label': 'From Timezone',
                'choices': timezones,
                'default': 'UTC',
                'help_text': 'If no timezone is provided in the incoming (input) data, set this to explicitly tell us which to use. (Default: UTC)' # NOQA
            },
        ]