Esempio n. 1
0
    def local_timestamp(self, ts) -> str:
        """Convert Timestamp to a localized timestamp string.

        .. versionadded:: 7.0
        """
        year = formatYear(self.site.lang, ts.year)
        date = format_date(ts.month, ts.day, self.site)
        *_, time = str(ts).strip('Z').partition('T')
        return ' '.join((date, year, time))
    def test_basic(self):
        site = self.get_site()
        # Some languages are missing (T85681)
        if (site.lang not in date.formats['YearBC']) or (site.lang not in date.formats['YearAD']):
            raise unittest.SkipTest('Date formats for this language are missing from date.py')
        start = -20
        end = 2026

        i = 0
        for page in pagegenerators.YearPageGenerator(start, end, site):
            self.assertIsInstance(page, pywikibot.Page)
            self.assertEqual(date.formatYear(site.lang, start + i), page.title())
            self.assertNotEqual(page.title(), "0")
            i += 1
            if start + i == 0:
                i += 1
        self.assertEqual(start + i - 1, end)
Esempio n. 3
0
    def test_basic(self):
        """Test YearPageGenerator."""
        site = self.get_site()
        # Some languages are missing (T85681)
        if (site.lang not in date.formats['YearBC']) or (site.lang not in date.formats['YearAD']):
            raise unittest.SkipTest('Date formats for this language are missing from date.py')
        start = -20
        end = 2026

        i = 0
        for page in pagegenerators.YearPageGenerator(start, end, site):
            self.assertIsInstance(page, pywikibot.Page)
            self.assertEqual(date.formatYear(site.lang, start + i), page.title())
            self.assertNotEqual(page.title(), "0")
            i += 1
            if start + i == 0:
                i += 1
        self.assertEqual(start + i - 1, end)