I try to use moment.js in vue3(ts),based vite.it can be used,but i can not use 'zh-cn' in my code.thanks - momentjs

in main.ts
import * as moment from 'moment';
import 'moment/locale/pt';
import 'moment/locale/zh-cn';
console.log(1,moment.locale()); // en
moment.locale('fr');
console.log(2,moment.locale()); // en
moment.locale('zh-CN');
console.log(3,moment.locale()); // pt-BR
console.log(moment.locales())
const app = createApp(App)
app.config.globalProperties.$moment = moment
It can not be changed 'zh-cn',moment.locale() run result is also 'en',use 'moment.locale('zh-CN')' or 'moment.locale('zh-cn')' or 'moment.locale('zh-Cn')' is not useful.

I try to using day.js instead of momentjs.It can be use chinese in my code.
In main.ts.
import dayjs from 'dayjs'
import isLeapYear from 'dayjs/plugin/isLeapYear' // 导入插件
import relativeTime from'dayjs/plugin/relativeTime'
import 'dayjs/locale/zh-cn' // 导入本地化语言
dayjs.extend(relativeTime)
dayjs.extend(isLeapYear) // 使用插件
dayjs.locale('zh-cn') // 使用本地化语言
console.log(dayjs().from(dayjs('1990-01-01')))

Related

How to import GUN SEA with Deno Fresh?

The first attempt to import GUN from Fresh was to add the gun library from esm to import_map.json, where it correctly works in simple examples of using GUN.
{
"imports": {
...
"gun": "https://esm.sh/gun#0.2020.1237",
}
}
But the problem occurred when I wanted to import additionally gun/sea,
After importing import Sea from "gun/sea";.
I got this error:
error: Uncaught (in promise) Error: Dynamic require of "./lib/text-encoding" is not supported
On GitHub I read to import gun/lib/mobile before importing SEA when such a problem occurs.
But this brings an additional problem:
error: Uncaught (in promise) TypeError: Assignment to constant variable.
I checked the gun/lib/mobile file and it literally contains a few lines of global variables:
import Buffer from "buffer";
import { TextEncoder, TextDecoder } from "text-encoding";
global.Buffer = global.Buffer || Buffer.Buffer;
global.TextEncoder = TextEncoder;
global.TextDecoder = TextDecoder;
Is there any chance to make SEA work on Fresh?
Add following line inside imports in import_map.json file:
"#gun": "https://esm.sh/gun#0.2020.1237"
Then use this import statement to import GUN in any route/component:
import GUN from "#gun"
Usage (from GUN documentation):
const gun = GUN();
gun.get('mark').put({
name: "Mark",
email: "mark#gun.eco",
});
gun.get('mark').on((data, key) => {
console.log("realtime updates:", data);
});
setInterval(() => { gun.get('mark').get('live').put(Math.random()) }, 9);

How to import external library in QT Python?

I have an issue when importing external python library in QT app.
The program is crashing when I'm trying to import the canlib.
However, no import error is caught, only application communicate appear like this:
program finished with code -1
When I comment out the canlib import, program runs fine.
import os
from pathlib import Path
import sys
import random
from Connection import Connection
from PySide6.QtGui import QGuiApplication
from PySide6.QtQml import QQmlApplicationEngine
from PySide6.QtCore import QTimer
from canlib import kvadblib #here is an error source
if __name__ == "__main__":
app = QGuiApplication(sys.argv)
engine = QQmlApplicationEngine()
# Connection QT <---> Python
connection = Connection()
engine.rootContext().setContextProperty("connection", connection)
# End
# Hardware Init
db = kvadblib.Dbc(filename='battery_monitoring_app.dbc')
ch = communication.open_virtual_channel(1)
# End
engine.load(os.fspath(Path(__file__).resolve().parent / "qml/main.qml"))
if not engine.rootObjects():
sys.exit(-1)
### DO WHILE TRUE STUFF
def doStuff():
connection.testSignalVariable.emit(random.uniform(0.00, 2.00))
### END
timer = QTimer()
timer.timeout.connect(doStuff)
timer.start(100)
sys.exit(app.exec_())

Not compile project after migrate from Vaadin 7 to Vaadin 8

