Add properties for time and date to cell
This commit is contained in:
parent
6e101413b9
commit
524eb06749
|
@ -26,7 +26,9 @@ import gettext
|
|||
import logging
|
||||
import os
|
||||
import platform
|
||||
import re
|
||||
import shlex
|
||||
import shutil
|
||||
import socket
|
||||
import subprocess
|
||||
import sys
|
||||
|
@ -1094,6 +1096,29 @@ class LOCalcRange(object):
|
|||
d = (data.hour * 3600 + data.minute * 60 + data.second) / SECONDS_DAY
|
||||
self.obj.setValue(d)
|
||||
|
||||
@property
|
||||
def date(self):
|
||||
value = int(self.obj.Value)
|
||||
date = datetime.date.fromordinal(value + DATE_OFFSET)
|
||||
return date
|
||||
|
||||
@property
|
||||
def time(self):
|
||||
value = self.obj.Value - int(self.obj.Value)
|
||||
h = 24 * value
|
||||
hours = int(h)
|
||||
m = round((h - hours) * 60, 6)
|
||||
minutes = int(m)
|
||||
s = (m - minutes) * 60
|
||||
seconds = int(s)
|
||||
ms = int(round((s - seconds), 6) * 1_000_000)
|
||||
time = datetime.time(hours, minutes, seconds, ms)
|
||||
return time
|
||||
|
||||
@property
|
||||
def datetime(self):
|
||||
return datetime.datetime.combine(self.date, self.time)
|
||||
|
||||
@property
|
||||
def data(self):
|
||||
return self.obj.getDataArray()
|
||||
|
@ -2549,6 +2574,10 @@ class Paths(object):
|
|||
def ext(self):
|
||||
return self._path.suffix
|
||||
|
||||
@property
|
||||
def info(self):
|
||||
return self.path, self.file_name, self.name, self.ext
|
||||
|
||||
@property
|
||||
def url(self):
|
||||
return self._path.as_uri()
|
||||
|
@ -2590,6 +2619,31 @@ class Paths(object):
|
|||
if path.startswith('file://'):
|
||||
path = str(Path(uno.fileUrlToSystemPath(path)).resolve())
|
||||
return path
|
||||
|
||||
@classmethod
|
||||
def walk(cls, path, filters=''):
|
||||
paths = []
|
||||
if filters in ('*', '*.*'):
|
||||
filters = ''
|
||||
for folder, _, files in os.walk(path):
|
||||
if filters:
|
||||
pattern = re.compile(r'\.(?:{})$'.format(filters), re.IGNORECASE)
|
||||
paths += [cls.join(folder, f) for f in files if pattern.search(f)]
|
||||
else:
|
||||
paths += files
|
||||
return paths
|
||||
|
||||
@classmethod
|
||||
def copy(cls, source, target='', name=''):
|
||||
p, f, n, e = _P(source).info
|
||||
if target:
|
||||
p = target
|
||||
if name:
|
||||
e = ''
|
||||
n = name
|
||||
path_new = cls.join(p, f'{n}{e}')
|
||||
shutil.copy(source, path_new)
|
||||
return path_new
|
||||
_P = Paths
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue