-
Notifications
You must be signed in to change notification settings - Fork 26
Expand file tree
/
Copy pathinteger.py
More file actions
36 lines (28 loc) · 1.1 KB
/
integer.py
File metadata and controls
36 lines (28 loc) · 1.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# (C) Copyright 2020 ECMWF.
#
# This software is licensed under the terms of the Apache Licence Version 2.0
# which can be obtained at http://www.apache.org/licenses/LICENSE-2.0.
# In applying this licence, ECMWF does not waive the privileges and immunities
# granted to it by virtue of its status as an intergovernmental organisation
# nor does it submit to any jurisdiction.
#
import datetime
from earthkit.data.wrappers import Wrapper
class IntWrapper(Wrapper):
def __init__(self, data):
self.data = data
def to_datetime(self):
if self.data <= 0:
date = datetime.datetime.now(datetime.timezone.utc) + datetime.timedelta(days=self.data)
return datetime.datetime(date.year, date.month, date.day)
else:
return datetime.datetime(self.data // 10000, self.data % 10000 // 100, self.data % 100)
def to_datetime_list(self):
return [self.to_datetime()]
@property
def values(self):
return self.data
def wrapper(data, *args, fieldlist=False, **kwargs):
if isinstance(data, int):
return IntWrapper(data)
return None