Current version of Vaadin is 7.3.6
Here some my code:
import com.vaadin.data.Property;
import com.vaadin.data.Property.ValueChangeEvent;
import com.vaadin.ui.NativeSelect;
import com.vaadin.ui.TextField;
import com.vaadin.ui.UI;
import com.vaadin.ui.VerticalLayout;
private NativeSelect currencySelector;
private void initCurrencySelector(String providerId) {
currencySelector = new NativeSelect();
List<String> selectCurrencyList;
currencySelector.removeAllItems();
}
And this code success compile.
But after I try to upgrade to Vaadin 8.12.0 then this code not compile.
error in this lines:
import com.vaadin.data.Property;
import com.vaadin.data.Property.ValueChangeEvent;
import com.vaadin.event.FieldEvents.TextChangeEvent;
import com.vaadin.event.FieldEvents.TextChangeListener;
and in this line:
currencySelector.removeAllItems();
the new imports should be
import com.vaadin.data.HasValue.ValueChangeEvent;
import com.vaadin.event.FieldsEvent
TextChangeEvent and TextChangeListener probably were replaced by HasValue.ValueChangeEvent and HasValue.ValueChangeListener
currencySelector.removeAllItems(); should be
currencySelector.setDataProvider(new ListDataProvider(new ArrayList()));
a list of incompatible changes can be found here https://vaadin.com/download/prerelease/8.0/8.0.0/8.0.0.beta1/release-notes.html#incompatible

Pact: Error when trying to setup mock provider

I'm trying to write my first Pact-python test using pytest, Could someone please tell me what's wrong with my code?
import unittest
import requests
import json
import pytest
import atexit
from pact import Consumer, Provider
pact = Consumer('Consumer').has_pact_with(Provider('Provider'), host_name='mockservice', port=8080)
pact.start_service()
atexit.register(pact.stop_service)
class InterviewDetails(unittest.TestCase):
def test_candidate_report_api(self):
candidate_report_payload = {}
resp = requests.post("http://localhost:1234/users/",data=json.dumps(candidate_report_payload))
response = json.loads(resp.text)
return response
#pytest.mark.health1
def test_candidate_report(self):
expected = {}
(pact.given('Comment')
.upon_receiving('comment')
.with_request(method='POST', path="http://localhost:1234/users/", headers={})
.will_respond_with(200, body=expected))
with pact:
pact.setup()
result = self.test_candidate_report_api()
self.assertEqual(result, expected)
pact.verify()
The error from stacktrace:
AttributeError: module 'pact' has no attribute 'Like'
Can you please confirm you're using pact-python from https://github.com/pact-foundation/pact-python/ (and not pactman, a project that is not maintained by the Pact Foundation)?
It might be related to the way you have setup your test?
Here is an example project you can use for reference: https://github.com/pactflow/example-consumer-python/
Relevant test code:
"""pact test for product service client"""
import json
import logging
import os
import requests
from requests.auth import HTTPBasicAuth
import pytest
from pact import Consumer, Like, Provider, Term, Format
from src.consumer import ProductConsumer
log = logging.getLogger(__name__)
logging.basicConfig(level=logging.INFO)
print(Format().__dict__)
PACT_MOCK_HOST = 'localhost'
PACT_MOCK_PORT = 1234
PACT_DIR = os.path.dirname(os.path.realpath(__file__))
#pytest.fixture
def consumer():
return ProductConsumer(
'http://{host}:{port}'
.format(host=PACT_MOCK_HOST, port=PACT_MOCK_PORT)
)
#pytest.fixture(scope='session')
def pact(request):
pact = Consumer('pactflow-example-consumer-python').has_pact_with(
Provider('pactflow-example-provider-python'), host_name=PACT_MOCK_HOST, port=PACT_MOCK_PORT,
pact_dir="./pacts", log_dir="./logs")
try:
print('start service')
pact.start_service()
yield pact
finally:
print('stop service')
pact.stop_service()
def test_get_product(pact, consumer):
expected = {
'id': "27",
'name': 'Margharita',
'type': 'Pizza'
}
(pact
.given('a product with ID 10 exists')
.upon_receiving('a request to get a product')
.with_request('GET', '/product/10')
.will_respond_with(200, body=Like(expected)))
with pact:
user = consumer.get_product('10')
assert user.name == 'Margharita'

Why am I getting NameError: Not Defined after adding to urls.py?

I am getting this error:
NameError at /storefront/
name 'storefront' is not defined
My Urls.Py looks like this:
from django.conf import settings
from django.conf.urls import patterns, include, url
from django.conf.urls.static import static
from django.views.generic import TemplateView
from accounts.views import home
from django.contrib import admin
urlpatterns = patterns('',
url(r"^$", home),
url(r"^storefront/", storefront, name="storefront")
My Views.Py looks like this:
def storefront(request):
latest_entries = Entry.objects.filter()
context = {'latest_entries': latest_entries}
return render(request, 'storefront.html', context)
Is the error in the urls or the views?

Resources