soonmyeong2

calculate date module and int2str_json

This diff is collapsed. Click to expand it.
#-*- coding: utf-8 -*-
import json
from datetime import datetime, timedelta
import json
import re
'''
def dday_calculate(date):
y_m_d = date.split("-")
return (datetime.now() - datetime(int(y_m_d[0]), int(y_m_d[1]), int(y_m_d[2]))).days
with open('tset.json', 'rt', encoding='utf-8') as json_file:
def date_calculate(url):
dates = re.findall(r'[0-9]{2,4}[.|-][0-9]{1,2}[.|-][0-9]{1,2}|~', url)
for i in range(len(dates)):
dates[i] = dates[i].replace(".", "-")
# 날짜가 없는 경우
if len(dates) == 0:
return "상시"
# XXX ~
if dates[-1] == "~":
dday = dday_calculate(dates[0])
if dday > 0:
return "진행중"
else:
return "준비중"
# ~ XXX and XXX ~ XXX
if dates[-1] != "~":
dday = dday_calculate(dates[-1])
if dday < 0:
return "D"+str(dday)
else:
return "종료"
# except
return "상 시"
'''
with open('d.json', 'rt', encoding='utf-8') as json_file:
json_data = json.load(json_file)
......@@ -10,6 +48,11 @@ for js in json_data:
for key, value in js.items():
if type(value) != str and key != 'View':
js[key] = str(value)
if key == "Link" and value[0] == '[':
js[key] = value[1:-1]
# if key == "Date":
# js[key] = date_calculate(value)
with open('result.json', 'w', encoding='utf-8') as make_file:
make_file.write('[')
......@@ -19,4 +62,3 @@ with open('result.json', 'w', encoding='utf-8') as make_file:
if i != len(json_data) - 1:
make_file.write(',')
make_file.write(']')
......
This diff is collapsed. Click to expand it.
......@@ -9,7 +9,7 @@ android {
buildToolsVersion "29.0.2"
defaultConfig {
applicationId "com.example.vip"
minSdkVersion 23
minSdkVersion 26
targetSdkVersion 29
versionCode 1
versionName "1.0"
......
......@@ -3,6 +3,7 @@ package com.example.vip
import android.content.Context
import android.content.Intent
import android.content.SharedPreferences
import android.util.Log
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
......@@ -10,6 +11,11 @@ import android.widget.Toast
import androidx.recyclerview.widget.RecyclerView
import kotlinx.android.synthetic.main.item_policy.view.*
import kotlinx.android.synthetic.main.item_policyfield.view.*
import java.time.LocalDate
import java.text.ParseException
import java.text.SimpleDateFormat
import java.time.format.DateTimeFormatter
class PolicyAdapter(private val items: ArrayList<PolicyItem>) :
RecyclerView.Adapter<PolicyAdapter.ViewHolder>() {
......@@ -43,6 +49,36 @@ class PolicyAdapter(private val items: ArrayList<PolicyItem>) :
var sepstr=tempstring!!.split("@")
var sepstrset=sepstr.toMutableSet()
/*
fun dday_calculate(date : String) : Long {
var now = LocalDate.now()
var Strnow = now.format(DateTimeFormatter.ofPattern("yyyy-MM-dd"))
var calDateDays : Long = 0.toLong()
try { // String Type을 Date Type으로 캐스팅하면서 생기는 예외로 인해 여기서 예외처리 해주지 않으면 컴파일러에서 에러가 발생해서 컴파일을 할 수 없다.
val format = SimpleDateFormat("yyyy-mm-dd")
// date1, date2 두 날짜를 parse()를 통해 Date형으로 변환.
val Date = format.parse(date)
val nowDate = format.parse(Strnow)
// Date로 변환된 두 날짜를 계산한 뒤 그 리턴값으로 long type 변수를 초기화 하고 있다.
// 연산결과 -950400000. long type 으로 return 된다.
val calDate = nowDate.getTime() - Date.getTime()
// Date.getTime() 은 해당날짜를 기준으로1970년 00:00:00 부터 몇 초가 흘렀는지를 반환해준다.
// 이제 24*60*60*1000(각 시간값에 따른 차이점) 을 나눠주면 일수가 나온다.
calDateDays = calDate / (24 * 60 * 60 * 1000)
} catch (e: ParseException) {
calDateDays = 0
}
return calDateDays
}
fun date_calculate(dday : String) {
val matchResult : Sequence<MatchResult> = Regex.findAll("abcd")
return
}*/
fun bind(item: PolicyItem) {
view.policyImage.setImageDrawable(item.policyItemImage)
if (item.policyItemDate == "") { item.policyItemDate = "상시" }
......
......@@ -60,8 +60,11 @@
android:layout_width="match_parent"
android:layout_height="10dp"
android:layout_marginLeft="14dp"
android:layout_marginRight="12dp"
android:layout_weight="0.7"
android:ellipsize="end"
android:gravity="bottom|left|center_vertical"
android:maxLines="1"
android:text="TextView"
android:textColor="#C04A4A4A"
android:textSize="13dp" />
......@@ -71,8 +74,11 @@
android:layout_width="match_parent"
android:layout_height="10dp"
android:layout_marginLeft="11dp"
android:layout_marginRight="10dp"
android:layout_weight="1"
android:ellipsize="end"
android:gravity="left|center_vertical"
android:maxLines="1"
android:text="TextView"
android:textColor="#000"
android:textSize="18dp" />
......